test(260928-ujj): rote Tests fuer Dashboard-Hintergrund in der Datenbank
- PATCH me/dashboard-background: Allowlist, UUID-Bildkennung, Mandantenbindung - getMe liefert dashboardBackground normalisiert - Web: Uebernahme der alten localStorage-Wahl, Hook liest aus dem Auth-Store Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -1,48 +1,72 @@
|
||||
import { DASHBOARD_BACKGROUND_PRESET_IDS } from '@tessera/shared';
|
||||
import { afterEach, describe, expect, it, vi } from 'vitest';
|
||||
import {
|
||||
BACKGROUND_PRESETS,
|
||||
DARK_FALLBACK_ID,
|
||||
loadDashboardBackground,
|
||||
presetBackground,
|
||||
saveDashboardBackground,
|
||||
takeLegacyDashboardBackground,
|
||||
} from './dashboard-background';
|
||||
|
||||
const IMAGE_ID = '3f2b8c1e-9a4d-4e7f-8b21-0c5d6e7f8a9b';
|
||||
|
||||
afterEach(() => {
|
||||
window.localStorage.clear();
|
||||
vi.restoreAllMocks();
|
||||
});
|
||||
|
||||
describe('dashboard-background (Design „Mosaik“, Prototyp)', () => {
|
||||
it('ohne gespeicherte Wahl: kein Hintergrund', () => {
|
||||
expect(loadDashboardBackground('u1')).toEqual({ kind: 'none' });
|
||||
});
|
||||
|
||||
it('speichert je Benutzer getrennt', () => {
|
||||
saveDashboardBackground('u1', { kind: 'preset', id: 'bloom' });
|
||||
saveDashboardBackground('u2', { kind: 'image', imageId: 'img-1' });
|
||||
expect(loadDashboardBackground('u1')).toEqual({ kind: 'preset', id: 'bloom' });
|
||||
expect(loadDashboardBackground('u2')).toEqual({ kind: 'image', imageId: 'img-1' });
|
||||
});
|
||||
|
||||
it('verwirft kaputte oder unbekannte Werte', () => {
|
||||
window.localStorage.setItem('tessera.dashboardBackground.u1', '{kaputt');
|
||||
expect(loadDashboardBackground('u1')).toEqual({ kind: 'none' });
|
||||
window.localStorage.setItem(
|
||||
'tessera.dashboardBackground.u1',
|
||||
JSON.stringify({ kind: 'preset', id: 'regenbogen' }),
|
||||
);
|
||||
expect(loadDashboardBackground('u1')).toEqual({ kind: 'none' });
|
||||
});
|
||||
|
||||
it('gesperrter Speicher wirft nicht', () => {
|
||||
vi.spyOn(Storage.prototype, 'getItem').mockImplementation(() => {
|
||||
throw new Error('blocked');
|
||||
describe('dashboard-background (Design „Mosaik“)', () => {
|
||||
describe('takeLegacyDashboardBackground (quick-260928-ujj)', () => {
|
||||
it('ohne alte Wahl: null', () => {
|
||||
expect(takeLegacyDashboardBackground('u1')).toBeNull();
|
||||
});
|
||||
vi.spyOn(Storage.prototype, 'setItem').mockImplementation(() => {
|
||||
throw new Error('blocked');
|
||||
|
||||
it('liefert eine gueltige alte Wahl je Benutzer und entfernt den Schluessel', () => {
|
||||
window.localStorage.setItem(
|
||||
'tessera.dashboardBackground.u1',
|
||||
JSON.stringify({ kind: 'preset', id: 'bloom' }),
|
||||
);
|
||||
window.localStorage.setItem(
|
||||
'tessera.dashboardBackground.u2',
|
||||
JSON.stringify({ kind: 'image', imageId: IMAGE_ID }),
|
||||
);
|
||||
|
||||
expect(takeLegacyDashboardBackground('u1')).toEqual({ kind: 'preset', id: 'bloom' });
|
||||
expect(window.localStorage.getItem('tessera.dashboardBackground.u1')).toBeNull();
|
||||
// der Schluessel des anderen Benutzers bleibt, bis dieser sich anmeldet
|
||||
expect(window.localStorage.getItem('tessera.dashboardBackground.u2')).not.toBeNull();
|
||||
expect(takeLegacyDashboardBackground('u2')).toEqual({ kind: 'image', imageId: IMAGE_ID });
|
||||
// zweiter Aufruf: nichts mehr da
|
||||
expect(takeLegacyDashboardBackground('u1')).toBeNull();
|
||||
});
|
||||
expect(() => saveDashboardBackground('u1', { kind: 'preset', id: 'mist' })).not.toThrow();
|
||||
expect(loadDashboardBackground('u1')).toEqual({ kind: 'none' });
|
||||
|
||||
it.each([
|
||||
['{kaputt'],
|
||||
[JSON.stringify({ kind: 'preset', id: 'regenbogen' })],
|
||||
// Prototyp-Werte mit beliebiger Bildkennung werden nicht uebernommen
|
||||
[JSON.stringify({ kind: 'image', imageId: 'img-1' })],
|
||||
[JSON.stringify(null)],
|
||||
])('ungueltiger Wert %j: null, Schluessel entfernt', (raw) => {
|
||||
window.localStorage.setItem('tessera.dashboardBackground.u1', raw);
|
||||
|
||||
expect(takeLegacyDashboardBackground('u1')).toBeNull();
|
||||
expect(window.localStorage.getItem('tessera.dashboardBackground.u1')).toBeNull();
|
||||
});
|
||||
|
||||
it('gesperrter Speicher: null ohne Ausnahme', () => {
|
||||
vi.spyOn(Storage.prototype, 'getItem').mockImplementation(() => {
|
||||
throw new Error('blocked');
|
||||
});
|
||||
vi.spyOn(Storage.prototype, 'removeItem').mockImplementation(() => {
|
||||
throw new Error('blocked');
|
||||
});
|
||||
|
||||
expect(() => takeLegacyDashboardBackground('u1')).not.toThrow();
|
||||
expect(takeLegacyDashboardBackground('u1')).toBeNull();
|
||||
});
|
||||
});
|
||||
|
||||
it('die eingebauten Hintergruende sind deckungsgleich mit der Pruefregel in @tessera/shared', () => {
|
||||
expect(BACKGROUND_PRESETS.map((p) => p.id).sort()).toEqual([...DASHBOARD_BACKGROUND_PRESET_IDS].sort());
|
||||
});
|
||||
|
||||
it('jeder eingebaute Hintergrund liefert hell und dunkel ein Bild (dunkel notfalls den Ersatz)', () => {
|
||||
|
||||
Reference in New Issue
Block a user