error.js 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  1. import { expect } from 'chai';
  2. import deepFreeze from 'deep-freeze';
  3. import {
  4. SHORTENER_ERROR,
  5. DOMAIN_ERROR,
  6. SET_DOMAIN,
  7. SHOW_DOMAIN_INPUT,
  8. ADD_URL,
  9. UPDATE_URL,
  10. AUTH_ERROR,
  11. AUTH_USER,
  12. HIDE_PAGE_LOADING
  13. } from '../../actions/actionTypes';
  14. import reducer from '../error';
  15. describe('error reducer', () => {
  16. const initialState = {
  17. auth: '',
  18. domain: '',
  19. shortener: '',
  20. urlOptions: ''
  21. };
  22. beforeEach(() => {
  23. deepFreeze(initialState);
  24. });
  25. it('should return the initial state', () => {
  26. expect(reducer(undefined, {})).to.deep.equal(initialState);
  27. });
  28. it('should handle SHORTENER_ERROR', () => {
  29. const error = 'SHORTENER_ERROR';
  30. const state = reducer(initialState, {
  31. type: SHORTENER_ERROR,
  32. payload: error
  33. });
  34. expect(state).not.to.be.undefined;
  35. expect(state.shortener).to.be.equal(error);
  36. });
  37. it('should handle DOMAIN_ERROR', () => {
  38. const error = 'DOMAIN_ERROR';
  39. const state = reducer(initialState, {
  40. type: DOMAIN_ERROR,
  41. payload: error
  42. });
  43. expect(state).not.to.be.undefined;
  44. expect(state.domain).to.be.equal(error);
  45. });
  46. it('should handle SET_DOMAIN', () => {
  47. const state = reducer(initialState, {
  48. type: SET_DOMAIN
  49. });
  50. expect(state).not.to.be.undefined;
  51. expect(state.domain).to.be.empty;
  52. });
  53. it('should handle SHOW_DOMAIN_INPUT', () => {
  54. const state = reducer(initialState, {
  55. type: SHOW_DOMAIN_INPUT
  56. });
  57. expect(state).not.to.be.undefined;
  58. expect(state.domain).to.be.empty;
  59. });
  60. it('should handle ADD_URL', () => {
  61. const state = reducer(initialState, {
  62. type: ADD_URL
  63. });
  64. expect(state).not.to.be.undefined;
  65. expect(state.shortener).to.be.empty;
  66. });
  67. it('should handle UPDATE_URL', () => {
  68. const state = reducer(initialState, {
  69. type: UPDATE_URL
  70. });
  71. expect(state).not.to.be.undefined;
  72. expect(state.urlOptions).to.be.empty;
  73. });
  74. it('should handle AUTH_ERROR', () => {
  75. const error = 'AUTH_ERROR';
  76. const state = reducer(initialState, {
  77. type: AUTH_ERROR,
  78. payload: error
  79. });
  80. expect(state).not.to.be.undefined;
  81. expect(state.auth).to.be.equal(error);
  82. });
  83. it('should handle AUTH_USER', () => {
  84. const state = reducer(initialState, {
  85. type: AUTH_USER
  86. });
  87. expect(state).not.to.be.undefined;
  88. expect(state.auth).to.be.empty;
  89. });
  90. it('should handle HIDE_PAGE_LOADING', () => {
  91. const state = reducer(initialState, {
  92. type: HIDE_PAGE_LOADING
  93. });
  94. expect(state).not.to.be.undefined;
  95. expect(state.auth).to.be.empty;
  96. expect(state.shortener).to.be.empty;
  97. expect(state.urlOptions).to.be.empty;
  98. });
  99. it('should not handle other action types', () => {
  100. const state = reducer(initialState, {
  101. type: 'ANOTHER_ACTION'
  102. });
  103. expect(state).not.to.be.undefined;
  104. expect(state).to.deep.equal(initialState);
  105. });
  106. });