import type { GridEditState } from './edit' import reducerConfig, { selectEdit, selectIsEditing, selectIsEditingCell, selectIsEditingCellInColumn, } from './edit' const { reducer: editReducer } = reducerConfig const getStateMock = () => reducerConfig.initialState describe('editReducer', () => { describe('unknown action', () => { it('should not modify the state', () => { const state = getStateMock() const newState = editReducer(state, { type: 'nope' } as any) expect(state).toBe(newState) }) }) describe('updateEdit', () => { it('should replace the edit config', () => { const state = editReducer(getStateMock(), { type: 'updateEdit', payload: { rowId: '2', columnId: 'firstName', }, }) expect(selectEdit(state)).toEqual({ rowId: '2', columnId: 'firstName', }) }) }) describe('selectIsEditing', () => { it('should return false when no currentEdit value', () => { expect(selectIsEditing(getStateMock())).toBe(false) }) it('should return true with a currentEdit value', () => { const state = editReducer(getStateMock(), { type: 'updateEdit', payload: { rowId: '2', columnId: 'firstName', }, }) expect(selectIsEditing(state)).toBe(true) }) }) describe('selectIsEditingCell', () => { let state: GridEditState beforeEach(() => { state = editReducer(getStateMock(), { type: 'updateEdit', payload: { rowId: '2', columnId: 'firstName', }, }) }) it('should return false when no currentEdit value', () => { expect( selectIsEditingCell(getStateMock(), { columnId: 'firstName', rowId: '2', }) ).toBe(false) }) it('should return true with a currentEdit value that matches', () => { expect( selectIsEditingCell(state, { columnId: 'firstName', rowId: '2', }) ).toBe(true) }) it('should return false with a currentEdit value that does not match', () => { expect( selectIsEditingCell(state, { columnId: 'firstName', rowId: '3', }) ).toBe(false) }) }) describe('selectIsEditingCellInColumn', () => { let state: GridEditState beforeEach(() => { state = editReducer(getStateMock(), { type: 'updateEdit', payload: { rowId: '2', columnId: 'firstName', }, }) }) it('should return false when no currentEdit value', () => { expect( selectIsEditingCellInColumn(getStateMock(), 'firstName') ).toBe(false) }) it('should return true with a currentEdit value that matches', () => { expect(selectIsEditingCellInColumn(state, 'firstName')).toBe(true) }) it('should return false with a currentEdit value that does not match', () => { expect(selectIsEditingCellInColumn(state, 'lastName')).toBe(false) }) }) })