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