-
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.
Merge pull request #193 from UoaWDCC/UABC-onboard
Onboarding flow
- Loading branch information
Showing
16 changed files
with
364 additions
and
8 deletions.
There are no files selected for viewing
File renamed without changes.
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,51 @@ | ||
name: E2E Playwright Tests | ||
|
||
on: | ||
pull_request: | ||
branches: | ||
- main | ||
push: | ||
branches: [main] | ||
|
||
jobs: | ||
test: | ||
timeout-minutes: 60 | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v4 | ||
|
||
- uses: pnpm/action-setup@v3 | ||
name: Setup pnpm | ||
with: | ||
version: 8 | ||
|
||
- name: Set up Node.js version | ||
uses: actions/setup-node@v4 | ||
with: | ||
node-version: 20 | ||
cache: "pnpm" | ||
|
||
- name: Install dependencies | ||
run: pnpm install | ||
|
||
- name: Install Playwright Browsers | ||
run: pnpm exec playwright install --with-deps | ||
|
||
- name: Create env file | ||
run: echo ${{ secrets.UABC_DEV_BACKEND_ENVFILE }} | base64 --decode > .env | ||
|
||
- name: Build Next app | ||
env: | ||
CI: true | ||
run: | | ||
pnpm build | ||
- name: Run Playwright tests | ||
run: pnpm test:e2e | ||
|
||
- uses: actions/upload-artifact@v4 | ||
if: always() | ||
with: | ||
name: playwright-report | ||
path: playwright-report/ | ||
retention-days: 30 |
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 |
---|---|---|
|
@@ -42,3 +42,7 @@ next-env.d.ts | |
|
||
# env files | ||
.env | ||
/test-results/ | ||
/playwright-report/ | ||
/blob-report/ | ||
/playwright/.cache/ |
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,77 @@ | ||
import { defineConfig, devices } from "@playwright/test"; | ||
|
||
/** | ||
* Read environment variables from file. | ||
* https://github.com/motdotla/dotenv | ||
*/ | ||
// require('dotenv').config(); | ||
|
||
/** | ||
* See https://playwright.dev/docs/test-configuration. | ||
*/ | ||
export default defineConfig({ | ||
testDir: "./playwright", | ||
/* Run tests in files in parallel */ | ||
fullyParallel: true, | ||
/* Fail the build on CI if you accidentally left test.only in the source code. */ | ||
forbidOnly: !!process.env.CI, | ||
/* Retry on CI only */ | ||
retries: process.env.CI ? 2 : 0, | ||
/* Opt out of parallel tests on CI. */ | ||
workers: process.env.CI ? 1 : undefined, | ||
/* Reporter to use. See https://playwright.dev/docs/test-reporters */ | ||
reporter: "html", | ||
/* Shared settings for all the projects below. See https://playwright.dev/docs/api/class-testoptions. */ | ||
use: { | ||
/* Base URL to use in actions like `await page.goto('/')`. */ | ||
baseURL: "http://localhost:3000", | ||
|
||
/* Collect trace when retrying the failed test. See https://playwright.dev/docs/trace-viewer */ | ||
trace: "on-first-retry", | ||
}, | ||
|
||
/* Configure projects for major browsers */ | ||
projects: [ | ||
{ | ||
name: "chromium", | ||
use: { ...devices["Desktop Chrome"] }, | ||
}, | ||
|
||
// { | ||
// name: "firefox", | ||
// use: { ...devices["Desktop Firefox"] }, | ||
// }, | ||
|
||
// { | ||
// name: "webkit", | ||
// use: { ...devices["Desktop Safari"] }, | ||
// }, | ||
|
||
/* Test against mobile viewports. */ | ||
// { | ||
// name: 'Mobile Chrome', | ||
// use: { ...devices['Pixel 5'] }, | ||
// }, | ||
// { | ||
// name: 'Mobile Safari', | ||
// use: { ...devices['iPhone 12'] }, | ||
// }, | ||
|
||
/* Test against branded browsers. */ | ||
// { | ||
// name: 'Microsoft Edge', | ||
// use: { ...devices['Desktop Edge'], channel: 'msedge' }, | ||
// }, | ||
// { | ||
// name: 'Google Chrome', | ||
// use: { ...devices['Desktop Chrome'], channel: 'chrome' }, | ||
// }, | ||
], | ||
|
||
/* Run your local dev server before starting the tests */ | ||
webServer: { | ||
command: "npm run start", | ||
url: "http://127.0.0.1:3000", | ||
reuseExistingServer: !process.env.CI, | ||
}, | ||
}); |
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,58 @@ | ||
import { expect, test } from "@playwright/test"; | ||
|
||
import { signUpAndLogin } from "./utils/helper"; | ||
import { generateMockOnboardingUser } from "./utils/mock"; | ||
|
||
test.beforeEach(async ({ page }) => { | ||
const user = generateMockOnboardingUser(); | ||
await signUpAndLogin(page, user.email, user.password); | ||
}); | ||
|
||
test.afterEach(async ({ page }) => { | ||
// await is necessary so test context is not disposed before the request is completed | ||
await page.request | ||
.get(`/api/auth/session`) | ||
.then((res) => res.json()) | ||
.then(async ({ user }) => { | ||
await page.request.delete(`/api/users/${user.id}`); | ||
}); | ||
}); | ||
|
||
test.describe("Onboarding flow", () => { | ||
test("should navigate to the name page", async ({ page }) => { | ||
await expect(page).toHaveURL("/onboarding/name"); | ||
}); | ||
|
||
test("should navigate to the member page", async ({ page }) => { | ||
await page.goto("/onboard/name"); | ||
await page.getByRole("textbox").nth(0).fill("John"); | ||
await page.getByRole("textbox").nth(1).fill("Doe"); | ||
await page.click("text=Continue"); | ||
await expect(page).toHaveURL("onboarding/member"); | ||
}); | ||
test("should navigate to the session page", async ({ page }) => { | ||
await page.goto("/onboard/name"); | ||
await page.getByRole("textbox").nth(0).fill("John"); | ||
await page.getByRole("textbox").nth(1).fill("Doe"); | ||
await page.click("text=Continue"); | ||
await page.click("text=Prepaid Member"); | ||
await page.click("text=Next"); | ||
await expect(page).toHaveURL("sessions"); | ||
}); | ||
test("should fill in first name and last name before continuing", async ({ | ||
page, | ||
}) => { | ||
await page.goto("/onboard/name"); | ||
const continueButton = await page.locator("text=Continue"); | ||
await expect(continueButton).toBeDisabled(); | ||
}); | ||
|
||
test("should select membership type before continuing", async ({ page }) => { | ||
await page.goto("/onboard/name"); | ||
await page.getByRole("textbox").nth(0).fill("John"); | ||
await page.getByRole("textbox").nth(1).fill("Doe"); | ||
await page.click("text=Continue"); | ||
const nextButton = await page.locator("text=Next"); | ||
await expect(nextButton).toBeDisabled(); | ||
}); | ||
}); |
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,30 @@ | ||
import type { Page } from "@playwright/test"; | ||
|
||
export const signUpAndLogin = async ( | ||
page: Page, | ||
email: string, | ||
password: string, | ||
): Promise<void> => { | ||
await page.request.post(`/api/auth/register`, { | ||
data: { | ||
email, | ||
password, | ||
}, | ||
}); | ||
|
||
const res = await page.request.get(`/api/auth/csrf`); | ||
const { csrfToken } = await res.json(); | ||
|
||
await page.goto("/"); | ||
|
||
// page.request stores cookies between requests | ||
await page.request.post(`/api/auth/callback/credentials`, { | ||
data: { | ||
email, | ||
password, | ||
csrfToken, | ||
}, | ||
}); | ||
|
||
await page.reload(); | ||
}; |
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,4 @@ | ||
export const generateMockOnboardingUser = () => ({ | ||
email: crypto.randomUUID() + "@onboarding.com", | ||
password: "231Xh7D&dM8u75EjIYV", | ||
}); |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
Oops, something went wrong.