2025-11-24 23:11:46 +05:30
|
|
|
/**
|
|
|
|
|
* @license
|
|
|
|
|
* Copyright 2025 Google LLC
|
|
|
|
|
* SPDX-License-Identifier: Apache-2.0
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
import { describe, it, expect, vi } from 'vitest';
|
|
|
|
|
import { appEvents, AppEvent } from './events.js';
|
|
|
|
|
|
|
|
|
|
describe('events', () => {
|
|
|
|
|
it('should allow registering and emitting events', () => {
|
|
|
|
|
const callback = vi.fn();
|
2026-01-23 11:45:46 -05:00
|
|
|
appEvents.on(AppEvent.SelectionWarning, callback);
|
2025-11-24 23:11:46 +05:30
|
|
|
|
2026-01-23 11:45:46 -05:00
|
|
|
appEvents.emit(AppEvent.SelectionWarning);
|
2025-11-24 23:11:46 +05:30
|
|
|
|
2026-01-23 11:45:46 -05:00
|
|
|
expect(callback).toHaveBeenCalled();
|
2025-11-24 23:11:46 +05:30
|
|
|
|
2026-01-23 11:45:46 -05:00
|
|
|
appEvents.off(AppEvent.SelectionWarning, callback);
|
2025-11-24 23:11:46 +05:30
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it('should work with events without data', () => {
|
|
|
|
|
const callback = vi.fn();
|
|
|
|
|
appEvents.on(AppEvent.Flicker, callback);
|
|
|
|
|
|
|
|
|
|
appEvents.emit(AppEvent.Flicker);
|
|
|
|
|
|
|
|
|
|
expect(callback).toHaveBeenCalled();
|
|
|
|
|
|
|
|
|
|
appEvents.off(AppEvent.Flicker, callback);
|
|
|
|
|
});
|
|
|
|
|
});
|