crud.spec.js 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. import { expect } from 'chai';
  2. import {
  3. getDocs
  4. } from 'selectors/crud';
  5. describe('CRUD selectors', () => {
  6. describe('getDocs', () => {
  7. const route = 'employees';
  8. it('should return the list of docs', () => {
  9. const state = {
  10. crud: {
  11. [route]: {
  12. items: [
  13. {
  14. id: '<actualId>',
  15. name: 'John Doe',
  16. email: 'john.doe@mubaloo.com'
  17. }
  18. ]
  19. }
  20. }
  21. };
  22. const result = getDocs(state, route);
  23. expect(result).to.deep.equal(state.crud[route].items);
  24. });
  25. it('should return an empty array by default', () => {
  26. const state = {
  27. crud: {}
  28. };
  29. const result = getDocs(state, route);
  30. expect(result).to.deep.equal([]);
  31. });
  32. it('should memoise default results', () => {
  33. const state = {
  34. crud: {}
  35. };
  36. const resultA = getDocs(state, route);
  37. const resultB = getDocs(state, route);
  38. expect(resultA).to.equal(resultB);
  39. });
  40. });
  41. });