forked from freeCodeCamp/freeCodeCamp
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: convert "navigation tests spec" to Playwright (freeCodeCamp#54944)
Co-authored-by: Huyen Nguyen <[email protected]>
- Loading branch information
1 parent
58b3218
commit 020a8c5
Showing
10 changed files
with
102 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{ | ||
"content": "<head><style>@media (max-width: 500px){nav{display: none;}}</style></head><body><nav id=\"navbar\"><a href=\"#projects\">text</a> | </nav><main><section id=\"welcome-section\"><h1>text</h1></section><hr><section id=\"projects\"><h1>Projects</h1><h2 class=\"project-tile\"><a id=\"profile-link\" target=\"_blank\" href=\"https://freecodecamp.org\">text</a></h2></section><hr></body></html>" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
import { test } from '@playwright/test'; | ||
import solution from './fixtures/build-a-personal-portfolio-webpage.json'; | ||
import { clearEditor, focusEditor } from './utils/editor'; | ||
import { isMacOS } from './utils/user-agent'; | ||
|
||
// middle of block | ||
const challenge1 = { | ||
url: '/learn/front-end-development-libraries/front-end-development-libraries-projects/build-a-javascript-calculator', | ||
nextUrl: | ||
'/learn/front-end-development-libraries/front-end-development-libraries-projects/build-a-25--5-clock' | ||
}; | ||
|
||
// last in superblock | ||
const challenge2 = { | ||
url: '/learn/college-algebra-with-python/build-a-data-graph-explorer-project/build-a-data-graph-explorer', | ||
nextUrl: | ||
'/learn/college-algebra-with-python/#build-a-data-graph-explorer-project' | ||
}; | ||
|
||
const rwdChallenge = { | ||
url: '/learn/2022/responsive-web-design/build-a-personal-portfolio-webpage-project/build-a-personal-portfolio-webpage', | ||
nextUrl: | ||
'/learn/2022/responsive-web-design/#build-a-personal-portfolio-webpage-project' | ||
}; | ||
test.use({ storageState: 'playwright/.auth/certified-user.json' }); | ||
test.describe('Navigation from the middle or end (URL solution)', () => { | ||
test('In the middle of a block should take you to the next challenge', async ({ | ||
page | ||
}) => { | ||
await page.goto(challenge1.url); | ||
await page | ||
.getByRole('textbox', { name: 'solution' }) | ||
.fill('https://example.com'); | ||
await page.keyboard.press('Enter'); | ||
await page | ||
.getByRole('button', { name: 'Submit and go to next challenge' }) | ||
.click(); | ||
await page.waitForURL(challenge1.nextUrl); | ||
}); | ||
|
||
test('at the end of a superblock should take you to the superblock page with the current block hash', async ({ | ||
page | ||
}) => { | ||
await page.goto(challenge2.url); | ||
await page | ||
.getByRole('textbox', { name: 'solution' }) | ||
.fill('https://example.com'); | ||
await page.keyboard.press('Enter'); | ||
await page | ||
.getByRole('button', { name: 'Submit and go to next challenge' }) | ||
.click(); | ||
await page.waitForURL(challenge2.nextUrl); | ||
}); | ||
}); | ||
|
||
test.describe('Should take you to the next superblock (with editor solution)', () => { | ||
test.skip( | ||
({ browserName }) => browserName !== 'chromium', | ||
'Only chromium allows us to use the clipboard API.' | ||
); | ||
test('at the end of a superblock should take you to the superblock page with the current block hash', async ({ | ||
page, | ||
isMobile, | ||
browserName, | ||
context | ||
}) => { | ||
await context.grantPermissions(['clipboard-read', 'clipboard-write']); | ||
await page.goto(rwdChallenge.url); | ||
await focusEditor({ page, isMobile }); | ||
await clearEditor({ page, browserName }); | ||
|
||
await page.evaluate( | ||
async solution => await navigator.clipboard.writeText(solution.content), | ||
solution | ||
); | ||
|
||
if (isMacOS) { | ||
await page.keyboard.press('Meta+v'); | ||
} else { | ||
await page.keyboard.press('Control+v'); | ||
} | ||
|
||
await page.keyboard.press('Control+Enter'); | ||
|
||
await page | ||
.getByRole('button', { name: 'Submit and go to next challenge' }) | ||
.click(); | ||
await page.waitForURL(rwdChallenge.nextUrl); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters