mirror of
https://github.com/freeCodeCamp/freeCodeCamp.git
synced 2025-12-25 02:14:11 -05:00
test(e2e): allow testing of multiple users (#54752)
This commit is contained in:
committed by
GitHub
parent
372bb9f38a
commit
86860e85a5
@@ -1,9 +1,31 @@
|
||||
import { execSync } from 'child_process';
|
||||
|
||||
import { test as setup } from '@playwright/test';
|
||||
|
||||
setup('Login', async ({ page }) => {
|
||||
await page.goto('/');
|
||||
await page.getByRole('link', { name: 'Sign in' }).click();
|
||||
await page
|
||||
.context()
|
||||
.storageState({ path: 'playwright/.auth/certified-user.json' });
|
||||
setup.describe('certifieduser', () => {
|
||||
setup('can sign in', async ({ request }) => {
|
||||
await request.get(process.env.API_LOCATION + '/signin');
|
||||
await request.storageState({
|
||||
path: 'playwright/.auth/certified-user.json'
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
setup.describe('developmentuser', () => {
|
||||
// We can only sign in as a single user (one with email: 'foo@bar.com'), so
|
||||
// changing users means changing the record with that email in the database.
|
||||
setup.beforeAll(() => {
|
||||
execSync('node ./tools/scripts/seed/seed-demo-user');
|
||||
});
|
||||
|
||||
setup.afterAll(() => {
|
||||
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({
|
||||
path: 'playwright/.auth/development-user.json'
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
13
e2e/signin.spec.ts
Normal file
13
e2e/signin.spec.ts
Normal file
@@ -0,0 +1,13 @@
|
||||
import { test, expect } from '@playwright/test';
|
||||
|
||||
test.describe('signing in', () => {
|
||||
test('welcomes the user', async ({ page }) => {
|
||||
const welcomeText = 'Welcome back, Full Stack User.';
|
||||
await page.goto('/');
|
||||
await expect(page.getByText(welcomeText)).not.toBeVisible();
|
||||
|
||||
await page.getByRole('link', { name: 'Sign in' }).click();
|
||||
|
||||
await expect(page.getByText(welcomeText)).toBeVisible();
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user