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

VF-131 bytt ut cypress med playwright #346

Merged
merged 23 commits into from
Oct 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
329d446
Install playwright and create e2e test
juliadai8 Apr 16, 2024
3955d9c
chore: :fire: remove cypress config
phibkro Apr 16, 2024
a6b6f2d
Update example test
juliadai8 Apr 23, 2024
432af24
Merge branch 'main' into vf-131-bytt-ut-cypress-med-playwright
phibkro Oct 18, 2024
a909262
ci: :hammer: update testing scripts
phibkro Oct 18, 2024
a525c17
docs: :memo: update testing with playwright
phibkro Oct 18, 2024
f2b47f5
chore: :wrench: remove unused type
phibkro Oct 18, 2024
c218035
ci: :construction_worker: use pnpm
phibkro Oct 18, 2024
237d035
chore: :wrench: co-locate e2e test results
phibkro Oct 18, 2024
b911ce4
chore: :hammer: rename e2e related scripts under e2e:
phibkro Oct 18, 2024
801a2b2
style: :art: use double quotes
phibkro Oct 18, 2024
f663935
test: :coffin: remove example test
phibkro Oct 18, 2024
b9f4b28
ci: :hammer: use exec over npx
phibkro Oct 18, 2024
01a28d2
ci: :truck: move e2e testing to own workflow
phibkro Oct 18, 2024
dd9628c
ci: :truck: move all tests into one workflow
phibkro Oct 18, 2024
0289945
ci: :construction_worker: use node version variable
phibkro Oct 18, 2024
1d1ecc8
ci: :green_heart: fix workflow variables
phibkro Oct 18, 2024
6c409e7
ci: :green_heart: remove build dependency, use pnpm exec
phibkro Oct 18, 2024
2750c93
ci: :truck: rename workflow to quality-control
phibkro Oct 18, 2024
ec3765a
chore: :wrench: configure vitest to run tests in ./src
phibkro Oct 18, 2024
1576f93
test: :coffin: remove example test
phibkro Oct 18, 2024
ad90794
style: :art: remove empty line
phibkro Oct 18, 2024
da5467f
Merge branch 'main' into vf-131-bytt-ut-cypress-med-playwright
phibkro Oct 25, 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
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# This workflow will do a clean install of node dependencies, build the source code and run tests across different versions of node
# For more information see: https://help.github.com/actions/language-and-framework-guides/using-nodejs-with-github-actions

name: Code Quality Check
name: Quality Control

env:
NODE_VERSION: 20.12.2
Expand All @@ -22,14 +22,13 @@ jobs:
uses: pnpm/action-setup@v3
with:
version: 8
- name: Setup Node
- name: Setup Node
uses: actions/setup-node@v4
with:
node-version: ${{env.NODE_VERSION}}
node-version: ${{ env.NODE_VERSION }}
cache: "pnpm"
- name: Install dependencies
run:
pnpm install
run: pnpm install
- name: Build
run: pnpm build
- name: store build artifact
Expand All @@ -51,41 +50,42 @@ jobs:
run: biome ci .

vitest_tests:
needs: build
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v4
- uses: pnpm/action-setup@v3
with:
version: 8
- uses: actions/setup-node@v4
with:
node-version: ${{ env.NODE_VERSION }}
cache: "pnpm"
- name: Run tests
run: |
pnpm install
pnpm test:vitest

cypress_tests:
needs: build
e2e-tests:
timeout-minutes: 60
runs-on: ubuntu-latest

strategy:
matrix:
browser: [chrome, firefox, edge]

container:
image: cypress/browsers:node16.14.2-slim-chrome100-ff99-edge
options: --user 1001
steps:
- uses: actions/checkout@v4
- uses: pnpm/action-setup@v3
with:
version: 8
- name: Download the build folders
uses: actions/download-artifact@v4
- uses: actions/setup-node@v4
with:
name: build
path: build
- uses: cypress-io/github-action@v4
node-version: ${{ env.NODE_VERSION }}
cache: "pnpm"
- name: Install dependencies
run: pnpm install
- name: Install Playwright Browsers
run: pnpm exec playwright install --with-deps
- name: Run Playwright tests
run: pnpm exec playwright test
- uses: actions/upload-artifact@v4
if: ${{ !cancelled() }}
with:
browser: ${{ matrix.browser }}
build: pnpm build
name: playwright-report
path: playwright-report/
retention-days: 30
6 changes: 4 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@

# testing
/coverage
e2e/results/
/playwright-report/
/playwright/.cache/
/blob-report/

# production
/build
Expand All @@ -29,5 +33,3 @@ yarn-debug.log*
yarn-error.log*

.eslintcache

/cypress/videos
18 changes: 13 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,6 @@ Open [http://localhost:3000](http://localhost:3000) to view it in the browser.
The page will reload if you make edits.\
You will also see any lint errors in the console.

### `pnpm test`

Runs the cypress tests defined in [cypress](./cypress).
To specify the tests to run in firefox specifically run `pnpm test:firefox`

### `pnpm build`

Builds the app for production to the `build` folder.\
Expand Down Expand Up @@ -47,6 +42,19 @@ The linter settings are stored in the [.eslintrc.js file](.eslintrc.js) which al

Running `pnpm lint --fix` will fix small auto-fixable problems.

## Testing

Testing is done with Vitest for simple testing,
and Playwright for e2e testing in browsers.

Install required browsers by running:

- `pnpm e2e:install`

Then run e2e test with:

- `pnpm e2e:test`

## Learn More

You can learn more in the [Create React App documentation](https://facebook.github.io/create-react-app/docs/getting-started).
Expand Down
10 changes: 0 additions & 10 deletions cypress.config.ts

This file was deleted.

5 changes: 0 additions & 5 deletions cypress/e2e/test.cy.ts

This file was deleted.

5 changes: 0 additions & 5 deletions cypress/fixtures/example.json

This file was deleted.

37 changes: 0 additions & 37 deletions cypress/support/commands.ts

This file was deleted.

20 changes: 0 additions & 20 deletions cypress/support/e2e.ts

This file was deleted.

140 changes: 140 additions & 0 deletions e2e/example.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,140 @@
import { test, expect } from '@playwright/test';



test('has title', async ({page}) => {
await page.goto('/');
await expect(page).toHaveTitle('Vektorprogrammet');
})

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

test('can navigate to assistent page', async ({page}) => {
await page.getByRole('link', { name: 'Assistenter' }).click();
await expect(page.getByRole('heading', { name: 'Assistenter' })).toBeVisible();
})

test('can navigate to parent page', async ({page}) => {
await page.getByRole('link', { name: 'Foreldre' }).click();
await expect(page.getByRole('heading', { name: 'Informasjon for foreldre' })).toBeVisible();
})

test('can navigate to teams page', async ({page}) => {
await page.getByRole('link', { name: 'Team' }).click();
await expect(page.getByRole('heading', { name: 'Styre og team' })).toBeVisible();
})

test('can navigate to school page', async ({page}) => {
await page.getByRole('link', { name: 'Skoler' }).click();
await expect(page.getByRole('heading', { name: 'Vektorassistenter i skolen' })).toBeVisible();
})
})

test.describe('Contact page', () => {
test.beforeEach( async ({ page }) => {
await page.goto('/kontakt');
})

test('has contact informations for Trondheim and contact', async ({ page }) => {
await page.locator('button').filter({ hasText: 'Trondheim' }).click();
await expect(
page.locator('div').filter({ hasText: /^styret\.ntnu@vektorprogrammet\.no$/ }).getByRole('link'))
.toBeVisible();
await expect(page.getByText('Høgskoleringen 5 7491')).toBeVisible();
})

test('can submit message in contact form', async ({ page }) => {
const name = page.getByLabel('Ditt navn');
const email = page.getByLabel('Din e-post');
const subject = page.getByLabel('Emne');
const message = page.getByLabel('Melding');
const submitButton = page.getByRole('button', { name: 'Send melding' });

await expect(name).toBeVisible();
await expect(email).toBeVisible();
await expect(subject).toBeVisible();
await expect(message).toBeVisible();
await expect(submitButton).toBeVisible();

await name.fill('John Doe');
await email.fill('[email protected]');
await subject.fill('teams');
await message.fill('How do I apply for teams?');

await expect(name).not.toBeEmpty();
await expect(email).not.toBeEmpty();
await expect(subject).not.toBeEmpty();
await expect(message).not.toBeEmpty();

submitButton.click();
await expect(name).toBeEmpty();
await expect(email).toBeEmpty();
await expect(subject).toBeEmpty();
await expect(message).toBeEmpty();
})

})

test.describe('Assistent page', () => {
test.beforeEach( async ({ page }) => {
await page.goto('/assistenter');
});

test('can use button to scroll down to application form', async ({page}) => {
const scrollButton = await page.getByRole('button', { name: 'Scroll ned for å søke!' });
scrollButton.click();
await expect(page.getByRole('button', { name: 'Søk nå!' })).toBeInViewport();
})

test('can change city', async ({page}) => {
const trondheimButton = await page.locator('button').filter({ hasText: 'Trondheim' })
const bergenButton = await page.getByRole('main').getByText('Bergen');
const aasButton = await page.getByRole('main').getByText('Ås');

await expect(trondheimButton).toBeVisible();
await expect(bergenButton).toBeVisible();
await expect(aasButton).toBeVisible();

await trondheimButton.click();
await expect(page.getByRole('heading', { name: 'Trondheim' })).toBeVisible();

await bergenButton.click();
await expect(page.getByRole('heading', { name: 'Bergen' })).toBeVisible();

await aasButton.click();
await expect(page.getByRole('heading', { name: 'Ås' })).toBeVisible();

})

test('can submit application', async ({page}) => {
await expect(page.getByRole('heading', { name: 'Trondheim' })).toBeVisible();
const submit = page.getByRole('button', { name: 'Søk nå!' });

const firstname = page.getByPlaceholder('Fornavn');
const surname = page.getByPlaceholder('Etternavn');
const email = page.getByPlaceholder('E-post');
const phone = page.getByPlaceholder('Telefon nr');
const studyprogram = page.getByPlaceholder('Linje');

await expect(firstname).toBeVisible();
await expect(surname).toBeVisible();
await expect(email).toBeVisible();
await expect(phone).toBeVisible();
await expect(studyprogram).toBeVisible();
await expect(submit).toBeVisible();

await firstname.fill('John');
await surname.fill('Doe');
await email.fill('[email protected]');
await phone.fill('00000000');
await studyprogram.fill('mtdt');

await submit.click();
await expect(page.getByRole('heading', { name: 'Assistenter' })).toBeInViewport()
})


})
10 changes: 6 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,12 @@
"scripts": {
"start": "vite",
"build": "tsc && vite build",
"test": "cypress run && vitest run",
"test:cypress:firefox": "cypress run --browser firefox",
"test:vitest": "vitest run",
"test:vitest:watch": "vitest watch",
"e2e:test": "exec playwright test",
"e2e:test:ui": "exec playwright test --ui",
"e2e:show-report": "exec playwright show-report",
"e2e:install": "exec playwright install",
"check": "biome check ./ --apply",
"lint": "biome lint ./ --apply",
"format": "biome format ./ --apply"
Expand Down Expand Up @@ -70,13 +72,13 @@
"web-vitals": "^4.2.3"
},
"devDependencies": {
"@playwright/test": "^1.43.0",
"@biomejs/biome": "1.9.4",
"@testing-library/dom": "^10.0.0",
"@testing-library/react": "^16.0.0",
"@testing-library/user-event": "^14.5.2",
"@types/jest": "^29.5.12",
"@vitejs/plugin-react": "^4.2.1",
"cypress": "12.8.1",
"vitest": "^2.0.0"
}
}
}
Loading
Loading