Add dashboard UI updates and settings modal
This commit is contained in:
114
pikit-web/tests/update-settings.spec.js
Normal file
114
pikit-web/tests/update-settings.spec.js
Normal file
@@ -0,0 +1,114 @@
|
||||
import { test, expect } from '@playwright/test';
|
||||
|
||||
const baseStatus = {
|
||||
hostname: 'pikit',
|
||||
ready: true,
|
||||
uptime_seconds: 100,
|
||||
load: [0, 0, 0],
|
||||
memory_mb: { total: 1024, free: 512 },
|
||||
disk_mb: { total: 10240, free: 9000 },
|
||||
cpu_temp_c: 40,
|
||||
lan_ip: '10.0.0.10',
|
||||
os_version: 'DietPi',
|
||||
auto_updates_enabled: true,
|
||||
auto_updates: { enabled: true },
|
||||
};
|
||||
|
||||
const defaultUpdatesConfig = {
|
||||
enabled: true,
|
||||
scope: 'all',
|
||||
update_time: '04:00',
|
||||
upgrade_time: '04:30',
|
||||
cleanup: false,
|
||||
bandwidth_limit_kbps: null,
|
||||
auto_reboot: false,
|
||||
reboot_time: '04:30',
|
||||
reboot_with_users: false,
|
||||
};
|
||||
|
||||
test('update settings form loads and saves config', async ({ page }) => {
|
||||
let posted = null;
|
||||
await page.addInitScript(() => {
|
||||
window.__pikitTest = window.__pikitTest || {};
|
||||
window.__pikitTest.forceAccordionsOpen = true;
|
||||
});
|
||||
|
||||
await page.route('**/api/status', async (route) => {
|
||||
await route.fulfill({ json: { ...baseStatus, services: [] } });
|
||||
});
|
||||
await page.route('**/api/updates/config', async (route) => {
|
||||
if (route.request().method() === 'POST') {
|
||||
posted = await route.request().postDataJSON();
|
||||
await route.fulfill({ json: { ...defaultUpdatesConfig, ...posted } });
|
||||
return;
|
||||
}
|
||||
await route.fulfill({ json: defaultUpdatesConfig });
|
||||
});
|
||||
|
||||
await page.goto('/');
|
||||
await page.click('#advBtn');
|
||||
await expect(page.locator('#acc-updates')).toBeVisible();
|
||||
|
||||
await page.selectOption('#updatesScope', 'security');
|
||||
await page.fill('#updateTimeInput', '03:00');
|
||||
await page.fill('#upgradeTimeInput', '03:30');
|
||||
await page.click('#updatesCleanup');
|
||||
await page.fill('#updatesBandwidth', '500');
|
||||
await page.click('#updatesRebootToggle');
|
||||
await page.fill('#updatesRebootTime', '03:45');
|
||||
await page.click('#updatesRebootUsers');
|
||||
|
||||
const resp = await Promise.all([
|
||||
page.waitForResponse((r) => r.url().includes('/api/updates/config') && r.request().method() === 'POST'),
|
||||
page.click('#updatesSaveBtn'),
|
||||
]);
|
||||
expect(resp[0].ok()).toBeTruthy();
|
||||
|
||||
expect(posted).toMatchObject({
|
||||
enable: true,
|
||||
scope: 'security',
|
||||
update_time: '03:00',
|
||||
upgrade_time: '03:30',
|
||||
cleanup: true,
|
||||
bandwidth_limit_kbps: 500,
|
||||
auto_reboot: true,
|
||||
reboot_time: '03:45',
|
||||
reboot_with_users: true,
|
||||
});
|
||||
|
||||
await expect(page.getByText('Update settings saved.')).toBeVisible({ timeout: 2000 });
|
||||
});
|
||||
|
||||
test('disabling updates disables controls and saves enable=false', async ({ page }) => {
|
||||
let posted = null;
|
||||
await page.addInitScript(() => {
|
||||
window.__pikitTest = window.__pikitTest || {};
|
||||
window.__pikitTest.forceAccordionsOpen = true;
|
||||
});
|
||||
|
||||
await page.route('**/api/status', async (route) => {
|
||||
await route.fulfill({ json: { ...baseStatus, services: [] } });
|
||||
});
|
||||
await page.route('**/api/updates/config', async (route) => {
|
||||
if (route.request().method() === 'POST') {
|
||||
posted = await route.request().postDataJSON();
|
||||
await route.fulfill({ json: { ...defaultUpdatesConfig, ...posted } });
|
||||
return;
|
||||
}
|
||||
await route.fulfill({ json: defaultUpdatesConfig });
|
||||
});
|
||||
|
||||
await page.goto('/');
|
||||
await page.click('#advBtn');
|
||||
|
||||
await page.click('#updatesToggle + .slider', { force: true }); // disable via slider
|
||||
await expect(page.locator('#updatesScope')).toBeDisabled();
|
||||
await expect(page.locator('#updateTimeInput')).toBeDisabled();
|
||||
|
||||
await Promise.all([
|
||||
page.waitForResponse((r) => r.url().includes('/api/updates/config') && r.request().method() === 'POST'),
|
||||
page.click('#updatesSaveBtn'),
|
||||
]);
|
||||
|
||||
expect(posted).toMatchObject({ enable: false });
|
||||
});
|
||||
Reference in New Issue
Block a user