fix tests
Some checks failed
build / test (macOS-latest) (push) Has been cancelled
build / test (ubuntu-latest) (push) Has been cancelled
build / test (windows-latest) (push) Has been cancelled
lint / go-lint (push) Has been cancelled
lint / eslint (push) Has been cancelled
build / build-release (push) Has been cancelled
build / notify (push) Has been cancelled
lint / notify (push) Has been cancelled

This commit is contained in:
Ildar Kamalov 2025-01-29 18:28:34 +03:00
parent 885e24496c
commit 77d05e550e
5 changed files with 31 additions and 13 deletions

2
client/package.json vendored
View File

@ -12,7 +12,7 @@
"lint:fix": "eslint './src/**/*.(ts|tsx)' --fix",
"test": "jest",
"test:watch": "jest --watch",
"test:e2e": "npx playwright test tests/e2e --headed",
"test:e2e": "npx playwright test tests/e2e",
"test:e2e:interactive": "npx playwright test --ui",
"test:e2e:debug": "npx playwright test --debug",
"test:e2e:codegen": "npx playwright codegen",

View File

@ -1,10 +1,13 @@
import { defineConfig, devices } from '@playwright/test';
import path from 'path';
/**
* See https://playwright.dev/docs/test-configuration.
*/
export default defineConfig({
testDir: './tests/e2e',
globalSetup: path.resolve('./tests/e2e/globalSetup.ts'),
/* Run tests in files in parallel */
fullyParallel: true,
/* Fail the build on CI if you accidentally left test.only in the source code. */
@ -22,6 +25,9 @@ export default defineConfig({
/* Collect trace when retrying the failed test. See https://playwright.dev/docs/trace-viewer */
trace: 'on-first-retry',
launchOptions: {
headless: true,
},
},
/* Configure projects for major browsers */
@ -63,7 +69,7 @@ export default defineConfig({
],
webServer: {
command: 'sudo ./AdGuardHome --local-frontend -v',
command: 'rm -f AdGuardHome.yaml && sudo ./AdGuardHome --local-frontend -v',
url: 'http://127.0.0.1:3000',
cwd: '..',
reuseExistingServer: !process.env.CI,

View File

@ -14,8 +14,9 @@ test.describe('DHCP Configuration', () => {
await page.getByTestId('username').fill(ADMIN_USERNAME);
await page.getByTestId('password').click();
await page.getByTestId('password').fill(ADMIN_PASSWORD);
await page.keyboard.press('Tab');
await page.getByTestId('sign_in').click();
await page.getByText('Settings', { exact: true }).click();
await page.waitForURL((url) => !url.href.endsWith('/login.html'));
await page.goto(`/#dhcp`);
});
@ -45,8 +46,7 @@ test.describe('DHCP Configuration', () => {
await page.getByTestId('v4_range_start').fill(RANGE_END);
await page.getByTestId('v4_range_end').click();
await page.getByTestId('v4_range_end').fill(RANGE_START);
await page.locator('.col-12').first().click();
await page.getByText('Must be greater than range').click();
await page.keyboard.press('Tab');
expect(await page.getByText('Must be greater than range').isVisible()).toBe(true);
});
@ -55,7 +55,7 @@ test.describe('DHCP Configuration', () => {
await page.getByTestId('interface_name').selectOption(INTERFACE_NAME);
await page.getByTestId('v4_gateway_ip').click();
await page.getByTestId('v4_gateway_ip').fill('192.168.1.200s');
await page.getByText('Invalid IPv4 address').click();
await page.keyboard.press('Tab');
expect(await page.getByText('Invalid IPv4 address').isVisible()).toBe(true);
});

View File

@ -1,18 +1,27 @@
import { test } from '@playwright/test';
import { chromium, FullConfig } from '@playwright/test';
const ADMIN_USERNAME = 'admin';
const ADMIN_PASSWORD = 'superpassword';
const PORT = 3000;
import { ADMIN_USERNAME, ADMIN_PASSWORD, PORT } from '../constants';
async function globalSetup(config: FullConfig) {
const browser = await chromium.launch({
slowMo: 100,
});
const page = await browser.newPage({ baseURL: config.webServer?.url });
test('install', async ({ page }) => {
await page.goto('/');
await page.getByTestId('install_get_started').click();
await page.getByTestId('install_web_port').fill(PORT.toString());
await page.getByTestId('install_next').click();
await page.getByTestId('install_username').fill(ADMIN_USERNAME);
await page.getByTestId('install_password').fill(ADMIN_PASSWORD);
await page.getByTestId('install_confirm_password').click();
await page.getByTestId('install_confirm_password').fill(ADMIN_PASSWORD);
await page.getByTestId('install_next').click();
await page.getByTestId('install_next').click();
await page.getByTestId('install_open_dashboard').click();
});
await page.waitForURL((url) => !url.href.endsWith('/install.html'));
await browser.close();
}
export default globalSetup;

View File

@ -1,13 +1,16 @@
import { test } from '@playwright/test';
import { ADMIN_PASSWORD, ADMIN_USERNAME } from '../constants';
test.describe('Login', () => {
test('should successfully log in with valid credentials', async ({ page }) => {
await page.goto(`/login.html`);
await page.goto('/login.html');
await page.getByTestId('username').click();
await page.getByTestId('username').fill(ADMIN_USERNAME);
await page.getByTestId('password').click();
await page.getByTestId('password').fill(ADMIN_PASSWORD);
await page.keyboard.press('Tab');
await page.getByTestId('sign_in').click();
await page.waitForURL((url) => !url.href.endsWith('/login.html'));
});
});