difuse-playwright/tests/network/lan.spec.js

118 lines
4.2 KiB
JavaScript

import { test, expect } from '@playwright/test';
import { getDefaultNetmask, isValidMacAddress, isValidPrivateIPV4 } from '../../utils/utils.js';
test.describe('Network & Services - Network - LAN', () => {
test.beforeEach(async ({ page }) => {
await page.goto('/network/lan', { waitUntil: 'networkidle' });
});
test('Title', async ({ page }) => {
expect(await page.title()).toBe('Difuse - Network - LAN');
});
test('Card Header Title', async ({ page }) => {
const title = await page.locator('.card-header-title');
expect(await title).toBeTruthy();
});
test('Tabs', async ({ page }) => {
const ipv4Tab = await page.$('a[role="tab"][id="4-tab"]');
const ipv4visible = await ipv4Tab.isVisible();
expect(ipv4visible).toBeTruthy();
await page.click('a[role="tab"][id="4-tab"]');
await page.waitForSelector('#content-4');
const ipv4Content = await page.locator('#content-4');
const ipv4ContentVisible = await ipv4Content.isVisible();
expect(ipv4ContentVisible).toBeTruthy();
const ipv6Tab = await page.$('a[role="tab"][id="6-tab"]');
const ipv6visible = await ipv6Tab.isVisible();
expect(ipv6visible).toBeTruthy();
await page.click('a[role="tab"][id="6-tab"]');
await page.waitForSelector('#content-6');
const ipv6Content = await page.locator('#content-6');
const ipv6ContentVisible = await ipv6Content.isVisible();
expect(ipv6ContentVisible).toBeTruthy();
const bridgeSlaves = await page.$('a[role="tab"][id="bs-tab"]');
const bridgeSlavesVisible = await bridgeSlaves.isVisible();
expect(bridgeSlavesVisible).toBeTruthy();
await page.click('a[role="tab"][id="bs-tab"]');
await page.waitForSelector('#content-bs');
const bsContent = await page.locator('#content-bs');
const bsContentVisible = await bsContent.isVisible();
expect(bsContentVisible).toBeTruthy();
});
test('Info Tables', async ({ page }) => {
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(isValidPrivateIPV4(value)).toBeTruthy();
}
}
}
});
test('Validate Ip Address', async ({ page }) => {
await page.waitForSelector('#ipAddress');
const ipAddress = await page.locator('#ipAddress');
const ipValue = await ipAddress.inputValue();
const validateIP = await isValidPrivateIPV4(ipValue);
expect(validateIP).toBe(true);
});
test('Validate Network Mask Address', async ({ page }) => {
await page.waitForSelector('#ipAddress');
const ipAddress = await page.locator('#ipAddress');
const ipValue = await ipAddress.inputValue();
const networkMask = await page.locator('.lan-netmask-select');
const networkValue = await networkMask.inputValue();
const defaultValue = getDefaultNetmask(ipValue);
expect(defaultValue).toBe(networkValue);
});
test('Enable 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 page.evaluate((checkbox) => checkbox.click(), dhcpCb);
expect(await page.isVisible('label:has-text("DHCP Start")')).toBeTruthy();
}
});
test('Disable DHCP Toggle', async ({ page }) => {
const dhcpCb = await page.$('.dhcp-cb');
const isChecked = await dhcpCb.isChecked();
if (isChecked) {
await page.evaluate((checkbox) => checkbox.click(), dhcpCb);
expect(await page.isVisible('label:has-text("DHCP Start")')).toBe(false);
} else {
expect(await page.isVisible('label:has-text("DHCP Start")')).toBe(false);
}
});
});