Skip to content

Commit

Permalink
fix(docs-e2e): 'Edit on GitHub' button going to 404 page
Browse files Browse the repository at this point in the history
Remove "/docs" from the endpoints pointing to the docs page.
  • Loading branch information
HasithDeAlwis authored and MFarabi619 committed Nov 1, 2024
1 parent 11d852a commit 6a9acb5
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 12 deletions.
14 changes: 7 additions & 7 deletions apps/docs-e2e/src/docs.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,6 @@ const CUHACKING_2025_PLATFORM_GITHUB_REPOSITORY_URL = `${GITHUB_BASE_URL}/2025`
const CUHACKING_2025_PLATFORM_GITHUB_INDEX_PAGE_URL = `${GITHUB_BASE_URL}/2025/blob/main/apps/docs/src/content/docs/index.mdx`
const CUHACKING_2025_LANDING_PAGE_GITHUB_REPOSITORY_URL = `${GITHUB_BASE_URL}/landing-page`

const CUHACKING_2025_DOCS_URL = `${DOCS_BASE_URL}/docs`

const CUHACKING_2025_LANDING_PAGE_URL = 'https://cuhacking.ca/'

/* ---------------- MOBILE + DESKTOP + TABLET ---------------- */
Expand All @@ -39,7 +37,7 @@ test.describe(`Common MOBILE, TABLET and DESKTOP Layout Elements`, {

test(`should take user to docs home page when cuHacking logo icon is clicked in header`, async ({ docsLayoutPage }) => {
await docsLayoutPage.cuHackingLogoIcon.click()
await expect(docsLayoutPage.page).toHaveURL(CUHACKING_2025_DOCS_URL)
await expect(docsLayoutPage.page).toHaveURL(DOCS_BASE_URL)
})

test(`should contain cuHacking logo Text in header`, async ({ docsLayoutPage }) => {
Expand All @@ -48,7 +46,7 @@ test.describe(`Common MOBILE, TABLET and DESKTOP Layout Elements`, {

test(`should take user to docs home page when cuHacking logo text is clicked in header`, async ({ docsLayoutPage }) => {
await docsLayoutPage.cuHackingLogoText.click()
await expect(docsLayoutPage.page).toHaveURL(CUHACKING_2025_DOCS_URL)
await expect(docsLayoutPage.page).toHaveURL(DOCS_BASE_URL)
})

test(`should contain last updated text in docs page footer for`, async ({ docsLayoutPage }) => {
Expand Down Expand Up @@ -285,9 +283,11 @@ test.describe('Unique Floating Table of Contents DESKTOP Elements', {
await expect(docsLayoutPage.editOnGitHubButton).toBeVisible()
})

test('should take user to current docs page file on the cuHacking Hacker Portal GitHub repository when the \'Edit on GitHub\' icon is clicked', async ({ docsLayoutPage }) => {
await clickAndGoToPage(docsLayoutPage, docsLayoutPage.editOnGitHubButton, CUHACKING_2025_PLATFORM_GITHUB_INDEX_PAGE_URL)
})
// test('should take user to current docs page file on the cuHacking Hacker Portal GitHub repository when the \'Edit on GitHub\' icon is clicked', async ({ docsLayoutPage }) => {
// FIXME: navigate to a different page, click the button, and check that the url is the corresponding file on the GitHub repo.
// Currently the test checks it against the index page instead of the current page. Also see TODO in `(docs)/page.tsx`.
// await clickAndGoToPage(docsLayoutPage, docsLayoutPage.editOnGitHubButton, CUHACKING_2025_PLATFORM_GITHUB_INDEX_PAGE_URL)
// })
})

/* ---------------- UNIQUE MOBILE HEADER ---------------- */
Expand Down
7 changes: 6 additions & 1 deletion apps/docs-e2e/src/helpers/click-and-go-to-page.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,14 @@
import type { Locator, Page } from '@playwright/test'
import { expect } from '@playwright/test'

export async function clickAndGoToPage(layout: { page: Page }, button: Locator, expectedUrl: string) {
export async function clickAndGoToPage(
layout: { page: Page },
button: Locator,
expectedUrl: string,
) {
const pagePromise = layout.page.context().waitForEvent('page')
await button.click()
const newPage = await pagePromise
// TODO: factor out of this function, as helper functions should be pure actions, and not contain assertions
await expect(newPage).toHaveURL(expectedUrl)
}
4 changes: 2 additions & 2 deletions apps/docs-e2e/src/pom.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ export class DocsLayout {
this.mobileHackerPortalSourceLink = page.getByRole('link', { name: 'Source', exact: true })
this.mobileHackerAppLink = page.getByRole('link', { name: 'App', exact: true })
this.mobileWebsiteSourceLink = page.getByRole('link', { name: 'Source (legacy)' })
this.mobileGithubIcon = page.getByRole('link', { name: 'Github' })
this.mobileGithubIcon = page.getByRole('link', { name: 'Github', exact: true })
this.mobileHackerPortalProjectBoardLink = page.getByRole('link', { name: 'Project Board' })

// Desktop Sidebar
Expand All @@ -102,6 +102,6 @@ export class DocsLayout {
}

async goto() {
await this.page.goto('http://localhost:3000/docs')
await this.page.goto('http://localhost:3000')
}
}
5 changes: 3 additions & 2 deletions apps/docs/src/app/(docs)/[[...slug]]/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,14 @@ export default async function Page({
}

const MDX = page.data.exports.default
const path = `src/content/(docs)/${page.file.path}`
/* TODO: use the same variable for corresponding test, see FIXME in `docs.spec.ts` */
const path = `src/content/docs/${page.file.path}`
const gitHubRepoUrl = packageJson.repository.url.replace(/\.git$/, '') // Remove .git suffix

const footer = (
<>
<a
href={`${gitHubRepoUrl}/blob/main/apps/(docs)/${path}`}
href={`${gitHubRepoUrl}/blob/main/apps/docs/${path}`}
target="_blank"
rel="noreferrer noopener"
className="inline-flex items-center justify-center rounded-md font-medium ring-offset-background transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring disabled:pointer-events-none disabled:opacity-50 border bg-fd-secondary text-fd-secondary-foreground hover:bg-fd-secondary/80 h-9 px-3 text-xs gap-1.5"
Expand Down

0 comments on commit 6a9acb5

Please sign in to comment.