import { expect } from 'chai'; import { getCrudLoading, getDocs } from 'selectors/crud'; describe('CRUD selectors', () => { describe('getCrudLoading', () => { const route = 'employees'; it('should return true if the CRUD page is loading', () => { const state = { crud: { [route]: { loading: true, items: [] } } }; expect(getCrudLoading(state, route)).to.equal(true); }); it('should return false if the CRUD page is not loading', () => { expect(getCrudLoading({ crud: { [route]: { loading: false }, otherRoute: { loading: true } } }), route) .to.equal(false); expect(getCrudLoading({ crud: {} }), route) .to.equal(false); }); }); describe('getDocs', () => { const route = 'employees'; it('should return the list of docs', () => { const state = { crud: { [route]: { items: [ { id: '', name: 'John Doe', email: 'john.doe@mubaloo.com' } ] } } }; const result = getDocs(state, route); expect(result).to.deep.equal(state.crud[route].items); }); it('should return an empty array by default', () => { const state = { crud: {} }; const result = getDocs(state, route); expect(result).to.deep.equal([]); }); it('should memoise default results', () => { const state = { crud: {} }; const resultA = getDocs(state, route); const resultB = getDocs(state, route); expect(resultA).to.equal(resultB); }); }); });