: 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", "type": "module",
"scripts": { "scripts": {
"lint": "semistandard --fix tests/**/*.js", "lint": "semistandard --fix tests/**/*.js",
"codegen": "npx playwright codegen",
"test": "playwright test", "test": "playwright test",
"prepare": "npm run lint" "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'); const { defineConfig, devices } = require('@playwright/test');
require('dotenv').config(); require('dotenv').config();

View file

@ -1,23 +1,24 @@
import { test, expect } from '@playwright/test'; import { test, expect } from '@playwright/test';
test.beforeEach(async ({ page }) => { test.describe('General - Dashboard - Router', () => {
test.beforeEach(async ({ page }) => {
await page.goto('/', { waitUntil: 'networkidle' }); await page.goto('/', { waitUntil: 'networkidle' });
}); });
test('Title', async ({ page }) => { test('Title', async ({ page }) => {
const title = await page.title(); const title = await page.title();
expect(title).toBe('Difuse - Dashboard - Router'); expect(title).toBe('Difuse - Dashboard - Router');
}); });
test('Top Cards', async ({ page }) => { test('Top Cards', async ({ page }) => {
const lanClients = await page.getByRole('heading', { name: 'LAN Clients' }); const lanClients = await page.getByRole('heading', { name: 'LAN Clients' });
const wifiClients = await page.getByRole('heading', { name: 'GHz & 5 GHz Clients' }); const wifiClients = await page.getByRole('heading', { name: 'GHz & 5 GHz Clients' });
const wgEndpoints = await page.getByRole('heading', { name: 'Peers & Clients' }); const wgEndpoints = await page.getByRole('heading', { name: 'Peers & Clients' });
expect(lanClients && wifiClients && wgEndpoints).toBeTruthy(); expect(lanClients && wifiClients && wgEndpoints).toBeTruthy();
}); });
test('Basic System Information', async ({ page }) => { test('Basic System Information', async ({ page }) => {
const cells = (await page.$$('.tabulator-cell')).filter(async (cell) => { const cells = (await page.$$('.tabulator-cell')).filter(async (cell) => {
const field = await cell.getAttribute('tabulator-field'); const field = await cell.getAttribute('tabulator-field');
return field === 'value'; return field === 'value';
@ -38,8 +39,9 @@ test('Basic System Information', async ({ page }) => {
} }
expect(foundFw && foundUptime).toBe(true); expect(foundFw && foundUptime).toBe(true);
}); });
test('Network Information', async ({ page }) => { test('Network Information', async ({ page }) => {
expect(await page.$('th:has-text("Network Information")')).toBeTruthy(); expect(await page.$('th:has-text("Network Information")')).toBeTruthy();
});
}); });

View file

@ -1,28 +1,29 @@
import { test, expect } from '@playwright/test'; import { test, expect } from '@playwright/test';
test.beforeEach(async ({ page }) => { test.describe('General - Dashboard - Telephony', () => {
test.beforeEach(async ({ page }) => {
await page.goto('/telephony', { waitUntil: 'networkidle' }); await page.goto('/telephony', { waitUntil: 'networkidle' });
}); });
test('Title', async ({ page }) => { test('Title', async ({ page }) => {
const title = await page.title(); const title = await page.title();
expect(title).toBe('Difuse - Dashboard - Telephony'); expect(title).toBe('Difuse - Dashboard - Telephony');
}); });
test('Top Cards', async ({ page }) => { test('Top Cards', async ({ page }) => {
const sipExtensions = await page.getByRole('heading', { name: 'SIP Extensions' }); const sipExtensions = await page.getByRole('heading', { name: 'SIP Extensions' });
const sipTrunks = await page.getByRole('heading', { name: 'SIP Trunks' }); const sipTrunks = await page.getByRole('heading', { name: 'SIP Trunks' });
const currentChannels = await page.getByRole('heading', { name: 'Current Channels' }); const currentChannels = await page.getByRole('heading', { name: 'Current Channels' });
const completedCalls = await page.getByRole('heading', { name: 'Completed Calls' }); const completedCalls = await page.getByRole('heading', { name: 'Completed Calls' });
expect(sipExtensions && sipTrunks && currentChannels && completedCalls).toBeTruthy(); expect(sipExtensions && sipTrunks && currentChannels && completedCalls).toBeTruthy();
}); });
test('Endpoint Table', async ({ page }) => { test('Endpoint Table', async ({ page }) => {
expect(await page.getByText('Page Size')).toBeTruthy(); expect(await page.getByText('Page Size')).toBeTruthy();
}); });
test('PBX Information', async ({ page }) => { test('PBX Information', async ({ page }) => {
const yearRegex = /\b\d{4}\b/; const yearRegex = /\b\d{4}\b/;
const coreReloadText = await page.textContent('td:has-text("Core Last Reload") + td'); const coreReloadText = await page.textContent('td:has-text("Core Last Reload") + td');
@ -34,4 +35,5 @@ test('PBX Information', async ({ page }) => {
const coreStartupTimeText = await page.textContent('#core-startup-time'); const coreStartupTimeText = await page.textContent('#core-startup-time');
expect(yearRegex.test(coreStartupTimeText)).toBeTruthy(); expect(yearRegex.test(coreStartupTimeText)).toBeTruthy();
});
}); });

View file

@ -1,19 +1,22 @@
import { test, expect } from '@playwright/test'; import { expect, test } from '@playwright/test';
import { isValidMacAddress, isValidCidr } from '../../utils/utils.js'; import { isValidCidr, isValidMacAddress, clickSelect2Dropdown, hasToastText, sleep } from '../../utils/utils.js';
test.beforeEach(async ({ page }) => { test.describe('Network & Services - Network - Guest LAN', () => {
test.beforeEach(async ({ page }) => {
await page.goto('/network/guest-lan', { waitUntil: 'networkidle' }); 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 }) => { test('Title', async ({ page }) => {
const title = await page.title(); const title = await page.title();
expect(title).toBe('Difuse - Network - Guest LAN'); expect(title).toBe('Difuse - Network - Guest LAN');
}); });
test('Info Table', async ({ page }) => {
await page.waitForSelector('td:has-text("Static Address")', { timeout: 5000 });
await page.waitForTimeout(2500);
test('Info Table', async ({ page }) => {
const rows = await page.$$('table > tbody > tr'); const rows = await page.$$('table > tbody > tr');
for (const row of rows) { for (const row of rows) {
@ -35,13 +38,53 @@ test('Info Table', async ({ page }) => {
} }
} }
} }
}); });
test('Bad IPv4 Form Submits', async ({ page }) => { test('DHCP Toggle', async ({ page }) => {
await page.waitForSelector('#ipAddress', {timeout: 5000}) const dhcpCb = await page.$('.dhcp-cb');
await page.fill('#ipAddress', '111.111.111.111.111'); const isChecked = await dhcpCb.isChecked();
await page.click('button[type="submit"]');
const errorPopup = await page.waitForSelector('.swal2-popup', { state: 'visible' }); if(isChecked) {
const errorText = await errorPopup.textContent(); expect(await page.isVisible('label:has-text("DHCP Start")')).toBeTruthy();
expect(errorText).toContain('Invalid IP Address'); } 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; 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));
}