settings.js 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. import { expect } from 'chai';
  2. import deepFreeze from 'deep-freeze';
  3. import {
  4. SET_DOMAIN,
  5. SET_APIKEY,
  6. DELETE_DOMAIN,
  7. SHOW_DOMAIN_INPUT,
  8. UNAUTH_USER
  9. } from '../../actions/actionTypes';
  10. import reducer from '../settings';
  11. describe('settings reducer', () => {
  12. const initialState = {
  13. apikey: '',
  14. customDomain: '',
  15. homepage: '',
  16. domainInput: true,
  17. };
  18. beforeEach(() => {
  19. deepFreeze(initialState);
  20. });
  21. it('should return the initial state', () => {
  22. expect(reducer(undefined, {})).to.deep.equal(initialState);
  23. });
  24. it('should handle SET_DOMAIN', () => {
  25. const customDomain = 'example.com';
  26. const homepage = '';
  27. const state = reducer(initialState, {
  28. type: SET_DOMAIN,
  29. payload: { customDomain, homepage }
  30. });
  31. expect(state).not.to.be.undefined;
  32. expect(state.customDomain).to.be.equal(customDomain);
  33. expect(state.domainInput).to.be.false;
  34. });
  35. it('should handle SET_APIKEY', () => {
  36. const apikey = '1234567';
  37. const state = reducer(initialState, {
  38. type: SET_APIKEY,
  39. payload: apikey
  40. });
  41. expect(state).not.to.be.undefined;
  42. expect(state.apikey).to.be.equal(apikey);
  43. });
  44. it('should handle DELETE_DOMAIN', () => {
  45. const state = reducer(initialState, {
  46. type: DELETE_DOMAIN
  47. });
  48. expect(state).not.to.be.undefined;
  49. expect(state.customDomain).to.be.empty;
  50. expect(state.domainInput).to.be.true;
  51. });
  52. it('should handle SHOW_DOMAIN_INPUT', () => {
  53. const state = reducer(initialState, {
  54. type: SHOW_DOMAIN_INPUT
  55. });
  56. expect(state).not.to.be.undefined;
  57. expect(state.domainInput).to.be.true;
  58. });
  59. it('should handle UNAUTH_USER', () => {
  60. const state = reducer(initialState, {
  61. type: UNAUTH_USER
  62. });
  63. expect(state).not.to.be.undefined;
  64. expect(state).to.deep.equal(initialState);
  65. });
  66. it('should not handle other action types', () => {
  67. const state = reducer(initialState, {
  68. type: 'ANOTHER_ACTION'
  69. });
  70. expect(state).not.to.be.undefined;
  71. expect(state).to.deep.equal(initialState);
  72. });
  73. });