Clarify the free and used RAM bar in device inventory
Rust development slice / linux (push) Failing after 12s
Rust development slice / linux (push) Failing after 12s
This commit is contained in:
@@ -20,6 +20,63 @@ test.beforeAll(async () => {
|
||||
|
||||
test.afterAll(async () => { await server?.close(); });
|
||||
|
||||
test('draws the free RAM share accurately on desktop and mobile', async ({ page }) => {
|
||||
const customer = { tenant_id: '11111111-1111-4111-8111-111111111111', name: 'RAM-Test' };
|
||||
const gib = 2 ** 30;
|
||||
const readings = [
|
||||
['mostly-free', 12 * gib, 16 * gib],
|
||||
['all-used', 0, 16 * gib],
|
||||
['all-free', 16 * gib, 16 * gib],
|
||||
['missing-available', null, 16 * gib],
|
||||
['invalid-range', 17 * gib, 16 * gib],
|
||||
['invalid-total', 0, 0],
|
||||
] as const;
|
||||
const listing = (items: unknown[]) => ({
|
||||
items, next_cursor: null, truncated: false, completeness: 'complete', as_of: '2026-11-19T12:00:00Z'
|
||||
});
|
||||
await page.route(`${origin}/auth/config`, route => route.fulfill({
|
||||
json: { local_login_enabled: true, oidc_configured: false, oidc_login_url: null, dev_login_enabled: false }
|
||||
}));
|
||||
await page.route(`${origin}/auth/session`, route => route.fulfill({
|
||||
json: { principal: 'ram-reader', testsimulation: false, tenant_id: customer.tenant_id,
|
||||
csrf_token: 'ram-fixture', permissions: ['inventory:read'] }
|
||||
}));
|
||||
await page.route(`${origin}/api/v1/**`, route => {
|
||||
const pathname = new URL(route.request().url()).pathname;
|
||||
if (pathname === '/api/v1/tenants') return route.fulfill({ json: listing([customer]) });
|
||||
if (pathname === '/api/v1/devices') return route.fulfill({
|
||||
json: listing(readings.map(([hostname, free, total]) => ({
|
||||
tenant_id: customer.tenant_id, customer_name: customer.name, asset_id: hostname, agent_id: hostname,
|
||||
lifecycle: 'current', status: 'online', hostname, ram_available_bytes: free, ram_total_bytes: total,
|
||||
disk_free_bytes: 12 * gib, disk_total_bytes: 16 * gib
|
||||
})))
|
||||
});
|
||||
return route.fulfill({ status: 404 });
|
||||
});
|
||||
await page.goto(`${origin}/#geraete`);
|
||||
const row = (host: string) => page.getByRole('row').filter({ has: page.getByRole('button', { name: host, exact: true }) });
|
||||
const ram = (host: string) => row(host).locator('[data-label="RAM frei / gesamt"]');
|
||||
await expect(ram('mostly-free')).toContainText('12 / 16 GiB');
|
||||
await expect(ram('mostly-free').locator('.capacity-caption')).toHaveText('75 % frei');
|
||||
await expect(row('mostly-free').locator('[data-label="Speicher frei / gesamt"] .capacity-track i'))
|
||||
.toHaveAttribute('style', 'width: 25%;');
|
||||
for (const width of [1280, 900, 390]) {
|
||||
await page.setViewportSize({ width, height: 844 });
|
||||
for (const [host, free] of [['mostly-free', 75], ['all-used', 0], ['all-free', 100]] as const) {
|
||||
const bar = ram(host).getByRole('img', { name: `${free} % frei, ${100 - free} % belegt` });
|
||||
await expect(bar).toBeVisible();
|
||||
const [track = 0, freeWidth = 0, usedWidth = 0] = await bar.evaluate(el => [el, ...Array.from(el.children)]
|
||||
.map(part => part.getBoundingClientRect().width));
|
||||
expect(track).toBeGreaterThan(0);
|
||||
expect(freeWidth / track).toBeCloseTo(free / 100, 2);
|
||||
expect(usedWidth / track).toBeCloseTo((100 - free) / 100, 2);
|
||||
}
|
||||
}
|
||||
for (const host of ['missing-available', 'invalid-range', 'invalid-total']) {
|
||||
await expect(ram(host).locator('.capacity-track')).toHaveCount(0);
|
||||
}
|
||||
});
|
||||
|
||||
test('creates and renames a customer, opens its inventory, and hides editing for a reader', async ({ page }) => {
|
||||
const home = { tenant_id: '11111111-1111-4111-8111-111111111111', name: 'Testzentrale' };
|
||||
const customerId = '22222222-2222-4222-8222-222222222222';
|
||||
@@ -111,9 +168,9 @@ test('creates and renames a customer, opens its inventory, and hides editing for
|
||||
await expect(device.locator('[data-label="Type"]')).toHaveText('hypervisor');
|
||||
await expect(device.locator('[data-label="OS"]')).toHaveText('Proxmox VE');
|
||||
const memory = device.locator('[data-label="RAM frei / gesamt"]');
|
||||
await expect(memory).toHaveText('6 / 16 GiB');
|
||||
await expect(memory.locator('.capacity-track')).toHaveAttribute('title', '37,5 % frei');
|
||||
await expect(memory.locator('.capacity-track i')).toHaveAttribute('style', 'width: 62.5%;');
|
||||
await expect(memory).toContainText('6 / 16 GiB');
|
||||
await expect(memory.getByRole('img', { name: '37,5 % frei, 62,5 % belegt' })).toBeVisible();
|
||||
await expect(memory.locator('.capacity-free')).toHaveAttribute('style', 'width: 37.5%;');
|
||||
await expect(device.locator('[data-label="Speicher frei / gesamt"] .capacity-track i'))
|
||||
.toHaveAttribute('style', 'width: 25%;');
|
||||
await expect(device.getByText('Auslastung 0 %', { exact: true })).toBeVisible();
|
||||
|
||||
Reference in New Issue
Block a user