mirror of
https://github.com/freeCodeCamp/freeCodeCamp.git
synced 2025-12-20 18:45:55 -05:00
chore(e2e): use ControlOrMeta and remove browserName (#55326)
This commit is contained in:
@@ -43,7 +43,7 @@ test('should render the modal content correctly', async ({ page }) => {
|
|||||||
await expectToRenderResetModal(page);
|
await expectToRenderResetModal(page);
|
||||||
});
|
});
|
||||||
|
|
||||||
test('User can reset challenge', async ({ page, isMobile, browserName }) => {
|
test('User can reset challenge', async ({ page, isMobile }) => {
|
||||||
const initialText = 'CatPhotoApp';
|
const initialText = 'CatPhotoApp';
|
||||||
const initialFrame = page
|
const initialFrame = page
|
||||||
.frameLocator('iframe[title="challenge preview"]')
|
.frameLocator('iframe[title="challenge preview"]')
|
||||||
@@ -64,7 +64,7 @@ test('User can reset challenge', async ({ page, isMobile, browserName }) => {
|
|||||||
// Modify the text in the editor pane, clearing first, otherwise the existing
|
// Modify the text in the editor pane, clearing first, otherwise the existing
|
||||||
// text will be selected before typing
|
// text will be selected before typing
|
||||||
await focusEditor({ page, isMobile });
|
await focusEditor({ page, isMobile });
|
||||||
await clearEditor({ page, browserName });
|
await clearEditor({ page });
|
||||||
await getEditors(page).fill(updatedText);
|
await getEditors(page).fill(updatedText);
|
||||||
await expect(updatedFrame).toBeVisible({ timeout: 10000 });
|
await expect(updatedFrame).toBeVisible({ timeout: 10000 });
|
||||||
|
|
||||||
@@ -160,11 +160,7 @@ test('should close when the user clicks the close button', async ({ page }) => {
|
|||||||
).toBeHidden();
|
).toBeHidden();
|
||||||
});
|
});
|
||||||
|
|
||||||
test('User can reset on a multi-file project', async ({
|
test('User can reset on a multi-file project', async ({ page, isMobile }) => {
|
||||||
page,
|
|
||||||
isMobile,
|
|
||||||
browserName
|
|
||||||
}) => {
|
|
||||||
const sampleText = 'function palindrome() { return true; }';
|
const sampleText = 'function palindrome() { return true; }';
|
||||||
|
|
||||||
await page.goto(
|
await page.goto(
|
||||||
@@ -172,7 +168,7 @@ test('User can reset on a multi-file project', async ({
|
|||||||
);
|
);
|
||||||
|
|
||||||
await focusEditor({ page, isMobile });
|
await focusEditor({ page, isMobile });
|
||||||
await clearEditor({ page, browserName });
|
await clearEditor({ page });
|
||||||
await getEditors(page).fill(sampleText);
|
await getEditors(page).fill(sampleText);
|
||||||
await expect(page.getByText(sampleText)).toBeVisible();
|
await expect(page.getByText(sampleText)).toBeVisible();
|
||||||
|
|
||||||
@@ -202,8 +198,7 @@ test.describe('Signed in user', () => {
|
|||||||
|
|
||||||
test('User can reset on a multi-file project after reloading and saving', async ({
|
test('User can reset on a multi-file project after reloading and saving', async ({
|
||||||
page,
|
page,
|
||||||
isMobile,
|
isMobile
|
||||||
browserName
|
|
||||||
}) => {
|
}) => {
|
||||||
test.setTimeout(60000);
|
test.setTimeout(60000);
|
||||||
const savedText = 'function palindrome() { return true; }';
|
const savedText = 'function palindrome() { return true; }';
|
||||||
@@ -215,7 +210,7 @@ test.describe('Signed in user', () => {
|
|||||||
|
|
||||||
// This first edit should reappear after the reset
|
// This first edit should reappear after the reset
|
||||||
await focusEditor({ page, isMobile });
|
await focusEditor({ page, isMobile });
|
||||||
await clearEditor({ page, browserName });
|
await clearEditor({ page });
|
||||||
await getEditors(page).fill(savedText);
|
await getEditors(page).fill(savedText);
|
||||||
await page.keyboard.press('Control+S');
|
await page.keyboard.press('Control+S');
|
||||||
|
|
||||||
@@ -223,7 +218,7 @@ test.describe('Signed in user', () => {
|
|||||||
|
|
||||||
// This second edit should be reset
|
// This second edit should be reset
|
||||||
await focusEditor({ page, isMobile });
|
await focusEditor({ page, isMobile });
|
||||||
await clearEditor({ page, browserName });
|
await clearEditor({ page });
|
||||||
await getEditors(page).fill(updatedText);
|
await getEditors(page).fill(updatedText);
|
||||||
|
|
||||||
await page
|
await page
|
||||||
@@ -242,8 +237,7 @@ test.describe('Signed in user', () => {
|
|||||||
|
|
||||||
test('User can reset on a multi-file project without reloading', async ({
|
test('User can reset on a multi-file project without reloading', async ({
|
||||||
page,
|
page,
|
||||||
isMobile,
|
isMobile
|
||||||
browserName
|
|
||||||
}) => {
|
}) => {
|
||||||
test.setTimeout(60000);
|
test.setTimeout(60000);
|
||||||
const savedText = 'function palindrome() { return true; }';
|
const savedText = 'function palindrome() { return true; }';
|
||||||
@@ -255,13 +249,13 @@ test.describe('Signed in user', () => {
|
|||||||
|
|
||||||
// This first edit should reappear after the reset
|
// This first edit should reappear after the reset
|
||||||
await focusEditor({ page, isMobile });
|
await focusEditor({ page, isMobile });
|
||||||
await clearEditor({ page, browserName });
|
await clearEditor({ page });
|
||||||
await getEditors(page).fill(savedText);
|
await getEditors(page).fill(savedText);
|
||||||
await page.keyboard.press('Control+S');
|
await page.keyboard.press('Control+S');
|
||||||
|
|
||||||
// This second edit should be reset
|
// This second edit should be reset
|
||||||
await focusEditor({ page, isMobile });
|
await focusEditor({ page, isMobile });
|
||||||
await clearEditor({ page, browserName });
|
await clearEditor({ page });
|
||||||
await getEditors(page).fill(updatedText);
|
await getEditors(page).fill(updatedText);
|
||||||
|
|
||||||
await page
|
await page
|
||||||
|
|||||||
@@ -36,11 +36,9 @@ const completeFrontEndCert = async (page: Page) => {
|
|||||||
|
|
||||||
const completeThreeChallenges = async ({
|
const completeThreeChallenges = async ({
|
||||||
page,
|
page,
|
||||||
browserName,
|
|
||||||
isMobile
|
isMobile
|
||||||
}: {
|
}: {
|
||||||
page: Page;
|
page: Page;
|
||||||
browserName: string;
|
|
||||||
isMobile: boolean;
|
isMobile: boolean;
|
||||||
}) => {
|
}) => {
|
||||||
await page.goto(
|
await page.goto(
|
||||||
@@ -66,7 +64,7 @@ const completeThreeChallenges = async ({
|
|||||||
await page.waitForURL(challenge.url);
|
await page.waitForURL(challenge.url);
|
||||||
|
|
||||||
await focusEditor({ page, isMobile });
|
await focusEditor({ page, isMobile });
|
||||||
await clearEditor({ page, browserName });
|
await clearEditor({ page });
|
||||||
|
|
||||||
await page.evaluate(
|
await page.evaluate(
|
||||||
async contents => await navigator.clipboard.writeText(contents),
|
async contents => await navigator.clipboard.writeText(contents),
|
||||||
@@ -82,11 +80,9 @@ const completeThreeChallenges = async ({
|
|||||||
|
|
||||||
const completeTenChallenges = async ({
|
const completeTenChallenges = async ({
|
||||||
page,
|
page,
|
||||||
browserName,
|
|
||||||
isMobile
|
isMobile
|
||||||
}: {
|
}: {
|
||||||
page: Page;
|
page: Page;
|
||||||
browserName: string;
|
|
||||||
isMobile: boolean;
|
isMobile: boolean;
|
||||||
}) => {
|
}) => {
|
||||||
await page.goto(
|
await page.goto(
|
||||||
@@ -140,7 +136,7 @@ const completeTenChallenges = async ({
|
|||||||
await page.waitForURL(challenge.url);
|
await page.waitForURL(challenge.url);
|
||||||
|
|
||||||
await focusEditor({ page, isMobile });
|
await focusEditor({ page, isMobile });
|
||||||
await clearEditor({ page, browserName });
|
await clearEditor({ page });
|
||||||
|
|
||||||
await page.evaluate(
|
await page.evaluate(
|
||||||
async contents => await navigator.clipboard.writeText(contents),
|
async contents => await navigator.clipboard.writeText(contents),
|
||||||
|
|||||||
@@ -33,15 +33,14 @@ test.describe('Editor Component', () => {
|
|||||||
test.describe('Python Terminal', () => {
|
test.describe('Python Terminal', () => {
|
||||||
test('should display error message when the user enters invalid code', async ({
|
test('should display error message when the user enters invalid code', async ({
|
||||||
page,
|
page,
|
||||||
isMobile,
|
isMobile
|
||||||
browserName
|
|
||||||
}) => {
|
}) => {
|
||||||
await page.goto(
|
await page.goto(
|
||||||
'learn/scientific-computing-with-python/learn-string-manipulation-by-building-a-cipher/step-2'
|
'learn/scientific-computing-with-python/learn-string-manipulation-by-building-a-cipher/step-2'
|
||||||
);
|
);
|
||||||
|
|
||||||
await focusEditor({ page, isMobile });
|
await focusEditor({ page, isMobile });
|
||||||
await clearEditor({ page, browserName });
|
await clearEditor({ page });
|
||||||
// Then enter invalid code
|
// Then enter invalid code
|
||||||
await page.keyboard.insertText('def');
|
await page.keyboard.insertText('def');
|
||||||
const preview = page.getByTestId('preview-pane');
|
const preview = page.getByTestId('preview-pane');
|
||||||
|
|||||||
@@ -79,7 +79,6 @@ test('Checks hotkeys when instruction is focused', async ({
|
|||||||
|
|
||||||
test('Focuses on the submit button after tests passed', async ({
|
test('Focuses on the submit button after tests passed', async ({
|
||||||
page,
|
page,
|
||||||
browserName,
|
|
||||||
isMobile
|
isMobile
|
||||||
}) => {
|
}) => {
|
||||||
const editor = getEditors(page);
|
const editor = getEditors(page);
|
||||||
@@ -88,7 +87,7 @@ test('Focuses on the submit button after tests passed', async ({
|
|||||||
name: 'Submit and go to next challenge'
|
name: 'Submit and go to next challenge'
|
||||||
});
|
});
|
||||||
await focusEditor({ page, isMobile });
|
await focusEditor({ page, isMobile });
|
||||||
await clearEditor({ page, browserName });
|
await clearEditor({ page });
|
||||||
|
|
||||||
await editor.fill(
|
await editor.fill(
|
||||||
'<h2>Cat Photos</h2>\n<p>See more cat photos in our gallery.</p>'
|
'<h2>Cat Photos</h2>\n<p>See more cat photos in our gallery.</p>'
|
||||||
@@ -100,7 +99,6 @@ test('Focuses on the submit button after tests passed', async ({
|
|||||||
|
|
||||||
test('Prompts unauthenticated user to sign in to save progress', async ({
|
test('Prompts unauthenticated user to sign in to save progress', async ({
|
||||||
page,
|
page,
|
||||||
browserName,
|
|
||||||
isMobile
|
isMobile
|
||||||
}) => {
|
}) => {
|
||||||
await signout(page);
|
await signout(page);
|
||||||
@@ -111,7 +109,7 @@ test('Prompts unauthenticated user to sign in to save progress', async ({
|
|||||||
name: 'Sign in to save your progress'
|
name: 'Sign in to save your progress'
|
||||||
});
|
});
|
||||||
await focusEditor({ page, isMobile });
|
await focusEditor({ page, isMobile });
|
||||||
await clearEditor({ page, browserName });
|
await clearEditor({ page });
|
||||||
|
|
||||||
await editor.fill(
|
await editor.fill(
|
||||||
'<h2>Cat Photos</h2>\n<p>See more cat photos in our gallery.</p>'
|
'<h2>Cat Photos</h2>\n<p>See more cat photos in our gallery.</p>'
|
||||||
|
|||||||
@@ -61,13 +61,12 @@ test.describe('Should take you to the next superblock (with editor solution)', (
|
|||||||
test('at the end of a superblock should take you to the superblock page with the current block hash', async ({
|
test('at the end of a superblock should take you to the superblock page with the current block hash', async ({
|
||||||
page,
|
page,
|
||||||
isMobile,
|
isMobile,
|
||||||
browserName,
|
|
||||||
context
|
context
|
||||||
}) => {
|
}) => {
|
||||||
await context.grantPermissions(['clipboard-read', 'clipboard-write']);
|
await context.grantPermissions(['clipboard-read', 'clipboard-write']);
|
||||||
await page.goto(rwdChallenge.url);
|
await page.goto(rwdChallenge.url);
|
||||||
await focusEditor({ page, isMobile });
|
await focusEditor({ page, isMobile });
|
||||||
await clearEditor({ page, browserName });
|
await clearEditor({ page });
|
||||||
|
|
||||||
await page.evaluate(
|
await page.evaluate(
|
||||||
async solution => await navigator.clipboard.writeText(solution.content),
|
async solution => await navigator.clipboard.writeText(solution.content),
|
||||||
|
|||||||
@@ -70,15 +70,14 @@ test.describe('For classic challenges', () => {
|
|||||||
|
|
||||||
test('shows test output when the tests are run', async ({
|
test('shows test output when the tests are run', async ({
|
||||||
page,
|
page,
|
||||||
isMobile,
|
isMobile
|
||||||
browserName
|
|
||||||
}) => {
|
}) => {
|
||||||
const closeButton = page.getByRole('button', { name: 'Close' });
|
const closeButton = page.getByRole('button', { name: 'Close' });
|
||||||
await expect(page).toHaveTitle(
|
await expect(page).toHaveTitle(
|
||||||
'Basic HTML and HTML5: Say Hello to HTML Elements |' + ' freeCodeCamp.org'
|
'Basic HTML and HTML5: Say Hello to HTML Elements |' + ' freeCodeCamp.org'
|
||||||
);
|
);
|
||||||
|
|
||||||
await clearEditor({ browserName, page });
|
await clearEditor({ page });
|
||||||
await insertTextInCodeEditor({
|
await insertTextInCodeEditor({
|
||||||
page,
|
page,
|
||||||
isMobile,
|
isMobile,
|
||||||
@@ -95,11 +94,10 @@ test.describe('For classic challenges', () => {
|
|||||||
|
|
||||||
test('shows test output when the tests are triggered by the keyboard', async ({
|
test('shows test output when the tests are triggered by the keyboard', async ({
|
||||||
page,
|
page,
|
||||||
isMobile,
|
isMobile
|
||||||
browserName
|
|
||||||
}) => {
|
}) => {
|
||||||
const closeButton = page.getByRole('button', { name: 'Close' });
|
const closeButton = page.getByRole('button', { name: 'Close' });
|
||||||
await clearEditor({ browserName, page });
|
await clearEditor({ page });
|
||||||
await insertTextInCodeEditor({
|
await insertTextInCodeEditor({
|
||||||
page,
|
page,
|
||||||
isMobile,
|
isMobile,
|
||||||
|
|||||||
@@ -6,8 +6,7 @@ test.use({ storageState: 'playwright/.auth/certified-user.json' });
|
|||||||
test.describe('Progress bar component', () => {
|
test.describe('Progress bar component', () => {
|
||||||
test('Should appear with the correct content after the user has submitted their code', async ({
|
test('Should appear with the correct content after the user has submitted their code', async ({
|
||||||
page,
|
page,
|
||||||
isMobile,
|
isMobile
|
||||||
browserName
|
|
||||||
}) => {
|
}) => {
|
||||||
await page.goto(
|
await page.goto(
|
||||||
'/learn/2022/responsive-web-design/learn-html-by-building-a-cat-photo-app/step-3'
|
'/learn/2022/responsive-web-design/learn-html-by-building-a-cat-photo-app/step-3'
|
||||||
@@ -16,7 +15,7 @@ test.describe('Progress bar component', () => {
|
|||||||
// large. There's a bug that means `scrollIntoView` does not work in the
|
// large. There's a bug that means `scrollIntoView` does not work in the
|
||||||
// editor and so we have to pick less verbose challenges until that's fixed.
|
// editor and so we have to pick less verbose challenges until that's fixed.
|
||||||
await focusEditor({ page, isMobile });
|
await focusEditor({ page, isMobile });
|
||||||
await clearEditor({ page, browserName });
|
await clearEditor({ page });
|
||||||
|
|
||||||
await page.keyboard.insertText(
|
await page.keyboard.insertText(
|
||||||
'<html><body><h1>CatPhotoApp</h1><h2>Cat Photos</h2><p>See more cat photos in our gallery.</p></body></html>'
|
'<html><body><h1>CatPhotoApp</h1><h2>Cat Photos</h2><p>See more cat photos in our gallery.</p></body></html>'
|
||||||
@@ -36,14 +35,13 @@ test.describe('Progress bar component', () => {
|
|||||||
|
|
||||||
test('should appear in the completion modal after user has submitted their code', async ({
|
test('should appear in the completion modal after user has submitted their code', async ({
|
||||||
page,
|
page,
|
||||||
isMobile,
|
isMobile
|
||||||
browserName
|
|
||||||
}) => {
|
}) => {
|
||||||
await page.goto(
|
await page.goto(
|
||||||
'/learn/javascript-algorithms-and-data-structures/basic-javascript/declare-javascript-variables'
|
'/learn/javascript-algorithms-and-data-structures/basic-javascript/declare-javascript-variables'
|
||||||
);
|
);
|
||||||
await focusEditor({ page, isMobile });
|
await focusEditor({ page, isMobile });
|
||||||
await clearEditor({ page, browserName });
|
await clearEditor({ page });
|
||||||
|
|
||||||
await page.keyboard.insertText('var myName;');
|
await page.keyboard.insertText('var myName;');
|
||||||
|
|
||||||
|
|||||||
@@ -110,7 +110,6 @@ test.describe('JavaScript projects can be submitted and then viewed in /settings
|
|||||||
|
|
||||||
test('projects are submitted and viewed correctly', async ({
|
test('projects are submitted and viewed correctly', async ({
|
||||||
page,
|
page,
|
||||||
browserName,
|
|
||||||
isMobile,
|
isMobile,
|
||||||
request,
|
request,
|
||||||
context
|
context
|
||||||
@@ -149,7 +148,7 @@ test.describe('JavaScript projects can be submitted and then viewed in /settings
|
|||||||
);
|
);
|
||||||
|
|
||||||
await focusEditor({ page, isMobile });
|
await focusEditor({ page, isMobile });
|
||||||
await clearEditor({ page, browserName });
|
await clearEditor({ page });
|
||||||
|
|
||||||
await page.evaluate(
|
await page.evaluate(
|
||||||
async contents => await navigator.clipboard.writeText(contents),
|
async contents => await navigator.clipboard.writeText(contents),
|
||||||
|
|||||||
@@ -24,18 +24,7 @@ export const focusEditor = async ({
|
|||||||
await getEditors(page).focus();
|
await getEditors(page).focus();
|
||||||
};
|
};
|
||||||
|
|
||||||
export async function clearEditor({
|
export async function clearEditor({ page }: { page: Page }) {
|
||||||
page,
|
await page.keyboard.press('ControlOrMeta+a');
|
||||||
browserName
|
|
||||||
}: {
|
|
||||||
page: Page;
|
|
||||||
browserName: string;
|
|
||||||
}) {
|
|
||||||
// TODO: replace with ControlOrMeta when it's supported
|
|
||||||
if (browserName === 'webkit') {
|
|
||||||
await page.keyboard.press('Meta+a');
|
|
||||||
} else {
|
|
||||||
await page.keyboard.press('Control+a');
|
|
||||||
}
|
|
||||||
await page.keyboard.press('Backspace');
|
await page.keyboard.press('Backspace');
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user