difuse-playwright/tests/network/guest-lan.spec.js
2024-02-07 05:59:45 +05:30

47 lines
No EOL
1.6 KiB
JavaScript

import { test, expect } from '@playwright/test';
import { isValidMacAddress, isValidCidr } from '../../utils/utils.js';
test.beforeEach(async ({ page }) => {
await page.goto('/network/guest-lan', { waitUntil: 'networkidle' });
});
test('Title', async ({ page }) => {
const title = await page.title();
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);
const rows = await page.$$('table > tbody > tr');
for (const row of rows) {
const cells = await row.$$('td');
if (cells.length === 2) {
const label = await cells[0].textContent();
const value = await cells[1].textContent();
if (label === 'Protocol') {
expect(value).toBe('Static Address');
} else if (label === 'Uptime') {
expect(typeof parseInt(value)).toBe('number');
} else if (label === 'MAC') {
expect(isValidMacAddress(value)).toBeTruthy();
} else if (label === 'RX' || label === 'TX') {
expect(typeof parseInt(value)).toBe('number');
} else if (label === 'IPv4') {
expect(isValidCidr(value)).toBeTruthy();
}
}
}
});
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');
});