Files
advanced-camera-card/tests/card-controller/expand-manager.test.ts
T
Dermot Duffy 8d3cf07b43 refactor: Significantly refactor how conditions work internally (#1886)
- Much improved API cleanliness and testability to allow further
extensibility in future
 - Simplified code in `live` view

This technically contains a small change in how overrides work in the
`live` view. Since that change is _closer_ to the documentation, and
since this is likely to be rarely used, this is not considered a
breaking change. Previously, overrides for a given live camera would
always render _as if_ that camera was selected, vs was actually
selected. Now, overrides will only apply in the live view when the
camera is _actually_ selected. If this is an issue for you in practice,
lets discuss.
2025-02-11 20:07:55 -08:00

55 lines
1.8 KiB
TypeScript

import { describe, expect, it, vi } from 'vitest';
import { ExpandManager } from '../../src/card-controller/expand-manager';
import { createCardAPI } from '../test-utils';
describe('ExpandManager', () => {
it('should construct', () => {
const api = createCardAPI();
const manager = new ExpandManager(api);
expect(manager.isExpanded()).toBeFalsy();
});
it('should initialize', () => {
const api = createCardAPI();
const manager = new ExpandManager(api);
manager.initialize();
expect(api.getConditionStateManager().setState).toBeCalledWith({ expand: false });
});
it('should set expanded', () => {
const api = createCardAPI();
vi.mocked(api.getFullscreenManager().isInFullscreen).mockReturnValue(true);
const manager = new ExpandManager(api);
manager.setExpanded(true);
expect(manager.isExpanded()).toBeTruthy();
expect(api.getFullscreenManager().setFullscreen).toBeCalledWith(false);
expect(api.getConditionStateManager().setState).toBeCalledWith({ expand: true });
expect(api.getCardElementManager().update).toBeCalled();
});
it('should not exit fullscreen when not in fullscreen', () => {
const api = createCardAPI();
vi.mocked(api.getFullscreenManager().isInFullscreen).mockReturnValue(false);
const manager = new ExpandManager(api);
manager.setExpanded(true);
expect(api.getFullscreenManager().setFullscreen).not.toBeCalled();
});
it('should toggle expanded', () => {
const api = createCardAPI();
vi.mocked(api.getFullscreenManager().isInFullscreen).mockReturnValue(false);
const manager = new ExpandManager(api);
manager.toggleExpanded();
expect(manager.isExpanded()).toBeTruthy();
manager.toggleExpanded();
expect(manager.isExpanded()).toBeFalsy();
});
});