crud.spec.js 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. import { expect } from 'chai';
  2. import {
  3. getCrudLoading,
  4. getDocs
  5. } from 'selectors/crud';
  6. describe('CRUD selectors', () => {
  7. describe('getCrudLoading', () => {
  8. const route = 'employees';
  9. it('should return true if the CRUD page is loading', () => {
  10. const state = {
  11. crud: {
  12. [route]: {
  13. loading: true,
  14. items: []
  15. }
  16. }
  17. };
  18. expect(getCrudLoading(state, route)).to.equal(true);
  19. });
  20. it('should return false if the CRUD page is not loading', () => {
  21. expect(getCrudLoading({
  22. crud: {
  23. [route]: {
  24. loading: false
  25. },
  26. otherRoute: {
  27. loading: true
  28. }
  29. }
  30. }), route)
  31. .to.equal(false);
  32. expect(getCrudLoading({
  33. crud: {}
  34. }), route)
  35. .to.equal(false);
  36. });
  37. });
  38. describe('getDocs', () => {
  39. const route = 'employees';
  40. it('should return the list of docs', () => {
  41. const state = {
  42. crud: {
  43. [route]: {
  44. items: [
  45. {
  46. id: '<actualId>',
  47. name: 'John Doe',
  48. email: 'john.doe@mubaloo.com'
  49. }
  50. ]
  51. }
  52. }
  53. };
  54. const result = getDocs(state, route);
  55. expect(result).to.deep.equal(state.crud[route].items);
  56. });
  57. it('should return an empty array by default', () => {
  58. const state = {
  59. crud: {}
  60. };
  61. const result = getDocs(state, route);
  62. expect(result).to.deep.equal([]);
  63. });
  64. it('should memoise default results', () => {
  65. const state = {
  66. crud: {}
  67. };
  68. const resultA = getDocs(state, route);
  69. const resultB = getDocs(state, route);
  70. expect(resultA).to.equal(resultB);
  71. });
  72. });
  73. });