settings.js 2.0 KB

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