Skip to content

Commit

Permalink
chore: set default login state playwright (freeCodeCamp#57277)
Browse files Browse the repository at this point in the history
  • Loading branch information
Sembauke authored Nov 22, 2024
1 parent 6d5aeef commit f1b2a08
Show file tree
Hide file tree
Showing 60 changed files with 72 additions and 152 deletions.
1 change: 0 additions & 1 deletion e2e/c-sharp.spec.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { test, expect } from '@playwright/test';
import translations from '../client/i18n/locales/english/translations.json';
test.use({ storageState: 'playwright/.auth/certified-user.json' });
const checkAnswerButtonText = translations.buttons['check-answer'];
const askForHelpButtonText = translations.buttons['ask-for-help'];
const trophyButtonText = translations.buttons['verify-trophy'];
Expand Down
1 change: 0 additions & 1 deletion e2e/cert-username-case-navigation.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import { execSync } from 'child_process';
import { expect, test } from '@playwright/test';

test.describe('Public profile certifications', () => {
test.use({ storageState: 'playwright/.auth/certified-user.json' });
test('Should show claimed certifications if the username has all lowercase characters', async ({
page
}) => {
Expand Down
3 changes: 0 additions & 3 deletions e2e/certification.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@ import { test, expect, Page } from '@playwright/test';
import translations from '../client/i18n/locales/english/translations.json';
import { alertToBeVisible } from './utils/alerts';

test.use({ storageState: 'playwright/.auth/certified-user.json' });

test.describe('Certification page - Non Microsoft', () => {
test.beforeEach(async ({ page }) => {
await page.goto('/certification/certifieduser/responsive-web-design');
Expand Down Expand Up @@ -148,7 +146,6 @@ test.describe('Invalid certification page', () => {
}
};
test.describe('for authenticated user', () => {
test.use({ storageState: 'playwright/.auth/certified-user.json' });
test(
'it should redirect to / and display an error message',
testInvalidCertification
Expand Down
101 changes: 54 additions & 47 deletions e2e/challenge-reset-modal.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,61 +97,68 @@ test('User can reset challenge', async ({ page, isMobile, browserName }) => {
).not.toBeVisible();
});

test('User can reset classic challenge', async ({ page, isMobile }) => {
await page.goto(
'/learn/javascript-algorithms-and-data-structures/basic-javascript/comment-your-javascript-code'
);

const challengeSolution = '// This is in-line comment';
await focusEditor({ page, isMobile });
await getEditors(page).fill(challengeSolution);
test.describe('When the user is not logged in', () => {
test.use({ storageState: { cookies: [], origins: [] } });
test('User can reset classic challenge', async ({ page, isMobile }) => {
await page.goto(
'/learn/javascript-algorithms-and-data-structures/basic-javascript/comment-your-javascript-code'
);

const submitButton = page.getByRole('button', {
name: isMobile ? translations.buttons.run : translations.buttons['run-test']
});
await submitButton.click();
const challengeSolution = '// This is in-line comment';
await focusEditor({ page, isMobile });
await getEditors(page).fill(challengeSolution);

await expect(
page.locator('.view-lines').getByText(challengeSolution)
).toBeVisible();
const submitButton = page.getByRole('button', {
name: isMobile
? translations.buttons.run
: translations.buttons['run-test']
});
await submitButton.click();

if (isMobile) {
await page
.getByText(translations.learn['editor-tabs'].instructions)
.click();
}
await expect(
page.locator('.view-lines').getByText(challengeSolution)
).toBeVisible();

await expect(
page.getByLabel(translations.icons.passed).locator('circle')
).toBeVisible();
if (isMobile) {
await page
.getByText(translations.learn['editor-tabs'].instructions)
.click();
}

await page
.getByRole('button', {
name: !isMobile
? translations.buttons['reset-lesson']
: translations.buttons.reset
})
.click();
await expect(
page.getByLabel(translations.icons.passed).locator('circle')
).toBeVisible();

await page
.getByRole('button', { name: translations.buttons['reset-lesson'] })
.click();

await expect(
page.locator('.view-lines').getByText(challengeSolution)
).not.toBeVisible();
await expect(
page.getByLabel(translations.icons.passed).locator('circle')
).not.toBeVisible();
await expect(
page.getByText(translations.learn['tests-completed'])
).not.toBeVisible();
await page
.getByRole('button', {
name: !isMobile
? translations.buttons['reset-lesson']
: translations.buttons.reset
})
.click();

if (isMobile) {
await page.getByText(translations.learn['editor-tabs'].console).click();
}
await page
.getByRole('button', { name: translations.buttons['reset-lesson'] })
.click();

await expect(page.getByText(translations.learn['test-output'])).toBeVisible();
await expect(
page.locator('.view-lines').getByText(challengeSolution)
).not.toBeVisible();
await expect(
page.getByLabel(translations.icons.passed).locator('circle')
).not.toBeVisible();
await expect(
page.getByText(translations.learn['tests-completed'])
).not.toBeVisible();

if (isMobile) {
await page.getByText(translations.learn['editor-tabs'].console).click();
}

await expect(
page.getByText(translations.learn['test-output'])
).toBeVisible();
});
});

test('should close when the user clicks the close button', async ({ page }) => {
Expand Down
2 changes: 0 additions & 2 deletions e2e/challenge-title.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,6 @@ test.describe('Challenge Title Component (signed out)', () => {
});

test.describe('Challenge Title Component (signed in)', () => {
test.use({ storageState: 'playwright/.auth/certified-user.json' });

test('should display GreenPass after challenge completion', async ({
page
}) => {
Expand Down
1 change: 0 additions & 1 deletion e2e/code-storage.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import { test, expect } from '@playwright/test';

import { getEditors } from './utils/editor';

test.use({ storageState: 'playwright/.auth/certified-user.json' });
test.describe('Challenge with editor', function () {
test.skip(({ isMobile }) => isMobile);
test('the shortcut "Ctrl + S" saves the code', async ({ page }) => {
Expand Down
2 changes: 0 additions & 2 deletions e2e/codeally.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,6 @@ test.describe('Before completing the project', () => {
});

test.describe('After completing the project', () => {
test.use({ storageState: 'playwright/.auth/certified-user.json' });

test.beforeAll(() => {
execSync('node ./tools/scripts/seed/seed-demo-user --certified-user');
});
Expand Down
3 changes: 1 addition & 2 deletions e2e/completion-modal.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ test.beforeEach(async ({ page }) => {
});

test.describe('Challenge Completion Modal Tests (Signed Out)', () => {
test.use({ storageState: { cookies: [], origins: [] } });
test('should render the modal correctly', async ({ page }) => {
await expect(page.getByRole('heading')).toBeVisible();
await expect(page.getByRole('button', { name: 'close' })).toBeVisible();
Expand Down Expand Up @@ -83,8 +84,6 @@ test.describe('Challenge Completion Modal Tests (Signed Out)', () => {
});

test.describe('Challenge Completion Modal Tests (Signed In)', () => {
test.use({ storageState: 'playwright/.auth/certified-user.json' });

test('should render the modal correctly', async ({ page }) => {
await expect(page.getByRole('heading')).toBeVisible();
await expect(page.getByRole('button', { name: 'close' })).toBeVisible();
Expand Down
2 changes: 0 additions & 2 deletions e2e/delete-modal.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@ import { alertToBeVisible } from './utils/alerts';

const execP = promisify(exec);

test.use({ storageState: 'playwright/.auth/certified-user.json' });

test.beforeEach(async ({ page }) => {
await page.goto('/settings');
});
Expand Down
2 changes: 0 additions & 2 deletions e2e/desktop-layout.spec.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
import { test, expect } from '@playwright/test';

test.use({ storageState: 'playwright/.auth/certified-user.json' });

test.describe('Classic challenge - 3 pane desktop layout component', () => {
test.skip(
({ isMobile }) => isMobile === true,
Expand Down
2 changes: 0 additions & 2 deletions e2e/donate-page-default.spec.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
import { test, expect, type Page } from '@playwright/test';
import translations from '../client/i18n/locales/english/translations.json';

test.use({ storageState: 'playwright/.auth/certified-user.json' });

const pageElements = {
mainHeading: 'main-head',
donateText1: 'donate-text-1',
Expand Down
5 changes: 0 additions & 5 deletions e2e/donation-modal.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -117,8 +117,6 @@ test.describe('Donation modal display', () => {
await addGrowthbookCookie({ context, variation: 'A' });
});

test.use({ storageState: 'playwright/.auth/certified-user.json' });

test('should display the content correctly and disable close when the animation is not complete', async ({
page,
browserName,
Expand Down Expand Up @@ -292,7 +290,6 @@ test.describe('Donation modal appearance logic - New user', () => {
});

test.describe('Donation modal appearance logic - Certified user', () => {
test.use({ storageState: 'playwright/.auth/certified-user.json' });
test.beforeEach(async ({ context }) => {
await addGrowthbookCookie({ context, variation: 'A' });
});
Expand Down Expand Up @@ -333,8 +330,6 @@ test.describe('Donation modal appearance logic - Certified user', () => {
});

test.describe('Donation modal appearance logic - Donor user', () => {
test.use({ storageState: 'playwright/.auth/certified-user.json' });

test.beforeAll(() => {
execSync(
'node ./tools/scripts/seed/seed-demo-user --certified-user --set-true isDonating'
Expand Down
2 changes: 0 additions & 2 deletions e2e/edit-profile-modal.spec.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
import { test, expect } from '@playwright/test';
import translations from '../client/i18n/locales/english/translations.json';

test.use({ storageState: 'playwright/.auth/certified-user.json' });

test.beforeEach(async ({ page }) => {
await page.goto('/certifieduser');

Expand Down
4 changes: 0 additions & 4 deletions e2e/editor.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,6 @@ test.describe('Editor theme if the system theme is dark', () => {
test.use({ colorScheme: 'dark' });

test.describe('If the user is signed in', () => {
test.use({ storageState: 'playwright/.auth/certified-user.json' });

test('should respect the user settings', async ({ page, request }) => {
const editor = page.locator("div[role='code'].monaco-editor");

Expand Down Expand Up @@ -96,8 +94,6 @@ test.describe('Editor theme if the system theme is light', () => {
test.use({ colorScheme: 'light' });

test.describe('If the user is signed in', () => {
test.use({ storageState: 'playwright/.auth/certified-user.json' });

test('should respect the user settings', async ({ page, request }) => {
const editor = page.locator("div[role='code'].monaco-editor");

Expand Down
2 changes: 0 additions & 2 deletions e2e/email-settings.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,6 @@ const settingsPageElement = {
const originalEmail = '[email protected]';
const newEmail = '[email protected]';

test.use({ storageState: 'playwright/.auth/certified-user.json' });

test.beforeEach(async ({ page }) => {
execSync('node ./tools/scripts/seed/seed-demo-user --certified-user');
await page.goto('/settings');
Expand Down
2 changes: 0 additions & 2 deletions e2e/exam-results-modal.spec.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
import { test, expect } from '@playwright/test';

test.use({ storageState: 'playwright/.auth/certified-user.json' });

test.describe('Exam results modal', () => {
test.beforeEach(async ({ page }) => {
await page.goto('/settings');
Expand Down
2 changes: 0 additions & 2 deletions e2e/exam-results.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@ import { test, expect } from '@playwright/test';
import translations from '../client/i18n/locales/english/translations.json';
import intro from '../client/i18n/locales/english/intro.json';

test.use({ storageState: 'playwright/.auth/certified-user.json' });

const examUrl =
'/learn/foundational-c-sharp-with-microsoft/foundational-c-sharp-with-microsoft-certification-exam/foundational-c-sharp-with-microsoft-certification-exam';

Expand Down
2 changes: 1 addition & 1 deletion e2e/exam-show-non-qualified.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import translations from '../client/i18n/locales/english/translations.json';

const examUrl =
'/learn/foundational-c-sharp-with-microsoft/foundational-c-sharp-with-microsoft-certification-exam/foundational-c-sharp-with-microsoft-certification-exam';

test.use({ storageState: { cookies: [], origins: [] } });
test.beforeEach(async ({ page }) => {
await page.goto(examUrl);
});
Expand Down
2 changes: 0 additions & 2 deletions e2e/exam-show-qualified.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@ import { test, expect } from '@playwright/test';
import intro from '../client/i18n/locales/english/intro.json';
import translations from '../client/i18n/locales/english/translations.json';

test.use({ storageState: 'playwright/.auth/certified-user.json' });

const examUrl =
'/learn/foundational-c-sharp-with-microsoft/foundational-c-sharp-with-microsoft-certification-exam/foundational-c-sharp-with-microsoft-certification-exam';

Expand Down
2 changes: 0 additions & 2 deletions e2e/exam-started-show.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@ import { test, expect } from '@playwright/test';
import translations from '../client/i18n/locales/english/translations.json';
import intro from '../client/i18n/locales/english/intro.json';

test.use({ storageState: 'playwright/.auth/certified-user.json' });

const examUrl =
'/learn/foundational-c-sharp-with-microsoft/foundational-c-sharp-with-microsoft-certification-exam/foundational-c-sharp-with-microsoft-certification-exam';

Expand Down
1 change: 0 additions & 1 deletion e2e/exam-survey.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import { test, expect } from '@playwright/test';
const url =
'/learn/foundational-c-sharp-with-microsoft/foundational-c-sharp-with-microsoft-certification-exam/foundational-c-sharp-with-microsoft-certification-exam';
test.describe('Exam Survey', () => {
test.use({ storageState: 'playwright/.auth/certified-user.json' });
test.beforeAll(() => {
execSync('node ./tools/scripts/seed/seed-demo-user --certified-user');
execSync('node tools/scripts/seed/seed-surveys.js delete-only');
Expand Down
2 changes: 0 additions & 2 deletions e2e/exam-token.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@

// import { test, expect } from '@playwright/test';

// test.use({ storageState: 'playwright/.auth/certified-user.json' });

// test.beforeEach(async ({ page }) => {
// await page.goto('/settings');
// });
Expand Down
2 changes: 0 additions & 2 deletions e2e/exit-exam-modal.spec.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
import { test, expect } from '@playwright/test';
import translations from '../client/i18n/locales/english/translations.json';

test.use({ storageState: 'playwright/.auth/certified-user.json' });

const examUrl =
'/learn/foundational-c-sharp-with-microsoft/foundational-c-sharp-with-microsoft-certification-exam/foundational-c-sharp-with-microsoft-certification-exam';
const cancelExamUrl =
Expand Down
2 changes: 0 additions & 2 deletions e2e/finish-exam-modal.spec.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
import { test, expect } from '@playwright/test';
import translations from '../client/i18n/locales/english/translations.json';

test.use({ storageState: 'playwright/.auth/certified-user.json' });

const examUrl =
'/learn/foundational-c-sharp-with-microsoft/foundational-c-sharp-with-microsoft-certification-exam/foundational-c-sharp-with-microsoft-certification-exam';
const QUESTION_COUNT = 5;
Expand Down
1 change: 0 additions & 1 deletion e2e/flash.spec.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { test, expect, type Page } from '@playwright/test';
import translations from '../client/i18n/locales/english/translations.json';

test.use({ storageState: 'playwright/.auth/certified-user.json' });
test.beforeEach(async ({ page }) => {
await page.goto('/settings');
});
Expand Down
2 changes: 0 additions & 2 deletions e2e/form-helper.spec.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
import { test, expect } from '@playwright/test';
import translations from '../client/i18n/locales/english/translations.json';

test.use({ storageState: 'playwright/.auth/certified-user.json' });

test.describe('Test form with only solution link', () => {
test.beforeEach(async ({ page }) => {
await page.goto(
Expand Down
10 changes: 10 additions & 0 deletions e2e/global-setup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,12 @@ import { execSync } from 'child_process';
import { test as setup } from '@playwright/test';

setup.describe('certifieduser', () => {
setup.use({ storageState: { cookies: [], origins: [] } });

setup.beforeAll(() => {
execSync('node ./tools/scripts/seed/seed-demo-user --certified-user ');
});

setup('can sign in', async ({ request }) => {
await request.get(process.env.API_LOCATION + '/signin');
await request.storageState({
Expand All @@ -12,6 +18,10 @@ setup.describe('certifieduser', () => {
});

setup.describe('developmentuser', () => {
// We need to make sure the development user does not have any cookies from the certified user.
// Ass the certified user now has the default storage state.
setup.use({ storageState: { cookies: [], origins: [] } });

// We can only sign in as a single user (one with email: '[email protected]'), so
// changing users means changing the record with that email in the database.
setup.beforeAll(() => {
Expand Down
Loading

0 comments on commit f1b2a08

Please sign in to comment.