import type { Store } from '../state/createStore' import { createStore } from '../state/createStore' import { createEmitter } from '../events' import type { GridActionsMenuApi } from './actions-menu' import { createActionsMenuApi } from './actions-menu' describe('actions-menu api', () => { let store: Store, api: GridActionsMenuApi beforeEach(() => { store = createStore() store.dispatch = jest.fn() jest.spyOn(store.selectors, 'selectActionsMenuEnabled') const events = createEmitter() api = createActionsMenuApi(store, events) }) it('should dispatch showActionsMenu when calling show', () => { jest.mocked(store.selectors.selectActionsMenuEnabled).mockReturnValue( true ) api.show('123', { top: 24, left: 100 }) expect(store.dispatch).toHaveBeenCalledWith({ type: 'showActionsMenu', payload: { rowId: '123', coordinates: { top: 24, left: 100 } }, }) }) it('should not dispatch showActionsMenu when calling show when not enabled', () => { jest.mocked(store.selectors.selectActionsMenuEnabled).mockReturnValue( false ) api.show('123', { top: 24, left: 100 }) expect(store.dispatch).not.toHaveBeenCalled() }) it('should dispatch hideActionsMenu when calling hide', () => { api.hide() expect(store.dispatch).toHaveBeenCalledWith({ type: 'hideActionsMenu', payload: undefined, }) }) })