loading.js 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211
  1. import { expect } from 'chai';
  2. import deepFreeze from 'deep-freeze';
  3. import {
  4. SHOW_PAGE_LOADING,
  5. HIDE_PAGE_LOADING,
  6. TABLE_LOADING,
  7. LOGIN_LOADING,
  8. SIGNUP_LOADING,
  9. SHORTENER_LOADING,
  10. ADD_URL,
  11. SHORTENER_ERROR,
  12. LIST_URLS,
  13. DELETE_URL,
  14. AUTH_ERROR,
  15. AUTH_USER,
  16. DOMAIN_LOADING,
  17. SET_DOMAIN,
  18. DOMAIN_ERROR,
  19. API_LOADING,
  20. SET_APIKEY
  21. } from '../../actions/actionTypes';
  22. import reducer from '../loading';
  23. describe('loading reducer', () => {
  24. const initialState = {
  25. api: false,
  26. domain: false,
  27. shortener: false,
  28. login: false,
  29. page: false,
  30. table: false,
  31. signup: false
  32. };
  33. beforeEach(() => {
  34. deepFreeze(initialState);
  35. });
  36. it('should return the initial state', () => {
  37. expect(reducer(undefined, {})).to.deep.equal(initialState);
  38. });
  39. it('should handle SHOW_PAGE_LOADING', () => {
  40. const state = reducer(initialState, {
  41. type: SHOW_PAGE_LOADING
  42. });
  43. expect(state).not.to.be.undefined;
  44. expect(state.page).to.be.true;
  45. });
  46. it('should handle HIDE_PAGE_LOADING', () => {
  47. const state = reducer(initialState, {
  48. type: HIDE_PAGE_LOADING
  49. });
  50. expect(state).not.to.be.undefined;
  51. expect(state.shortener).to.be.false;
  52. expect(state.login).to.be.false;
  53. expect(state.page).to.be.false;
  54. expect(state.signup).to.be.false;
  55. });
  56. it('should handle TABLE_LOADING', () => {
  57. const state = reducer(initialState, {
  58. type: TABLE_LOADING
  59. });
  60. expect(state).not.to.be.undefined;
  61. expect(state.table).to.be.true;
  62. });
  63. it('should handle LOGIN_LOADING', () => {
  64. const state = reducer(initialState, {
  65. type: LOGIN_LOADING
  66. });
  67. expect(state).not.to.be.undefined;
  68. expect(state.login).to.be.true;
  69. });
  70. it('should handle SIGNUP_LOADING', () => {
  71. const state = reducer(initialState, {
  72. type: SIGNUP_LOADING
  73. });
  74. expect(state).not.to.be.undefined;
  75. expect(state.signup).to.be.true;
  76. });
  77. it('should handle SHORTENER_LOADING', () => {
  78. const state = reducer(initialState, {
  79. type: SHORTENER_LOADING
  80. });
  81. expect(state).not.to.be.undefined;
  82. expect(state.shortener).to.be.true;
  83. });
  84. it('should handle ADD_URL', () => {
  85. const state = reducer(initialState, {
  86. type: ADD_URL
  87. });
  88. expect(state).not.to.be.undefined;
  89. expect(state.shortener).to.be.false;
  90. });
  91. it('should handle SHORTENER_ERROR', () => {
  92. const state = reducer(initialState, {
  93. type: SHORTENER_ERROR
  94. });
  95. expect(state).not.to.be.undefined;
  96. expect(state.shortener).to.be.false;
  97. });
  98. it('should handle LIST_URLS', () => {
  99. const state = reducer(initialState, {
  100. type: LIST_URLS
  101. });
  102. expect(state).not.to.be.undefined;
  103. expect(state.table).to.be.false;
  104. });
  105. it('should handle DELETE_URL', () => {
  106. const state = reducer(initialState, {
  107. type: DELETE_URL
  108. });
  109. expect(state).not.to.be.undefined;
  110. expect(state.table).to.be.false;
  111. });
  112. it('should handle AUTH_ERROR', () => {
  113. const state = reducer(initialState, {
  114. type: AUTH_ERROR
  115. });
  116. expect(state).not.to.be.undefined;
  117. expect(state.login).to.be.false;
  118. expect(state.signup).to.be.false;
  119. });
  120. it('should handle AUTH_USER', () => {
  121. const state = reducer(initialState, {
  122. type: AUTH_USER
  123. });
  124. expect(state).not.to.be.undefined;
  125. expect(state.login).to.be.false;
  126. expect(state.signup).to.be.false;
  127. });
  128. it('should handle DOMAIN_LOADING', () => {
  129. const state = reducer(initialState, {
  130. type: DOMAIN_LOADING
  131. });
  132. expect(state).not.to.be.undefined;
  133. expect(state.domain).to.be.true;
  134. });
  135. it('should handle SET_DOMAIN', () => {
  136. const state = reducer(initialState, {
  137. type: SET_DOMAIN
  138. });
  139. expect(state).not.to.be.undefined;
  140. expect(state.domain).to.be.false;
  141. });
  142. it('should handle DOMAIN_ERROR', () => {
  143. const state = reducer(initialState, {
  144. type: DOMAIN_ERROR
  145. });
  146. expect(state).not.to.be.undefined;
  147. expect(state.domain).to.be.false;
  148. });
  149. it('should handle API_LOADING', () => {
  150. const state = reducer(initialState, {
  151. type: API_LOADING
  152. });
  153. expect(state).not.to.be.undefined;
  154. expect(state.api).to.be.true;
  155. });
  156. it('should handle SET_APIKEY', () => {
  157. const state = reducer(initialState, {
  158. type: SET_APIKEY
  159. });
  160. expect(state).not.to.be.undefined;
  161. expect(state.api).to.be.false;
  162. });
  163. it('should not handle other action types', () => {
  164. const state = reducer(initialState, {
  165. type: 'ANOTHER_ACTION'
  166. });
  167. expect(state).not.to.be.undefined;
  168. expect(state).to.deep.equal(initialState);
  169. });
  170. });