File size: 6,510 Bytes
6bcb42f
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
describe('no-op', () => {
    test('no-op', () => {});
});
// tw: these seem to be hopelessly broken to the increasing scope of changes we make to the menu bar, disable for now...
/*
import React from 'react';
import {mount} from 'enzyme';
import configureStore from 'redux-mock-store';
import MenuBarHOC from '../../../src/containers/menu-bar-hoc.jsx';

describe('Menu Bar HOC', () => {
    const mockStore = configureStore();
    let store;

    beforeEach(() => {
        store = mockStore({
            scratchGui: {
                projectChanged: true
            }
        });
    });

    test('Logged in user who IS owner and HAS changed project will NOT be prompted to save', () => {
        const Component = () => (<div />);
        const WrappedComponent = MenuBarHOC(Component);
        const wrapper = mount(
            <WrappedComponent
                canCreateNew
                canSave
                projectChanged
                // assume the user will click "cancel" on the confirm dialog
                confirmWithMessage={() => (false)} // eslint-disable-line react/jsx-no-bind
                store={store}
            />
        );
        const child = wrapper.find(Component);
        expect(child.props().projectChanged).toBeUndefined();
        expect(child.props().confirmReadyToReplaceProject('message')).toBe(true);
    });

    test('Logged in user who IS owner and has NOT changed project will NOT be prompted to save', () => {
        const Component = () => (<div />);
        const WrappedComponent = MenuBarHOC(Component);
        const wrapper = mount(
            <WrappedComponent
                canCreateNew
                canSave
                confirmWithMessage={() => (false)} // eslint-disable-line react/jsx-no-bind
                projectChanged={false}
                store={store}
            />
        );
        const child = wrapper.find(Component);
        expect(child.props().projectChanged).toBeUndefined();
        expect(child.props().confirmReadyToReplaceProject('message')).toBe(true);
    });

    test('Logged in user who is NOT owner and HAS changed project will NOT be prompted to save', () => {
        const Component = () => (<div />);
        const WrappedComponent = MenuBarHOC(Component);
        const wrapper = mount(
            <WrappedComponent
                canCreateNew
                projectChanged
                canSave={false}
                confirmWithMessage={() => (false)} // eslint-disable-line react/jsx-no-bind
                store={store}
            />
        );
        const child = wrapper.find(Component);
        expect(child.props().projectChanged).toBeUndefined();
        expect(child.props().confirmReadyToReplaceProject('message')).toBe(true);
    });

    test('Logged OUT user who HAS changed project WILL be prompted to save', () => {
        const Component = () => (<div />);
        const WrappedComponent = MenuBarHOC(Component);
        const wrapper = mount(
            <WrappedComponent
                projectChanged
                canCreateNew={false}
                canSave={false}
                confirmWithMessage={() => (false)} // eslint-disable-line react/jsx-no-bind
                store={store}
            />
        );
        const child = wrapper.find(Component);
        expect(child.props().projectChanged).toBeUndefined();
        expect(child.props().confirmReadyToReplaceProject('message')).toBe(false);
    });

    test('Logged OUT user who has NOT changed project WILL NOT be prompted to save', () => {
        const Component = () => (<div />);
        const WrappedComponent = MenuBarHOC(Component);
        const wrapper = mount(
            <WrappedComponent
                canCreateNew={false}
                canSave={false}
                confirmWithMessage={() => (false)} // eslint-disable-line react/jsx-no-bind
                projectChanged={false}
                store={store}
            />
        );
        const child = wrapper.find(Component);
        expect(child.props().projectChanged).toBeUndefined();
        expect(child.props().confirmReadyToReplaceProject('message')).toBe(true);
    });

    test('Logged in user who IS owner and HAS changed project SHOULD save before transition to project page', () => {
        const Component = () => (<div />);
        const WrappedComponent = MenuBarHOC(Component);
        const wrapper = mount(
            <WrappedComponent
                canSave
                projectChanged
                store={store}
            />
        );
        const child = wrapper.find(Component);
        expect(child.props().projectChanged).toBeUndefined();
        expect(child.props().shouldSaveBeforeTransition()).toBe(true);
    });

    test('Logged in user who IS owner and has NOT changed project should NOT save before transition', () => {
        const Component = () => (<div />);
        const WrappedComponent = MenuBarHOC(Component);
        const wrapper = mount(
            <WrappedComponent
                canSave
                projectChanged={false}
                store={store}
            />
        );
        const child = wrapper.find(Component);
        expect(child.props().projectChanged).toBeUndefined();
        expect(child.props().shouldSaveBeforeTransition()).toBe(false);
    });

    test('Logged in user who is NOT owner and HAS changed project should NOT save before transition', () => {
        const Component = () => (<div />);
        const WrappedComponent = MenuBarHOC(Component);
        const wrapper = mount(
            <WrappedComponent
                projectChanged
                canSave={false}
                store={store}
            />
        );
        const child = wrapper.find(Component);
        expect(child.props().projectChanged).toBeUndefined();
        expect(child.props().shouldSaveBeforeTransition()).toBe(false);
    });

    test('Logged in user who is NOT owner and has NOT changed project should NOT save before transition', () => {
        const Component = () => (<div />);
        const WrappedComponent = MenuBarHOC(Component);
        const wrapper = mount(
            <WrappedComponent
                canSave={false}
                projectChanged={false}
                store={store}
            />
        );
        const child = wrapper.find(Component);
        expect(child.props().projectChanged).toBeUndefined();
        expect(child.props().shouldSaveBeforeTransition()).toBe(false);
    });

});
*/