Show occupied disk and RAM capacity with matching used and free segments
Rust development slice / linux (push) Failing after 9s

This commit is contained in:
2026-11-20 08:40:48 +01:00
parent 957bf3cd58
commit b5e96853c3
5 changed files with 44 additions and 39 deletions
+16 -14
View File
@@ -20,7 +20,7 @@ test.beforeAll(async () => {
test.afterAll(async () => { await server?.close(); });
test('draws free disk and RAM shares accurately on desktop and mobile', async ({ page }) => {
test('shows used disk and RAM in GiB and draws the occupied share in red on desktop and mobile', async ({ page }) => {
const customer = { tenant_id: '11111111-1111-4111-8111-111111111111', name: 'RAM-Test' };
const gib = 2 ** 30;
const readings = [
@@ -58,20 +58,23 @@ test('draws free disk and RAM shares accurately on desktop and mobile', async ({
for (const width of [1280, 900, 390]) {
await page.setViewportSize({ width, height: 844 });
for (const label of ['RAM', 'Speicher']) {
const cell = (host: string) => row(host).locator(`[data-label="${label} frei / gesamt"]`);
await expect(cell('mostly-free')).toContainText('12 / 16 GiB');
for (const [host, free] of [['mostly-free', 75], ['all-used', 0], ['all-free', 100]] as const) {
await expect(cell(host).locator('.capacity-caption')).toHaveText(`${free} % frei`);
const bar = cell(host).getByRole('img', { name: `${free} % frei, ${100 - free} % belegt` });
const cell = (host: string) => row(host).locator(`[data-label="${label} belegt / gesamt"]`);
for (const [host, used, usedGiB] of [['mostly-free', 25, 4], ['all-used', 100, 16], ['all-free', 0, 0]] as const) {
await expect(cell(host)).toContainText(`${usedGiB} / 16 GiB`);
await expect(cell(host).locator('.capacity-caption')).toHaveText(`${used} % belegt`);
const bar = cell(host).getByRole('img', { name: `${used} % belegt, ${100 - used} % frei` });
await expect(bar).toBeVisible();
const [track = 0, freeWidth = 0, usedWidth = 0] = await bar.evaluate(el => [el, ...Array.from(el.children)]
await expect(bar.locator('.capacity-used')).toHaveCSS('background-color', 'rgb(199, 137, 128)');
await expect(bar.locator('.capacity-free')).toHaveCSS('background-color', 'rgb(46, 118, 87)');
const [track = 0, usedWidth = 0, freeWidth = 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);
expect(usedWidth / track).toBeCloseTo(used / 100, 2);
expect(freeWidth / track).toBeCloseTo((100 - used) / 100, 2);
}
for (const host of ['missing-available', 'invalid-range', 'invalid-total']) {
await expect(cell(host).locator('.capacity-track')).toHaveCount(0);
await expect(cell(host)).toHaveText(host === 'invalid-total' ? 'Nicht gemeldet' : '– / 16 GiB');
}
}
}
@@ -167,11 +170,10 @@ test('creates and renames a customer, opens its inventory, and hides editing for
await expect(headers.nth(1)).toHaveText('Type');
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).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"]').getByRole('img', { name: '75 % frei, 25 % belegt' })).toBeVisible();
const memory = device.locator('[data-label="RAM belegt / gesamt"]');
await expect(memory).toContainText('10 / 16 GiB');
await expect(memory.getByRole('img', { name: '62,5 % belegt, 37,5 % frei' })).toBeVisible();
await expect(device.locator('[data-label="Speicher belegt / gesamt"]').getByRole('img', { name: '25 % belegt, 75 % frei' })).toBeVisible();
await expect(device.getByText('Auslastung 0 %', { exact: true })).toBeVisible();
const navigation = page.getByRole('navigation', { name: 'Hauptnavigation' });
await navigation.getByRole('link', { name: 'Aufträge', exact: true }).click();