Skip to content

Commit 87a268e

Browse files
authored
Merge pull request #7 from Lugonue/playwright-tests
Playwright tests
2 parents 3710d63 + 199e714 commit 87a268e

9 files changed

Lines changed: 5754 additions & 18805 deletions

File tree

.github/workflows/nodeci.yml

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ jobs:
1414

1515
strategy:
1616
matrix:
17-
node-version: [16.x, 17.x, 18.x]
17+
node-version: [18.x]
1818

1919
steps:
2020
- uses: actions/checkout@v2
@@ -26,5 +26,7 @@ jobs:
2626
run: make install
2727
- name: Run linter
2828
run: make lint-frontend
29-
# - name: Run tests
30-
# run: make test
29+
- name: Build
30+
run: make build
31+
- name: Run tests
32+
run: make test

.npmrc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
legacy-peer-deps=true

Makefile

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,5 +13,11 @@ deploy:
1313
lint-frontend:
1414
make -C frontend lint
1515

16+
build:
17+
DISABLE_ESLINT_PLUGIN=true npm run build
18+
19+
test:
20+
npx playwright test
21+
1622
install:
17-
make -C frontend install
23+
npm ci

__tests__/example.spec.js

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
// @ts-check
2+
//
3+
const { test, expect } = require('@playwright/test');
4+
5+
test('wrong login', async ({ page }) => {
6+
await page.goto('http://localhost:5001/');
7+
8+
expect(page.getByText(/Нет аккаунта?/)).toBeVisible();
9+
expect(page.getByAltText(/Войти/)).toBeVisible();
10+
expect(page.getByText(/Регистрация/)).toBeVisible();
11+
expect(await page.getByText(/Войти/).count()).toEqual(2);
12+
13+
await page.locator('#username').fill('test');
14+
await page.locator('#password').fill('test');
15+
await page.getByRole('button', { name: 'Войти' }).click();
16+
expect(await page.getByText(/Скрытая страница!/).count()).toEqual(0);
17+
expect(page.getByText(/Неверные имя пользователя или пароль/)).toBeVisible();
18+
});
19+
20+
test('registration page, success login', async ({ page }) => {
21+
await page.goto('http://localhost:5001/');
22+
23+
await page.getByText(/Регистрация/).click();
24+
expect(page.getByLabel(/Имя пользователя/)).toBeVisible();
25+
expect(page.getByLabel(/Пароль/)).toBeVisible();
26+
expect(page.getByLabel(/Подтвердите пароль/)).toBeVisible();
27+
expect(page.getByText(/Регистрация/)).toBeVisible();
28+
expect(page.getByAltText(/Регистрация/)).toBeVisible();
29+
30+
await page.locator('#username').fill('playwright');
31+
await page.locator('#password').fill('password');
32+
await page.locator('#confirmPassword').fill('password');
33+
await page.getByRole('button', { name: 'Зарегистрироваться' }).click();
34+
expect(page.getByText(/Скрытая страница!/)).toBeVisible();
35+
36+
await page.getByRole('button', { name: 'Выйти' }).click();
37+
38+
await page.locator('#username').fill('admin');
39+
await page.locator('#password').fill('admin');
40+
await page.getByRole('button', { name: 'Войти' }).click();
41+
expect(page.getByText(/Скрытая страница!/)).toBeVisible();
42+
});

frontend/Makefile

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,3 +10,5 @@ build:
1010
lint:
1111
npx eslint .
1212

13+
test:
14+
make -C playwright test

0 commit comments

Comments
 (0)