clean: use best practices

This commit is contained in:
hayzam 2024-02-07 05:59:45 +05:30
parent c1fc6907f7
commit c5eb074234
Signed by: hayzam
GPG key ID: 13B4C5B544B53947
7 changed files with 27 additions and 29 deletions

1
.husky/pre-commit Normal file
View file

@ -0,0 +1 @@
npm run lint

3
package-lock.json generated
View file

@ -10,13 +10,13 @@
"license": "ISC",
"dependencies": {
"dotenv": "^16.4.1",
"husky": "^9.0.10",
"ip-address": "^9.0.5",
"ip-cidr": "^4.0.0"
},
"devDependencies": {
"@playwright/test": "^1.41.2",
"@types/node": "^20.11.16",
"husky": "^9.0.10",
"semistandard": "^17.0.0"
}
},
@ -1613,6 +1613,7 @@
"version": "9.0.10",
"resolved": "https://registry.npmjs.org/husky/-/husky-9.0.10.tgz",
"integrity": "sha512-TQGNknoiy6bURzIO77pPRu+XHi6zI7T93rX+QnJsoYFf3xdjKOur+IlfqzJGMHIK/wXrLg+GsvMs8Op7vI2jVA==",
"dev": true,
"bin": {
"husky": "bin.mjs"
},

View file

@ -6,7 +6,8 @@
"type": "module",
"scripts": {
"lint": "semistandard --fix tests/**/*.js",
"test": "playwright test"
"test": "playwright test",
"prepare": "npm run lint"
},
"husky": {
"hooks": {
@ -19,11 +20,11 @@
"devDependencies": {
"@playwright/test": "^1.41.2",
"@types/node": "^20.11.16",
"husky": "^9.0.10",
"semistandard": "^17.0.0"
},
"dependencies": {
"dotenv": "^16.4.1",
"husky": "^9.0.10",
"ip-address": "^9.0.5",
"ip-cidr": "^4.0.0"
}

View file

@ -5,9 +5,9 @@ const authFile = 'playwright/.auth/user.json';
test('Authenticate', async ({ page }) => {
await page.goto('/login');
await page.waitForSelector('input[name="user"]', { timeout: 3000 });
await page.fill('input[name="user"]', process.env.ADMIN_USER);
await page.fill('input[name="password"]', process.env.ADMIN_PASS);
await page.click('#subBut');
await page.getByPlaceholder('Username').fill( process.env.ADMIN_USER);
await page.getByPlaceholder('Password').fill(process.env.ADMIN_PASS);
await page.getByRole('link', { name: 'Login' }).click();
await page.waitForSelector('span:has-text("Quick Actions")', { timeout: 3000 });
expect(await page.title()).toBe('Difuse - Dashboard - Router');
await page.context().storageState({ path: authFile });

View file

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

View file

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

View file

@ -2,8 +2,7 @@ import { test, expect } from '@playwright/test';
import { isValidMacAddress, isValidCidr } from '../../utils/utils.js';
test.beforeEach(async ({ page }) => {
await page.goto('/network/guest-lan');
await page.waitForTimeout(2500);
await page.goto('/network/guest-lan', { waitUntil: 'networkidle' });
});
test('Title', async ({ page }) => {