menu-bar-hoc.test.jsx 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164
  1. import React from 'react';
  2. import {mount} from 'enzyme';
  3. import configureStore from 'redux-mock-store';
  4. import MenuBarHOC from '../../../src/containers/menu-bar-hoc.jsx';
  5. describe('Menu Bar HOC', () => {
  6. const mockStore = configureStore();
  7. let store;
  8. beforeEach(() => {
  9. store = mockStore({
  10. scratchGui: {
  11. projectChanged: true
  12. }
  13. });
  14. });
  15. test('Logged in user who IS owner and HAS changed project will NOT be prompted to save', () => {
  16. const Component = () => (<div />);
  17. const WrappedComponent = MenuBarHOC(Component);
  18. const wrapper = mount(
  19. <WrappedComponent
  20. canCreateNew
  21. canSave
  22. projectChanged
  23. // assume the user will click "cancel" on the confirm dialog
  24. confirmWithMessage={() => (false)} // eslint-disable-line react/jsx-no-bind
  25. store={store}
  26. />
  27. );
  28. const child = wrapper.find(Component);
  29. expect(child.props().projectChanged).toBeUndefined();
  30. expect(child.props().confirmReadyToReplaceProject('message')).toBe(true);
  31. });
  32. test('Logged in user who IS owner and has NOT changed project will NOT be prompted to save', () => {
  33. const Component = () => (<div />);
  34. const WrappedComponent = MenuBarHOC(Component);
  35. const wrapper = mount(
  36. <WrappedComponent
  37. canCreateNew
  38. canSave
  39. confirmWithMessage={() => (false)} // eslint-disable-line react/jsx-no-bind
  40. projectChanged={false}
  41. store={store}
  42. />
  43. );
  44. const child = wrapper.find(Component);
  45. expect(child.props().projectChanged).toBeUndefined();
  46. expect(child.props().confirmReadyToReplaceProject('message')).toBe(true);
  47. });
  48. test('Logged in user who is NOT owner and HAS changed project will NOT be prompted to save', () => {
  49. const Component = () => (<div />);
  50. const WrappedComponent = MenuBarHOC(Component);
  51. const wrapper = mount(
  52. <WrappedComponent
  53. canCreateNew
  54. projectChanged
  55. canSave={false}
  56. confirmWithMessage={() => (false)} // eslint-disable-line react/jsx-no-bind
  57. store={store}
  58. />
  59. );
  60. const child = wrapper.find(Component);
  61. expect(child.props().projectChanged).toBeUndefined();
  62. expect(child.props().confirmReadyToReplaceProject('message')).toBe(true);
  63. });
  64. test('Logged OUT user who HAS changed project WILL be prompted to save', () => {
  65. const Component = () => (<div />);
  66. const WrappedComponent = MenuBarHOC(Component);
  67. const wrapper = mount(
  68. <WrappedComponent
  69. projectChanged
  70. canCreateNew={false}
  71. canSave={false}
  72. confirmWithMessage={() => (false)} // eslint-disable-line react/jsx-no-bind
  73. store={store}
  74. />
  75. );
  76. const child = wrapper.find(Component);
  77. expect(child.props().projectChanged).toBeUndefined();
  78. expect(child.props().confirmReadyToReplaceProject('message')).toBe(false);
  79. });
  80. test('Logged OUT user who has NOT changed project WILL NOT be prompted to save', () => {
  81. const Component = () => (<div />);
  82. const WrappedComponent = MenuBarHOC(Component);
  83. const wrapper = mount(
  84. <WrappedComponent
  85. canCreateNew={false}
  86. canSave={false}
  87. confirmWithMessage={() => (false)} // eslint-disable-line react/jsx-no-bind
  88. projectChanged={false}
  89. store={store}
  90. />
  91. );
  92. const child = wrapper.find(Component);
  93. expect(child.props().projectChanged).toBeUndefined();
  94. expect(child.props().confirmReadyToReplaceProject('message')).toBe(true);
  95. });
  96. test('Logged in user who IS owner and HAS changed project SHOULD save before transition to project page', () => {
  97. const Component = () => (<div />);
  98. const WrappedComponent = MenuBarHOC(Component);
  99. const wrapper = mount(
  100. <WrappedComponent
  101. canSave
  102. projectChanged
  103. store={store}
  104. />
  105. );
  106. const child = wrapper.find(Component);
  107. expect(child.props().projectChanged).toBeUndefined();
  108. expect(child.props().shouldSaveBeforeTransition()).toBe(true);
  109. });
  110. test('Logged in user who IS owner and has NOT changed project should NOT save before transition', () => {
  111. const Component = () => (<div />);
  112. const WrappedComponent = MenuBarHOC(Component);
  113. const wrapper = mount(
  114. <WrappedComponent
  115. canSave
  116. projectChanged={false}
  117. store={store}
  118. />
  119. );
  120. const child = wrapper.find(Component);
  121. expect(child.props().projectChanged).toBeUndefined();
  122. expect(child.props().shouldSaveBeforeTransition()).toBe(false);
  123. });
  124. test('Logged in user who is NOT owner and HAS changed project should NOT save before transition', () => {
  125. const Component = () => (<div />);
  126. const WrappedComponent = MenuBarHOC(Component);
  127. const wrapper = mount(
  128. <WrappedComponent
  129. projectChanged
  130. canSave={false}
  131. store={store}
  132. />
  133. );
  134. const child = wrapper.find(Component);
  135. expect(child.props().projectChanged).toBeUndefined();
  136. expect(child.props().shouldSaveBeforeTransition()).toBe(false);
  137. });
  138. test('Logged in user who is NOT owner and has NOT changed project should NOT save before transition', () => {
  139. const Component = () => (<div />);
  140. const WrappedComponent = MenuBarHOC(Component);
  141. const wrapper = mount(
  142. <WrappedComponent
  143. canSave={false}
  144. projectChanged={false}
  145. store={store}
  146. />
  147. );
  148. const child = wrapper.find(Component);
  149. expect(child.props().projectChanged).toBeUndefined();
  150. expect(child.props().shouldSaveBeforeTransition()).toBe(false);
  151. });
  152. });