: more stds
This commit is contained in:
hayzam 2024-02-09 00:36:05 +05:30
parent c5eb074234
commit e87dc83fbc
Signed by: hayzam
GPG key ID: 13B4C5B544B53947
6 changed files with 188 additions and 118 deletions

View file

@ -6,6 +6,7 @@
"type": "module",
"scripts": {
"lint": "semistandard --fix tests/**/*.js",
"codegen": "npx playwright codegen",
"test": "playwright test",
"prepare": "npm run lint"
},

View file

@ -1,7 +1,3 @@
// import { defineConfig, devices } from '@playwright/test';
//
// await import('dotenv/config');
const { defineConfig, devices } = require('@playwright/test');
require('dotenv').config();

View file

@ -1,5 +1,6 @@
import { test, expect } from '@playwright/test';
test.describe('General - Dashboard - Router', () => {
test.beforeEach(async ({ page }) => {
await page.goto('/', { waitUntil: 'networkidle' });
});
@ -43,3 +44,4 @@ test('Basic System Information', async ({ page }) => {
test('Network Information', async ({ page }) => {
expect(await page.$('th:has-text("Network Information")')).toBeTruthy();
});
});

View file

@ -1,5 +1,6 @@
import { test, expect } from '@playwright/test';
test.describe('General - Dashboard - Telephony', () => {
test.beforeEach(async ({ page }) => {
await page.goto('/telephony', { waitUntil: 'networkidle' });
});
@ -35,3 +36,4 @@ test('PBX Information', async ({ page }) => {
const coreStartupTimeText = await page.textContent('#core-startup-time');
expect(yearRegex.test(coreStartupTimeText)).toBeTruthy();
});
});

View file

@ -1,8 +1,14 @@
import { test, expect } from '@playwright/test';
import { isValidMacAddress, isValidCidr } from '../../utils/utils.js';
import { expect, test } from '@playwright/test';
import { isValidCidr, isValidMacAddress, clickSelect2Dropdown, hasToastText, sleep } from '../../utils/utils.js';
test.describe('Network & Services - Network - Guest LAN', () => {
test.beforeEach(async ({ page }) => {
await page.goto('/network/guest-lan', { waitUntil: 'networkidle' });
await page.waitForFunction(async () => {
await sleep(1000);
const element = document.querySelector('.lan-netmask-select');
return element && element.classList.contains('select2-hidden-accessible');
});
});
test('Title', async ({ page }) => {
@ -11,9 +17,6 @@ test('Title', async ({ page }) => {
});
test('Info Table', async ({ page }) => {
await page.waitForSelector('td:has-text("Static Address")', { timeout: 5000 });
await page.waitForTimeout(2500);
const rows = await page.$$('table > tbody > tr');
for (const row of rows) {
@ -37,11 +40,51 @@ test('Info Table', async ({ page }) => {
}
});
test('Bad IPv4 Form Submits', async ({ page }) => {
await page.waitForSelector('#ipAddress', {timeout: 5000})
await page.fill('#ipAddress', '111.111.111.111.111');
await page.click('button[type="submit"]');
const errorPopup = await page.waitForSelector('.swal2-popup', { state: 'visible' });
const errorText = await errorPopup.textContent();
expect(errorText).toContain('Invalid IP Address');
test('DHCP Toggle', async ({ page }) => {
const dhcpCb = await page.$('.dhcp-cb');
const isChecked = await dhcpCb.isChecked();
if(isChecked) {
expect(await page.isVisible('label:has-text("DHCP Start")')).toBeTruthy();
} else {
await dhcpCb.check();
expect(await page.isVisible('label:has-text("DHCP Start1")')).toBeTruthy();
}
});
test.describe('Bad IPv4 Form Submits', () => {
test('Bad IPv4', async ({ page }) => {
const ip = await page.getByPlaceholder('192.168.1.1');
await ip.fill('1.1.1.1.1.1.1.1.1.1.1');
await page.click('button.button.green:has-text("Save")');
expect(await hasToastText(page, 'Invalid IP Address')).toBeTruthy();
});
test('Bad Netmask', async ({ page }) => {
await clickSelect2Dropdown(page, '.lan-netmask-select');
await page.getByRole('searchbox', {name: 'Search'}).fill('15151515515151515');
await page.keyboard.press('Enter');
await page.click('button.button.green:has-text("Save")');
expect(await hasToastText(page, 'Invalid Netmask')).toBeTruthy();
});
test('Bad DHCP Start', async ({ page }) => {
await page.locator('#dhcpStart').fill('55555555555555');
await page.click('button.button.green:has-text("Save")');
expect(await hasToastText(page, 'Invalid DHCP Range')).toBeTruthy();
});
test('Bad DHCP Max Leases', async ({ page }) => {
await page.locator('#dhcpMax').fill('55555555555555');
await page.click('button.button.green:has-text("Save")');
expect(await hasToastText(page, 'Invalid DHCP Range')).toBeTruthy();
});
/* Hayzam - Fix This */
// test('Bad DHCP Leasetime', async ({ page }) => {
// await page.locator('#leaseTime').fill('55555555555555');
// await page.click('button.button.green:has-text("Save")');
// expect(await hasToastText(page, 'Invalid Lease Time')).toBeTruthy();
// });
});
});

View file

@ -43,3 +43,29 @@ export function isValidCidr (cidr, type = 0) {
return false;
}
}
export async function clickSelect2Dropdown(page, selectSelector) {
const select2ContainerSelector = `${selectSelector} + .select2-container`;
const select2ContainerExists = await page.$(select2ContainerSelector) !== null;
if (!select2ContainerExists) {
throw new Error('Select2 container not found');
}
const select2Selection = `${select2ContainerSelector} .select2-selection`;
await page.click(select2Selection);
await page.waitForSelector('.select2-dropdown .select2-results__option');
}
export async function hasToastText(page, text) {
try {
return (await (await page.waitForSelector('.swal2-popup', {state: 'visible'})).textContent()).includes(text);
} catch (error) {
console.log(error);
return false;
}
}
export async function sleep(ms) {
return new Promise(resolve => setTimeout(resolve, ms));
}