|
|
@@ -0,0 +1,53 @@
|
|
|
+import { expect } from 'chai';
|
|
|
+
|
|
|
+import {
|
|
|
+ getDocs
|
|
|
+} from 'selectors/crud';
|
|
|
+
|
|
|
+describe('CRUD selectors', () => {
|
|
|
+ describe('getDocs', () => {
|
|
|
+ const route = 'employees';
|
|
|
+
|
|
|
+ it('should return the list of docs', () => {
|
|
|
+ const state = {
|
|
|
+ crud: {
|
|
|
+ [route]: {
|
|
|
+ items: [
|
|
|
+ {
|
|
|
+ id: '<actualId>',
|
|
|
+ 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);
|
|
|
+ });
|
|
|
+ });
|
|
|
+});
|
|
|
+
|