Skip to content

armgit / Pulse

Public Imported from GitHub
0

Real-time monitoring dashboard for Proxmox VE, PBS, Docker, Kubernetes, TrueNAS and vSphere. Self-hosted, with alerts for failed backups, full disks, unhealthy containers and offline nodes.

1.5 KB
Raw Blame
import { beforeEach, describe, expect, it, vi } from 'vitest';

vi.mock('@/api/settings', () => ({
  SettingsAPI: { getSystemSettings: vi.fn() },
}));

vi.mock('@/utils/logger', () => ({
  logger: { debug: vi.fn(), info: vi.fn(), warn: vi.fn(), error: vi.fn() },
}));

import { createLayoutStore } from '@/utils/layout';
import { STORAGE_KEYS } from '@/utils/localStorage';

describe('layout store applyServerMode (#1130)', () => {
  beforeEach(() => {
    localStorage.clear();
  });

  it('applies the server full-width value even when a stale local preference exists', () => {
    // Stale local preference the server value has to beat.
    localStorage.setItem(STORAGE_KEYS.FULL_WIDTH_MODE, 'default');

    const store = createLayoutStore();
    expect(store.isFullWidth()).toBe(false);

    store.applyServerMode(true);

    expect(store.isFullWidth()).toBe(true);
    expect(localStorage.getItem(STORAGE_KEYS.FULL_WIDTH_MODE)).toBe('full-width');
  });

  it('applies a server default that overrides a local full-width preference', () => {
    localStorage.setItem(STORAGE_KEYS.FULL_WIDTH_MODE, 'full-width');

    const store = createLayoutStore();
    expect(store.isFullWidth()).toBe(true);

    store.applyServerMode(false);

    expect(store.isFullWidth()).toBe(false);
  });

  it('leaves the current mode unchanged when the server value is undefined', () => {
    localStorage.setItem(STORAGE_KEYS.FULL_WIDTH_MODE, 'full-width');

    const store = createLayoutStore();
    store.applyServerMode(undefined);

    expect(store.isFullWidth()).toBe(true);
  });
});