settings.js 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  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. useHttps: false,
  18. };
  19. beforeEach(() => {
  20. deepFreeze(initialState);
  21. });
  22. it('should return the initial state', () => {
  23. expect(reducer(undefined, {})).to.deep.equal(initialState);
  24. });
  25. it('should handle SET_DOMAIN', () => {
  26. const customDomain = 'example.com';
  27. const homepage = '';
  28. const state = reducer(initialState, {
  29. type: SET_DOMAIN,
  30. payload: { customDomain, homepage }
  31. });
  32. expect(state).not.to.be.undefined;
  33. expect(state.customDomain).to.be.equal(customDomain);
  34. expect(state.domainInput).to.be.false;
  35. });
  36. it('should handle SET_APIKEY', () => {
  37. const apikey = '1234567';
  38. const state = reducer(initialState, {
  39. type: SET_APIKEY,
  40. payload: apikey
  41. });
  42. expect(state).not.to.be.undefined;
  43. expect(state.apikey).to.be.equal(apikey);
  44. });
  45. it('should handle DELETE_DOMAIN', () => {
  46. const state = reducer(initialState, {
  47. type: DELETE_DOMAIN
  48. });
  49. expect(state).not.to.be.undefined;
  50. expect(state.customDomain).to.be.empty;
  51. expect(state.domainInput).to.be.true;
  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.domainInput).to.be.true;
  59. });
  60. it('should handle UNAUTH_USER', () => {
  61. const state = reducer(initialState, {
  62. type: UNAUTH_USER
  63. });
  64. expect(state).not.to.be.undefined;
  65. expect(state).to.deep.equal(initialState);
  66. });
  67. it('should not handle other action types', () => {
  68. const state = reducer(initialState, {
  69. type: 'ANOTHER_ACTION'
  70. });
  71. expect(state).not.to.be.undefined;
  72. expect(state).to.deep.equal(initialState);
  73. });
  74. });