246 lines
9.1 KiB
JavaScript
246 lines
9.1 KiB
JavaScript
import { test, expect } from '@playwright/test';
|
|
import { hasToastInput, isValidCidr, isValidMacAddress, isValidPrivateIPV4, splitIPv6 } from '../../utils/utils.js';
|
|
|
|
test.describe('Network & Services - Network - WAN', () => {
|
|
test.describe('IPV4 Tab', () => {
|
|
test.beforeEach(async ({ page }) => {
|
|
await page.goto('/network/wan', { waitUntil: 'networkidle' });
|
|
await page.waitForTimeout(3000);
|
|
});
|
|
|
|
test('Title', async ({ page }) => {
|
|
expect(await page.title()).toBe('Difuse - Network - WAN');
|
|
});
|
|
|
|
test('Card Header Title', async ({ page }) => {
|
|
const title = await page.locator('.card-header-title');
|
|
expect(await title).toBeTruthy();
|
|
});
|
|
|
|
test('IPv4 Info Tables', async ({ page }) => {
|
|
const rows = await page.$$('table > tbody > tr');
|
|
|
|
for (let i = 0; i < rows.length && i < 6; i++) {
|
|
const row = rows[i];
|
|
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('DHCPv4');
|
|
} 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)).toBe(true);
|
|
}
|
|
}
|
|
}
|
|
});
|
|
|
|
test('Restart WAN Interface', async ({ page }) => {
|
|
const restartButton = await page.locator('#restartWAN');
|
|
const visible = await restartButton.isVisible();
|
|
expect(visible).toBeTruthy();
|
|
});
|
|
|
|
test('Stop WAN Interface', async ({ page }) => {
|
|
const stopWAN = await page.locator('#stopWAN');
|
|
const visible = await stopWAN.isVisible();
|
|
expect(visible).toBeTruthy();
|
|
});
|
|
|
|
test('Disable WAN Interface', async ({ page }) => {
|
|
const disableWAN = await page.locator('#disableWAN');
|
|
const visible = await disableWAN.isVisible();
|
|
expect(visible).toBeTruthy();
|
|
});
|
|
|
|
test('IPv4 Protocol Static IP', async ({ page }) => {
|
|
const label = await page.locator('label:has-text("Protocol")');
|
|
expect(label).toBeTruthy();
|
|
|
|
const selectElement = await page.locator('select.proto-select');
|
|
|
|
await selectElement.selectOption({ label: 'Static IP' });
|
|
await page.waitForTimeout(1000);
|
|
|
|
const isVisible = await page.isVisible('#staticip-sub-div');
|
|
expect(isVisible).toBe(true);
|
|
|
|
const ipv4Address = await page.locator('label:has-text("IPv4 Address")');
|
|
const ipv4AddressField = await page.locator('#static-ip');
|
|
expect(ipv4Address && ipv4AddressField).toBeTruthy();
|
|
|
|
const networkMask = await page.locator('label:has-text("Network Mask")');
|
|
const networkMaskField = await page.locator('select.static-netmask-select');
|
|
expect(networkMask && networkMaskField).toBeTruthy();
|
|
|
|
const ipv4Gateway = await page.locator('label:has-text("IPv4 Gateway")');
|
|
const ipv4GatewayField = await page.locator('#static-gateway');
|
|
expect(ipv4Gateway && ipv4GatewayField).toBeTruthy();
|
|
|
|
const ipv4Broadcast = await page.locator('label:has-text("IPv4 Broadcast")');
|
|
const ipv4BroadcastField = await page.locator('#static-broadcast');
|
|
expect(ipv4Broadcast && ipv4BroadcastField).toBeTruthy();
|
|
});
|
|
|
|
test('IPv4 Protocol PPPoE', async ({ page }) => {
|
|
const selectElement = await page.locator('select.proto-select');
|
|
|
|
await selectElement.selectOption({ label: 'PPPoE' });
|
|
await page.waitForTimeout(1000);
|
|
|
|
const isVisible = await page.isVisible('#pppoe-sub-div');
|
|
expect(isVisible).toBe(true);
|
|
|
|
const pppoeUsername = await page.locator('label:has-text("PAP/CHAP Username")');
|
|
const pppoeUsernameField = await page.locator('#pppoe-username');
|
|
expect(pppoeUsername && pppoeUsernameField).toBeTruthy();
|
|
|
|
const pppoePassword = await page.locator('label:has-text("PAP/CHAP Password")');
|
|
const pppoePasswordField = await page.locator('#pppoe-password');
|
|
expect(pppoePassword && pppoePasswordField).toBeTruthy();
|
|
});
|
|
});
|
|
|
|
test.describe('IPV6 Tab', () => {
|
|
test.beforeEach(async ({ page }) => {
|
|
await page.goto('/network/wan', { waitUntil: 'networkidle' });
|
|
const ipv6Tab = await page.locator('#v6-tab');
|
|
await ipv6Tab.click();
|
|
await page.waitForTimeout(2000);
|
|
});
|
|
|
|
test('Restart WAN Interface', async ({ page }) => {
|
|
const restartButton = await page.locator('#restartWAN6');
|
|
const visible = await restartButton.isVisible();
|
|
expect(visible).toBeTruthy();
|
|
});
|
|
|
|
test('Stop WAN Interface', async ({ page }) => {
|
|
const stopWAN = await page.locator('#stopWAN6');
|
|
const visible = await stopWAN.isVisible();
|
|
expect(visible).toBeTruthy();
|
|
});
|
|
|
|
test('Disable WAN Interface', async ({ page }) => {
|
|
const disableWAN = await page.locator('#disableWAN6');
|
|
const visible = await disableWAN.isVisible();
|
|
expect(visible).toBeTruthy();
|
|
});
|
|
|
|
test('IPv6 Source Routing', async ({ page }) => {
|
|
const label = await page.locator('label:has-text("IPv6 Source Routing")');
|
|
const switchField = await page.locator('.wan6-srcft');
|
|
expect(label && switchField).toBeTruthy();
|
|
});
|
|
|
|
test('Delegate Prefix', async ({ page }) => {
|
|
const label = await page.locator('label:has-text("Delegate Prefix")');
|
|
const switchField = await page.locator('.wan6-pdele');
|
|
expect(label && switchField).toBeTruthy();
|
|
});
|
|
|
|
test('IPv6 Info Tables', async ({ page }) => {
|
|
const rows = await page.$$('#content-v6 table > tbody > tr');
|
|
|
|
for (let i = 0; i < rows.length && i < 7; i++) {
|
|
const row = rows[i];
|
|
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('DHCPv6');
|
|
} 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 === 'IPv6') {
|
|
if (value) {
|
|
const htmlContent = await cells[1].innerHTML();
|
|
const ipv6Addresses = htmlContent.split('<br>');
|
|
for (const value of ipv6Addresses) {
|
|
const isValid = isValidCidr(value);
|
|
expect(isValid).toBe(true);
|
|
}
|
|
} else {
|
|
expect(false).toBe(false);
|
|
}
|
|
} else if (label === 'IPv6-PD') {
|
|
let splittedValue;
|
|
if (value) {
|
|
splittedValue = splitIPv6(value);
|
|
for (const value of splittedValue) {
|
|
const isValid = await isValidCidr(value);
|
|
expect(isValid).toBe(true);
|
|
}
|
|
} else {
|
|
expect(false).toBe(false);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
});
|
|
|
|
test('Save button', async ({ page }) => {
|
|
const button = page.locator('button.button.green:has-text("Save")');
|
|
expect(button).toBeTruthy();
|
|
});
|
|
});
|
|
|
|
test.describe('Priorities Tab', () => {
|
|
test.beforeEach(async ({ page }) => {
|
|
await page.goto('/network/wan', { waitUntil: 'networkidle' });
|
|
const priorityTab = await page.locator('#pri-tab');
|
|
await priorityTab.click();
|
|
await page.waitForTimeout(2000);
|
|
});
|
|
|
|
test('Priority Table', async ({ page }) => {
|
|
const table = await page.locator('#priority-table');
|
|
const tableVisible = await table.isVisible();
|
|
expect(tableVisible).toBeTruthy();
|
|
});
|
|
|
|
test('Edit Priority WAN', async ({ page }) => {
|
|
const button = await page.$('button[onclick="editPriority(\'wan\')"]');
|
|
button.click();
|
|
expect(await hasToastInput(page, 'Set Priority - WAN')).toBeTruthy();
|
|
});
|
|
|
|
test('Edit Priority WAN6', async ({ page }) => {
|
|
const button = await page.$('button[onclick="editPriority(\'wan6\')"]');
|
|
button.click();
|
|
expect(await hasToastInput(page, 'Set Priority - WAN6')).toBeTruthy();
|
|
});
|
|
|
|
test('Edit Priority 4G_6', async ({ page }) => {
|
|
const button = await page.$('button[onclick="editPriority(\'4G_6\')"]');
|
|
button.click();
|
|
expect(await hasToastInput(page, 'Set Priority - 4G_6')).toBeTruthy();
|
|
});
|
|
});
|
|
|
|
test.describe('Bridge Slaves', () => {
|
|
test.beforeEach(async ({ page }) => {
|
|
await page.goto('/network/wan', { waitUntil: 'networkidle' });
|
|
const bridgeSlavesTab = await page.locator('#bs-tab');
|
|
await bridgeSlavesTab.click();
|
|
await page.waitForTimeout(2000);
|
|
});
|
|
|
|
test('Icon', async ({ page }) => {
|
|
const ethernetCable = await page.locator('.mdi-ethernet-cable');
|
|
const WAN = await page.locator('.mdi-ethernet');
|
|
expect(ethernetCable && WAN).toBeTruthy();
|
|
});
|
|
});
|
|
});
|