Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(ci): install Playwright for e2e tests and create e2e test for signup #456

Merged
merged 24 commits into from
Apr 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
a35f7c9
feat(ci): install and configure Playwright
lemilonkh Apr 18, 2024
ab986ed
feat(ci): add Playwright suggested GitHub Action
lemilonkh Apr 18, 2024
e42ebe5
fix(ci): run Playwright tests in app directory
lemilonkh Apr 22, 2024
75d1704
fix(ci): set default working directory to app and cache node dependen…
lemilonkh Apr 22, 2024
3e001e7
fix(ci): builder server before running Playwright tests
lemilonkh Apr 22, 2024
12ffccd
feat(ci): replace example test with signup test
lemilonkh Apr 22, 2024
86e43ca
fix(ci): move Playwright tests into normal test workflow
lemilonkh Apr 22, 2024
ed5627f
fix(ci): run unit tests first and install Playwright browsers before …
lemilonkh Apr 22, 2024
fc71166
feat(ci): add npm script e2e:test and update test script command
lemilonkh Apr 23, 2024
ca354a8
feat(docs): add commands for e2e and unit tests to README.md
lemilonkh Apr 23, 2024
25c8ad8
feat(script): add start-db.sh which starts a Docker Postgres instance…
lemilonkh Apr 23, 2024
ca1b5e1
feat(test): write e2e test for signup
lemilonkh Apr 23, 2024
8f9a040
fix(ci): add Playwright steps to develop and tag workflows for web
lemilonkh Apr 23, 2024
0af0234
fix(ci): use different email for signup e2e test to prevent collision…
lemilonkh Apr 23, 2024
0282a35
fix(ci): append random UUID to email to make it unique for testing in…
lemilonkh Apr 23, 2024
a623d74
fix(e2e): expect check email page at the end of signup test
lemilonkh Apr 23, 2024
e552fdc
fix(e2e): remove unnecessary click and press tab calls in signup test
lemilonkh Apr 23, 2024
f93250d
fix(e2e): encode email als URI component in URL check
lemilonkh Apr 23, 2024
92558f2
fix(e2e): only replace the @, not the + in URL
lemilonkh Apr 23, 2024
72438d4
feat(e2e): add more tests for signup page
lemilonkh Apr 24, 2024
bbcafd1
fix(e2e): remove old signup test built with Cypress
lemilonkh Apr 24, 2024
192907b
feat(e2e): add npm script e2e:test:head to see browser windows
lemilonkh Apr 24, 2024
49b415a
fix(e2e): errors in signup tests
lemilonkh Apr 24, 2024
c236ac1
fix(e2e): add comment explaining use of + selector
lemilonkh Apr 24, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions .github/workflows/web-develop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,17 @@ jobs:
- name: Run tests and generate coverage file
run: npm run ci:test

- name: Install Playwright Browsers
run: npx playwright install --with-deps
- name: Run Playwright tests
run: npx playwright test
- uses: actions/upload-artifact@v4
if: always()
with:
name: playwright-report
path: playwright-report/
retention-days: 30

- name: Upload coverage reports to Codecov
continue-on-error: true
uses: codecov/codecov-action@v4.0.1
Expand Down
11 changes: 11 additions & 0 deletions .github/workflows/web-tag.yml
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,17 @@ jobs:
- name: Run API tests
run: npm run api:test

- name: Install Playwright Browsers
run: npx playwright install --with-deps
- name: Run Playwright tests
run: npx playwright test
- uses: actions/upload-artifact@v4
if: always()
with:
name: playwright-report
path: playwright-report/
retention-days: 30

- name: Shut down database
run: docker stop github_action_postgresql

Expand Down
25 changes: 10 additions & 15 deletions .github/workflows/web-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -45,24 +45,19 @@ jobs:
- name: Run NextJS build
run: npm run build

# - name: Run Cypress tests
# run: npm run cy:test

# ... Generate LCOV files or download it from a different job
- name: Run tests and generate coverage file
run: npm run ci:test

# - name: Setup LCOV
# uses: hrishikesh-kadam/setup-lcov@v1
# - name: Report code coverage
# uses: zgosalvez/github-actions-report-lcov@v3
# with:
# coverage-files: ./app/lcov*.info
# minimum-coverage: 40
# artifact-name: code-coverage-report
# github-token: ${{ secrets.GITHUB_TOKEN }}
# working-directory: ./app
# update-comment: true
- name: Install Playwright Browsers
run: npx playwright install --with-deps
- name: Run Playwright tests
run: npx playwright test
- uses: actions/upload-artifact@v4
if: always()
with:
name: playwright-report
path: playwright-report/
retention-days: 30

- name: Upload coverage reports to Codecov
continue-on-error: true
Expand Down
5 changes: 4 additions & 1 deletion app/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -35,4 +35,7 @@ yarn-error.log*
# typescript
*.tsbuildinfo
next-env.d.ts

/test-results/
/playwright-report/
/blob-report/
/playwright/.cache/
12 changes: 12 additions & 0 deletions app/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -95,3 +95,15 @@ Then, you can run the app in a container:
```bash
docker run -p 3000:3000 ghcr.io/open-earth-foundation/citycatalyst
```

### End to end testing

We use Playwright to run automated E2E tests.

Setup: `npx playwright install --with-deps`

Run: `npm run e2e:test`

### API unit tests

Run: `npm run api:test`
58 changes: 0 additions & 58 deletions app/cypress/e2e/signup.cy.ts

This file was deleted.

90 changes: 90 additions & 0 deletions app/e2e/signup.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
import { test, expect, type Page } from "@playwright/test";
import { randomUUID } from "node:crypto";

async function expectText(page: Page, text: string) {
await expect(page.getByText(text).first()).toBeVisible();
}

test.beforeEach(async ({ page }) => {
await page.goto("/en/auth/signup");
});

test.describe("Signup", () => {
test("should navigate to signup from login", async ({ page }) => {
await page.goto("/");
const link = page.getByText("Sign up");
await expect(link).toBeVisible();
await link.click();
await expect(
page.getByRole("heading", { name: "Sign Up to City Catalyst" }),
).toBeVisible();
});

test("should redirect to dashboard after entering correct data", async ({
page,
}) => {
await expect(
page.getByRole("heading", { name: "Sign Up to City Catalyst" }),
).toBeVisible();

const email = `e2e-test+${randomUUID()}@example.com`;

await page.getByPlaceholder("Your full name").fill("Test User");
await page.getByPlaceholder("e.g. youremail@domain.com").fill(email);
await page.getByLabel("Password", { exact: true }).fill("Test123");
await page.getByLabel("Confirm Password").fill("Test123");
await page.getByPlaceholder("Enter the code you received").fill("123456");
await page
.locator('input[name="acceptTerms"] + .chakra-checkbox__control')
.click();
await page.getByRole("button", { name: "Create Account" }).click();

await expect(page).toHaveURL(
`/en/auth/check-email?email=${email.replace("@", "%40")}`,
);
});

test("should show errors when entering invalid data", async ({ page }) => {
await expect(
page.getByRole("heading", { name: "Sign Up to City Catalyst" }),
).toBeVisible();

await page.getByPlaceholder("Your full name").fill("asd");
await page
.getByPlaceholder("e.g. youremail@domain.com")
.fill("testopenearthorg");
await page.getByLabel("Password", { exact: true }).fill("Pas");
await page.getByLabel("Confirm Password").fill("Pa1");
await page.getByPlaceholder("Enter the code you received").fill("12345");
await page.getByRole("button", { name: "Create Account" }).click();

await expect(page).toHaveURL(`/en/auth/signup`);
await expectText(page, "valid email address");
await expectText(page, "Minimum length");
await expectText(page, "Invalid invite code");
await expectText(page, "Please accept the terms");
});

test("should require matching passwords", async ({ page }) => {
await expect(
page.getByRole("heading", { name: "Sign Up to City Catalyst" }),
).toBeVisible();

await page.getByPlaceholder("Your full name").fill("Test Account");
await page
.getByPlaceholder("e.g. youremail@domain.com")
.fill("e2e-test-fail@example.com");
await page.getByLabel("Password", { exact: true }).fill("Password1");
await page.getByLabel("Confirm Password").fill("Password2");
await page.getByPlaceholder("Enter the code you received").fill("123456");
await page
.locator('input[name="acceptTerms"] + .chakra-checkbox__control') // sibling
.click();
await page.getByRole("button", { name: "Create Account" }).click();

await expect(page).toHaveURL(`/en/auth/signup`);
await expectText(page, "Passwords don't match");
});

test.skip("should correctly handle and pass callbackUrl", () => {});
});
60 changes: 60 additions & 0 deletions app/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 4 additions & 4 deletions app/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,10 @@
"build": "next build",
"start": "next start",
"lint": "next lint",
"test": "npm run api:test & npm run cy:test",
"test": "npm run api:test & npm run e2e:test",
"api:test": "glob -c \"tsx --no-warnings --test\" \"./tests/**/*.test.ts\"",
"e2e:test": "npx playwright test",
"e2e:test:head": "npx playwright test -- --headed",
"test-single": "tsx --no-warnings --test",
"storybook": "storybook dev -p 6006",
"build-storybook": "storybook build",
Expand All @@ -22,9 +24,6 @@
"db:gen-seed": "sequelize-cli seed:generate --name",
"sync-catalogue": "tsx scripts/catalogue-sync.ts",
"ci:test": "tsx --test --experimental-test-coverage --test-reporter=lcov --test-reporter-destination=lcov.info tests/**/*.test.ts",
"cy:open": "cypress open",
"cy:run": "cypress run",
"cy:test": "start-server-and-test start http://localhost:3000/en/auth/login cy:run",
"prettier": "npx prettier . --write",
"email": "email dev --dir src/lib/emails",
"create-admin": "tsx scripts/create-admin.ts"
Expand Down Expand Up @@ -99,6 +98,7 @@
"zod": "^3.22.4"
},
"devDependencies": {
"@playwright/test": "^1.43.1",
"@storybook/addon-essentials": "^7.6.16",
"@storybook/addon-interactions": "^7.4.5",
"@storybook/addon-links": "^7.6.17",
Expand Down
Loading
Loading