44 lines
1.4 KiB
TypeScript
44 lines
1.4 KiB
TypeScript
import { afterEach, describe, expect, it, vi } from 'vitest';
|
|
|
|
import { createConditionEvaluator } from '../../../../src/condition-trigger/conditions/factory';
|
|
import { createEvaluatorContext } from './test-utils';
|
|
|
|
// @vitest-environment jsdom
|
|
describe('screen condition', () => {
|
|
afterEach(() => {
|
|
vi.restoreAllMocks();
|
|
});
|
|
|
|
it('should evaluate the media query', () => {
|
|
vi.spyOn(window, 'matchMedia').mockReturnValue({
|
|
matches: true,
|
|
} as unknown as MediaQueryList);
|
|
|
|
const evaluator = createConditionEvaluator(
|
|
{ condition: 'screen' as const, media_query: 'whatever' },
|
|
createEvaluatorContext(),
|
|
);
|
|
expect(evaluator.evaluate().result).toBeTruthy();
|
|
});
|
|
|
|
it('should expose the media query as an external invalidation source', () => {
|
|
const evaluator = createConditionEvaluator(
|
|
{ condition: 'screen' as const, media_query: 'whatever' },
|
|
createEvaluatorContext(),
|
|
);
|
|
expect(evaluator.externalSources).toHaveLength(1);
|
|
});
|
|
|
|
it('should not match or expose a source without a media query', () => {
|
|
const matchMedia = vi.spyOn(window, 'matchMedia');
|
|
const evaluator = createConditionEvaluator(
|
|
{ condition: 'screen' as const },
|
|
createEvaluatorContext(),
|
|
);
|
|
|
|
expect(evaluator.evaluate().result).toBeFalsy();
|
|
expect(evaluator.externalSources).toHaveLength(0);
|
|
expect(matchMedia).not.toHaveBeenCalled();
|
|
});
|
|
});
|