diff --git a/tests/network/lan.spec.js b/tests/network/lan.spec.js new file mode 100644 index 0000000..d275272 --- /dev/null +++ b/tests/network/lan.spec.js @@ -0,0 +1,74 @@ +import { test, expect } from '@playwright/test'; +import { 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(); + } + } + } + }); +}); diff --git a/tests/network/overview.spec.js b/tests/network/overview.spec.js index 446e71e..4494420 100644 --- a/tests/network/overview.spec.js +++ b/tests/network/overview.spec.js @@ -83,7 +83,6 @@ test.describe('Network & Services - Network - Overview', () => { await page.waitForSelector('#gwlan1Interface', { visible: true }); const gwlan1 = await page.isVisible('#gwlan1Interface'); expect(gwlan1).toBeTruthy(); - }); test('LAN - WiFi Label', async ({ page }) => { diff --git a/utils/utils.js b/utils/utils.js index 08146d9..6302f18 100644 --- a/utils/utils.js +++ b/utils/utils.js @@ -66,7 +66,6 @@ export async function hasToastText(page, text) { ).textContent() ).includes(text); } catch (error) { - console.log(error); return false; } } @@ -83,3 +82,43 @@ export function isValidDate(date) { return false; } } + +export function isValidPrivateIPV4(ip) { + try { + const privateRanges = [ + ["10.0.0.0", "10.255.255.255"], + ["172.16.0.0", "172.31.255.255"], + ["192.168.0.0", "192.168.255.255"], + ]; + + const ipNumber = ip + .split(".") + .reduce( + (acc, octet, index) => acc + (parseInt(octet) << ((3 - index) * 8)), + 0 + ); + + for (const [start, end] of privateRanges) { + const startNumber = start + .split(".") + .reduce( + (acc, octet, index) => acc + (parseInt(octet) << ((3 - index) * 8)), + 0 + ); + const endNumber = end + .split(".") + .reduce( + (acc, octet, index) => acc + (parseInt(octet) << ((3 - index) * 8)), + 0 + ); + + if (ipNumber >= startNumber && ipNumber <= endNumber) { + return true; + } + } + + return false; + } catch (error) { + return false; + } +}