import type { Store } from '../state/createStore' import { createStore } from '../state/createStore' import { createEmitter } from '../events' import type { GridNavigationApi } from './navigation' import { createNavigationApi } from './navigation' describe('navigation api', () => { let store: Store, api: GridNavigationApi beforeEach(() => { store = createStore() store.dispatch = jest.fn() jest.spyOn(store.selectors, 'selectNavigationEnabled') const events = createEmitter() api = createNavigationApi(store, events) }) it('should dispatch updateNavigationState when calling enable', () => { jest.mocked(store.selectors.selectNavigationEnabled).mockReturnValue( false ) api.enable() expect(store.dispatch).toHaveBeenCalledWith({ type: 'updateNavigationState', payload: { enabled: true }, }) }) it('should not dispatch updateNavigationState when calling enable and already enabled', () => { jest.mocked(store.selectors.selectNavigationEnabled).mockReturnValue( true ) api.enable() expect(store.dispatch).not.toHaveBeenCalled() }) it('should dispatch updateNavigationState when calling disable', () => { jest.mocked(store.selectors.selectNavigationEnabled).mockReturnValue( true ) api.disable() expect(store.dispatch).toHaveBeenCalledWith({ type: 'updateNavigationState', payload: { enabled: false }, }) }) it('should not dispatch updateNavigationState when calling disable and already disabled', () => { jest.mocked(store.selectors.selectNavigationEnabled).mockReturnValue( false ) api.disable() expect(store.dispatch).not.toHaveBeenCalled() }) })