From fc00659d730186661e2626d3e147ae83705a41ec Mon Sep 17 00:00:00 2001 From: April Hall Date: Wed, 26 Feb 2025 10:11:07 -0500 Subject: [PATCH] feat: Add tests for signup --- bun.lockb | Bin 241190 -> 241190 bytes playwright.config.ts | 27 ++++++++++++++++++++++++--- tests/signup.setup.ts | 6 ++++++ tests/updateUsername.spec.ts | 5 +++-- tests/utils.ts | 13 +++++++++++-- 5 files changed, 44 insertions(+), 7 deletions(-) create mode 100644 tests/signup.setup.ts diff --git a/bun.lockb b/bun.lockb index a78075dd655702a947637608382e46e61f653bc1..87c3dab527fed1706349eacb5c94849d074b8916 100755 GIT binary patch delta 1595 zcmXZcYix{J9LMpQe^u-YrKW>HQAM}o+6WVwNVHTDw`rAKp^BD{-e=ls-C9*sgs9!N z$0aIWbnGU(vKyCCb%{${61xd6Tw7IDw<6*ix9~mkJjo~j-<)%vbLKfG&*N_j@i&E( zRhW;+^A+R!i|NO;kZLAb5JnE7E;8D}$U}^ADMp)Bg=UB)v?pCXjILCwsA(C}*IKKm z;z~0{+sHMlBt!O_>y*tcQD&Elb&JKCzyLkH*BCg2>`-pEI7eJ0>Z{o3iY8w|Ka?14 zcJg(Y)HOY+J@C;jht1XmmXAX`CgTmmU#qj3vN58C2fK|X+`=8)#Xa0Wvr5kr$4|qF z!(dnSSrS?LjtM^CE#Bh++VBwVc#M-cg+`pf8JtD~j^Y>sIF2pYiq+81qMxx4Md*c} zp-*N628$`hG>p(4{V)Kb&_`m$KnzE3M4%6%5sq#cib2rl6a_o_!iGp#RDHJ0xBbpW zRiPUC{Ay5+3KgCs&e*QR5bR;ME3p%su>)IBh2Nl1i(RP3ZfwJLwKGS?gcq`@1@Isj zd1$Bm5gw}69EqHnMALjEA{lcLOZO}4K5CsFPM*lW>4J0QT2!M3J5Ytas8g<78IZk< zTT-wHnMg%8(vXfNSc(;JBLgdugIp}ea%ABkOA1qeX6rsdzbenD9e9pr)yk6Q7WFk( z9NBAWDaQt^M;YpwVGcD3^N@^0#33F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b_v3VHqM3jXChcAb1#WBAOwv zpr6`VG^-9-`J<$aRPs+e5VBX?If*Idz>=Lyiy%;O7P5M z+}wtTXvbr8;4bc=0oQQ>7jZ(paY~}?IO#w57thg&`#6I?(V`qKnKk=A(iiw2FYyYm z;YBMvyw6c|aDLseV34}y;#KwEdZg-g$&C0;7S)9wgu;f6bce%^80ep?{?W$bAhR5X w8w$Hoj1pYosaKVwK*9qbk>11&_zdrfAG}Qk5;kHmGYzyVpIf{>x5Xav8OGH6J^%m! diff --git a/playwright.config.ts b/playwright.config.ts index a96f63d..2bb2182 100644 --- a/playwright.config.ts +++ b/playwright.config.ts @@ -1,12 +1,33 @@ -import { defineConfig } from '@playwright/test'; +import { defineConfig, devices } from '@playwright/test'; export default defineConfig({ testDir: 'tests', + projects: [ + { + name: 'signup', + testMatch: /signup\.setup\.ts/, + use: { ...devices['Desktop Chrome'] }, + }, + + // Make all other tests depend on the signup, + // since they need user accounts to run + + { + name: 'tests', + use: { ...devices['Desktop Chrome'] }, + dependencies: ['signup'], + testMatch: /(.+\.)?(test|spec)\.[jt]s/, + fullyParallel: true, + }, + ], reporter: 'list', - testMatch: /(.+\.)?(test|spec)\.[jt]s/, webServer: { command: 'npm run dev', - port: 5174, + port: 5173, reuseExistingServer: true, }, + use: { + baseURL: 'http://localhost:5173', + trace: 'on-first-retry', + }, }); diff --git a/tests/signup.setup.ts b/tests/signup.setup.ts new file mode 100644 index 0000000..3a19843 --- /dev/null +++ b/tests/signup.setup.ts @@ -0,0 +1,6 @@ +import { test } from '@playwright/test'; +import { signup } from './utils'; + +test('Signup', async ({ page }) => { + await signup(page); +}); diff --git a/tests/updateUsername.spec.ts b/tests/updateUsername.spec.ts index 9171e30..3424101 100644 --- a/tests/updateUsername.spec.ts +++ b/tests/updateUsername.spec.ts @@ -1,7 +1,6 @@ import { test, expect, type Page, type Locator } from '@playwright/test'; import { login } from './utils'; -test.describe.configure({ mode: 'parallel' }); test.describe('Username Update Form', () => { let page: Page; let usernameInput: Locator; @@ -17,11 +16,12 @@ test.describe('Username Update Form', () => { currentUsernameElement = page.locator('#currentuser-username'); await login(page); - page.goto('http://localhost:5173/account'); + page.goto('/account'); }); // Test that the username will change test('should successfully update the username', async () => { + await page.waitForLoadState('domcontentloaded'); await usernameInput.fill(newUsername); await submitButton.click(); @@ -36,6 +36,7 @@ test.describe('Username Update Form', () => { // Test invalidator test('should show validation error for invalid username', async () => { + await page.waitForLoadState('domcontentloaded'); await usernameInput.fill('a'); await submitButton.click(); diff --git a/tests/utils.ts b/tests/utils.ts index 00192ec..99b2639 100644 --- a/tests/utils.ts +++ b/tests/utils.ts @@ -1,10 +1,19 @@ import type { Page } from '@playwright/test'; export async function login(page: Page): Promise { - await page.goto('http://localhost:5174/login'); + await page.goto('/login'); await page.waitForLoadState('domcontentloaded'); - console.log('loaded'); await page.fill('#email', 'playwright@playwright.com'); await page.fill('#password', 'Password1234!'); await page.click('button[type="submit"]'); } + +export async function signup(page: Page): Promise { + await page.goto('/signup'); + await page.waitForLoadState('domcontentloaded'); + await page.fill('#username', 'playwrightuser'); + await page.fill('#email', 'playwright@playwright.com'); + await page.fill('#password', 'Password1234!'); + await page.fill('#verify', 'Password1234!'); + await page.click('button[type="submit"]'); +}