| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990 |
- 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: '<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);
- });
- });
- });
|