Guest User

Untitled

a guest
Mar 5th, 2018
267
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.07 KB | None | 0 0
  1. describe('sign up form reducer', () => {
  2. test('should reduce submitted action', () => {
  3. const actualState = reducer({}, submitted());
  4. expect(actualState.submitted).toBe(true);
  5. });
  6. test('should reduce inputChange action', () => {
  7. const actualState = reducer({}, inputChange('username', 'foo'));
  8. expect(actualState.inputs.username).toBe('foo');
  9. });
  10. test('should set submitted to false when inputChange action is reduced', () => {
  11. const actualState = reducer({ submitted: true }, inputChange('username', 'foo'));
  12. expect(actualState.submitted).toBe(false);
  13. });
  14. test('should reduce validateInputs action and set isValid to false if there are errors', () => {
  15. const state = {
  16. ...defaultState,
  17. inputs: {
  18. username: '',
  19. email: '',
  20. password: '',
  21. passwordConfirmation: '',
  22. },
  23. isValid: true,
  24. };
  25. const actualState = reducer(state, validateInputs());
  26. expect(actualState.errors).toEqual({
  27. username: MISSING_FIELD,
  28. email: MISSING_FIELD,
  29. password: MISSING_FIELD,
  30. passwordConfirmation: MISSING_FIELD,
  31. });
  32. expect(actualState.isValid).toBe(false);
  33. });
  34. test('should reduce validateInputs action and set isValid to true if there is no error', () => {
  35. const state = {
  36. ...defaultState,
  37. inputs: {
  38. username: 'foo',
  39. email: 'foo@example.com',
  40. password: 'password',
  41. passwordConfirmation: 'password',
  42. },
  43. };
  44. const actualState = reducer(state, validateInputs());
  45. expect(actualState.errors).toEqual({});
  46. expect(actualState.isValid).toBe(true);
  47. });
  48. test('should remove error when the erroneous field has changed', () => {
  49. const state = {
  50. ...defaultState,
  51. inputs: {
  52. username: '',
  53. email: '',
  54. password: '',
  55. passwordConfirmation: '',
  56. },
  57. };
  58. const actualState = reducer(state, validateInputs());
  59. const stateAfterInputChanged = reducer(actualState, inputChange('username', 'foo'));
  60. expect(Object.keys(stateAfterInputChanged.errors).indexOf('username')).toBe(-1);
  61. });
  62. });
Add Comment
Please, Sign In to add comment