ServerKit is a lightweight, modern server control panel for managing web applications, databases, and services on your VPS or dedicated server. Built with Python/Flask backend and React frontend.
Python astracloudflarecontrol-panelcyberpaneldnsfablehosting-control-panelhosting-panelkimi-k3server-managementserverkitubuntu-web-panelwebserver
test(settings): cover AI controls and responsive settings surfaces in browsers
Juan Denis891666786c0f
diff --git a/.github/workflows/frontend-ci.yml b/.github/workflows/frontend-ci.ymlindex b27b8f75..4cc01b87 100644--- a/.github/workflows/frontend-ci.yml+++ b/.github/workflows/frontend-ci.yml@@ -53,6 +53,9 @@ jobs:- name: Settings browser regressionsworking-directory: frontendrun: npm run test:browser+ - name: Settings surfaces and assistant browser regressions+ working-directory: frontend+ run: npm run test:settings-ui- name: Shared controls browser regressionsworking-directory: frontendrun: npm run test:controlsdiff --git a/frontend/package.json b/frontend/package.jsonindex f44bdb19..de588c67 100644--- a/frontend/package.json+++ b/frontend/package.json@@ -8,6 +8,7 @@"build": "vite build","test": "node --test","test:browser": "node scripts/settings-browser.mjs",+ "test:settings-ui": "node scripts/settings-ui-browser.mjs","lint": "node scripts/lint.mjs && node scripts/check-font-integrity.mjs && node scripts/check-settings-index.mjs && node scripts/check-theme-tokens.mjs && node scripts/check-frontend-boundaries.mjs && node scripts/check-style-ownership.mjs && node scripts/check-status-one-door.mjs && node scripts/check-status-scss.mjs && node scripts/check-i18n-literals.mjs && node scripts/check-intl-door.mjs && node scripts/extract-i18n.mjs --check && node scripts/check-i18n.mjs && node scripts/check-logical-properties.mjs && node scripts/generate-vendor-shims.mjs --check && node ../scripts/check-html-sinks.mjs","lint:baseline": "node scripts/lint.mjs --update","test:controls": "node scripts/controls-browser.mjs",diff --git a/frontend/scripts/settings-ui-browser.mjs b/frontend/scripts/settings-ui-browser.mjsnew file mode 100644index 00000000..44445788--- /dev/null+++ b/frontend/scripts/settings-ui-browser.mjs@@ -0,0 +1,152 @@+// Real settings components and SCSS; synthetic APIs never contact a provider.+import assert from 'node:assert/strict';+import { mkdir } from 'node:fs/promises';+import { createServer } from 'vite';+import { chromium } from 'playwright';++const server = await createServer({ server: { host: '127.0.0.1', port: 0, open: false } });+let browser;+try {+ await server.listen();+ await mkdir('test-results', { recursive: true });+ browser = await chromium.launch({ headless: true });+ for (const theme of ['light', 'dark']) {+ const page = await browser.newPage({ viewport: { width: 1440, height: 1100 } });+ const errors = [];+ page.on('pageerror', (error) => errors.push(error.message));+ await page.addInitScript((value) => {+ localStorage.setItem('access_token', 'synthetic-browser-fixture');+ document.addEventListener('DOMContentLoaded', () => { document.documentElement.dataset.theme = value; });+ }, theme);+ let enabled = false;+ let rejectToggle = false;+ let savedConnection;+ let savedPreferences;+ let connection = { id: 'connection-1', name: 'Local gateway', provider: 'openai_compatible', model: 'team/default', config: { endpoint: 'http://gateway.test/v1' }, secrets_set: ['api_key'] };+ await page.route('**/api/v1/**', async (route) => {+ const path = new URL(route.request().url()).pathname;+ const method = route.request().method();+ let payload = {};+ if (path.endsWith('/auth/setup-status')) payload = { needs_setup: false };+ else if (path.endsWith('/auth/me')) payload = { user: { id: 1, username: 'operator', email: '[email protected]', role: 'admin', created_at: '2026-01-01' } };+ else if (path.endsWith('/ai/status')) payload = { enabled, configured: true };+ else if (path.endsWith('/ai/settings')) {+ if (method === 'PUT') {+ const body = route.request().postDataJSON();+ if ('enabled' in body) {+ if (rejectToggle) return route.fulfill({ status: 500, json: { error: 'Synthetic save failure' } });+ enabled = body.enabled;+ }+ }+ payload = { enabled, connections: [connection], default_connection_id: connection.id, max_cost_usd: '0.5', pii_redaction: true, injection_detection: true };+ } else if (path.endsWith('/ai/providers')) payload = { providers: [{ id: 'openai_compatible', label: 'OpenAI-Compatible', available: true, fields: [+ { name: 'endpoint', label: 'API base URL', type: 'url', required: true },+ { name: 'api_key', label: 'API key', type: 'text', secret: true },+ ] }] };+ else if (path.endsWith('/ai/connections/probe')) payload = { models: ['team/default', 'team/reasoning', 'team/fast'], source: 'live' };+ else if (path.endsWith('/ai/connections/connection-1')) {+ savedConnection = route.request().postDataJSON();+ connection = { ...connection, ...savedConnection, secrets_set: ['api_key'] };+ payload = connection;+ } else if (path.endsWith('/ai/connections')) payload = { connections: [connection], default_connection_id: connection.id };+ else if (path.endsWith('/notifications/preferences')) {+ if (method === 'PUT') savedPreferences = route.request().postDataJSON();+ payload = { enabled: true, channels: ['email', 'slack'], severities: ['critical', 'warning'] };+ } else if (path.endsWith('/api-analytics/overview')) payload = { total_requests: 0, avg_response_time_ms: 0, error_rate: 0, success_count: 0 };+ else if (path.endsWith('/views')) payload = { views: [] };+ await route.fulfill({ json: payload });+ });+ const visit = async (pane) => page.goto(`${server.resolvedUrls.local[0]}tests/browser/settings-ui.html?pane=${pane}`);+ await visit('ai');+ await page.locator('#ai-enabled').waitFor();+ await page.locator('#ai-max-cost').fill('1.25');+ await page.getByRole('button', { name: 'Discover models', exact: true }).click();+ await page.getByRole('button', { name: 'Browse models (3)', exact: true }).click();+ await page.getByPlaceholder('Search models…').fill('reasoning');+ await page.getByRole('option', { name: 'team/reasoning', exact: true }).click();+ assert.equal(await page.locator('#ai-model').inputValue(), 'team/reasoning');+ await page.getByRole('button', { name: 'Save connection', exact: true }).click();+ await page.getByText('Connection saved.', { exact: false }).waitFor();+ assert.equal(savedConnection.model, 'team/reasoning');+ assert.equal(savedConnection.config.api_key, undefined, 'Saved secret must not be copied to the browser');+ assert.equal(await page.locator('#ai-max-cost').inputValue(), '1.25', 'Saving a connection erased unsaved limits');+ await page.locator('#ai-enabled').click();+ await page.locator('[data-testid="ai-state"][data-ready="true"]').waitFor({ state: 'attached' });+ await page.reload();+ await page.locator('#ai-enabled[data-state="checked"]').waitFor();+ rejectToggle = true;+ await page.locator('#ai-enabled').click();+ await page.getByRole('alert').filter({ hasText: 'Synthetic save failure' }).waitFor();+ assert.equal(await page.locator('#ai-enabled').getAttribute('data-state'), 'checked');+ rejectToggle = false;+ await page.locator('#ai-enabled').click();+ await page.locator('[data-testid="ai-state"][data-enabled="false"][data-ready="false"]').waitFor({ state: 'attached' });+ await page.screenshot({ path: `test-results/settings-ai-${theme}.png`, fullPage: true });++ await visit('notifications');+ await page.getByRole('heading', { name: 'Notification Channels' }).waitFor();+ assert.equal(await page.getByRole('switch', { name: 'Slack', exact: true }).count(), 0);+ assert.equal(await page.getByRole('checkbox').count(), 0);+ const testButton = await page.getByRole('button', { name: 'Send Test Notification' }).boundingBox();+ const saveButton = await page.getByRole('button', { name: 'Save Preferences' }).boundingBox();+ const footer = await page.locator('.settings-actions--footer').boundingBox();+ assert(saveButton.x - testButton.x - testButton.width >= 12, 'Footer buttons must have a visible gap');+ assert(Math.abs(saveButton.y - testButton.y) < 1, 'Desktop footer actions must align');+ assert(Math.abs(saveButton.x + saveButton.width - footer.x - footer.width) < 2, 'Save belongs at the right edge');+ await page.getByRole('switch', { name: 'Info', exact: true }).click();+ await page.getByRole('button', { name: /Save Preferences/i }).click();+ await page.getByText('Your notification preferences have been saved').waitFor();+ assert(savedPreferences.severities.includes('info'));+ assert(!savedPreferences.channels.includes('slack'), 'Personal preferences must not retain the nonfunctional Slack channel');+ await page.screenshot({ path: `test-results/settings-notifications-${theme}.png`, fullPage: true });+ await page.getByRole('tab', { name: 'Delivery settings' }).click();+ await page.getByRole('button', { name: 'Slack', exact: true }).focus();+ await page.keyboard.press('Enter');+ await page.locator('.channel-config').waitFor();+ for (const display of await page.locator('.channel-config .severity-toggle').evaluateAll((nodes) => nodes.map((node) => getComputedStyle(node).display))) assert.equal(display, 'flex', 'Form labels must not break severity toggle layout');+ const surfaces = await page.locator('.channel-config').evaluate((node) => [getComputedStyle(node).backgroundColor, getComputedStyle(node.querySelector('input')).backgroundColor]);+ assert.notEqual(surfaces[0], surfaces[1], 'Webhook fields disappear into the form surface');+ await page.screenshot({ path: `test-results/settings-delivery-${theme}.png`, fullPage: true });++ await visit('profile');+ await page.locator('.settings-form input').first().waitFor();+ assert.notEqual(await page.locator('.settings-form').evaluate((node) => getComputedStyle(node).backgroundColor), 'rgba(0, 0, 0, 0)');+ await page.screenshot({ path: `test-results/settings-profile-${theme}.png`, fullPage: true });+ await visit('api');+ await page.getByRole('button', { name: 'Create Key' }).waitFor();+ await page.getByText('No API keys yet.').waitFor();+ for (const border of await page.locator('.settings-card > .empty-state').evaluateAll((nodes) => nodes.map((node) => getComputedStyle(node).borderTopWidth))) assert.equal(border, '0px');+ const create = await page.getByRole('button', { name: 'Create Key' }).boundingBox();+ const webhook = await page.getByRole('button', { name: 'Add Webhook' }).boundingBox();+ assert(create.x > 800 && webhook.x > 800, 'Create actions should share the right side of section headers');+ await page.screenshot({ path: `test-results/settings-api-${theme}.png`, fullPage: true });++ await visit('controls');+ await page.locator('#native-field').waitFor();+ for (const selector of ['#native-field', '#native-select']) {+ const field = await page.locator(selector).evaluate((node) => ({ height: node.getBoundingClientRect().height, bg: getComputedStyle(node).backgroundColor }));+ assert(field.height >= 36, 'FormField left a native control unstyled');+ assert.notEqual(field.bg, 'rgba(0, 0, 0, 0)');+ }+ assert((await page.getByRole('checkbox').boundingBox()).width < 32);+ const chrome = await page.locator('.fixture-chrome > *').evaluateAll((nodes) => nodes.map((node) => getComputedStyle(node).backgroundColor));+ assert.equal(new Set(chrome).size, 1, 'Shell bars must share one background token');+ await page.setViewportSize({ width: 390, height: 844 });+ for (const pane of ['ai', 'profile', 'notifications', 'api']) {+ await visit(pane);+ await page.locator('.settings-card, .settings-form').first().waitFor();+ assert(await page.evaluate(() => document.documentElement.scrollWidth <= window.innerWidth), `${pane} overflows on mobile`);+ if (pane === 'notifications') {+ await page.getByRole('button', { name: 'Save Preferences' }).waitFor();+ const actions = await page.locator('.settings-actions--footer > button').evaluateAll((nodes) => nodes.map((node) => ({ top: node.getBoundingClientRect().top, bottom: node.getBoundingClientRect().bottom })));+ assert(actions[1].top - actions[0].bottom >= 12, 'Mobile footer buttons should stack with a gap');+ }+ }+ assert.deepEqual(errors, []);+ await page.close();+ console.log(`Settings ${theme}: model discovery, secret preservation, enable persistence/failure, notifications, surfaces, shell and mobile passed`);+ }+} finally {+ await browser?.close();+ await server.close();+}diff --git a/frontend/tests/browser/settings-ui.html b/frontend/tests/browser/settings-ui.htmlnew file mode 100644index 00000000..ac5b2ab3--- /dev/null+++ b/frontend/tests/browser/settings-ui.html@@ -0,0 +1,5 @@+<!doctype html>+<html lang="en"><head><meta charset="UTF-8"><meta name="viewport" content="width=device-width,initial-scale=1">+<title>Settings UI regression</title>+<style>body { margin: 0; } #root { max-width: 1200px; margin: auto; padding: 24px; } .fixture-chrome { display: none; }</style>+</head><body><div id="root"></div><script type="module" src="./settings-ui.jsx"></script></body></html>diff --git a/frontend/tests/browser/settings-ui.jsx b/frontend/tests/browser/settings-ui.jsxnew file mode 100644index 00000000..41a309ce--- /dev/null+++ b/frontend/tests/browser/settings-ui.jsx@@ -0,0 +1,39 @@+import { createRoot } from 'react-dom/client';+import { MemoryRouter } from 'react-router-dom';+import { AuthProvider } from '../../src/contexts/AuthContext';+import { LocaleProvider } from '../../src/contexts/LocaleContext';+import { ToastProvider } from '../../src/contexts/ToastContext';+import { ConfirmProvider } from '../../src/contexts/ConfirmContext';+import { AIProvider } from '../../src/contexts/AIContext';+import { useServerkitAI } from '../../src/contexts/useServerkitAI';+import AISettingsTab from '../../src/components/settings/AISettingsTab';+import ProfileTab from '../../src/components/settings/ProfileTab';+import NotificationsTab from '../../src/components/settings/NotificationsTab';+import ApiSettingsTab from '../../src/components/settings/ApiSettingsTab';+import { FormField } from '../../src/components/FormField';+import '../../src/styles/main.scss';++export function Fixture() {+ const ai = useServerkitAI();+ const pane = new URLSearchParams(window.location.search).get('pane') || 'ai';+ return <>+ <div hidden data-testid="ai-state" data-enabled={ai.enabled} data-ready={ai.providerConfigured} />+ <main className="settings-content">+ {pane === 'ai' && <AISettingsTab />}+ {pane === 'profile' && <ProfileTab />}+ {pane === 'notifications' && <NotificationsTab />}+ {pane === 'api' && <ApiSettingsTab />}+ {pane === 'controls' && <div className="settings-card">+ <FormField label="Native field" htmlFor="native-field"><input id="native-field" /></FormField>+ <FormField label="Native select" htmlFor="native-select"><select id="native-select"><option>Option</option></select></FormField>+ <FormField><input type="checkbox" aria-label="Native checkbox" /></FormField>+ </div>}+ </main>+ <div className="fixture-chrome"><div className="sidebar" /><div className="sk-topbar" /><div className="global-statusbar" /></div>+ </>;+}+createRoot(document.getElementById('root')).render(+ <MemoryRouter><LocaleProvider><AuthProvider><ToastProvider><ConfirmProvider><AIProvider>+ <Fixture />+ </AIProvider></ConfirmProvider></ToastProvider></AuthProvider></LocaleProvider></MemoryRouter>+);