Spaces:
Running
Running
File size: 2,692 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 |
import React from 'react';
import {Provider} from 'react-redux';
import configureStore from 'redux-mock-store';
import {mountWithIntl} from '../../helpers/intl-helpers.jsx';
import SaveStatus from '../../../src/components/menu-bar/save-status.jsx';
import InlineMessages from '../../../src/containers/inline-messages.jsx';
import {AlertTypes} from '../../../src/lib/alerts/index.jsx';
// Stub the manualUpdateProject action creator for later testing
jest.mock('../../../src/reducers/project-state', () => ({
manualUpdateProject: jest.fn(() => ({type: 'stubbed'}))
}));
describe('SaveStatus container', () => {
const mockStore = configureStore();
test('if there are inline messages, they are shown instead of save now', () => {
const store = mockStore({
scratchGui: {
projectChanged: true,
alerts: {
alertsList: [
{alertId: 'saveSuccess', alertType: AlertTypes.INLINE}
]
}
}
});
const wrapper = mountWithIntl(
<Provider store={store}>
<SaveStatus />
</Provider>
);
expect(wrapper.find(InlineMessages).exists()).toBe(true);
expect(wrapper.contains('Save Now')).not.toBe(true);
});
test('save now is shown if there are project changes and no inline messages', () => {
const store = mockStore({
scratchGui: {
projectChanged: true,
alerts: {
alertsList: []
}
}
});
const wrapper = mountWithIntl(
<Provider store={store}>
<SaveStatus />
</Provider>
);
expect(wrapper.find(InlineMessages).exists()).not.toBe(true);
expect(wrapper.contains('Save Now')).toBe(true);
// Clicking save now should dispatch the manualUpdateProject action (stubbed above)
wrapper.find('[children="Save Now"]').simulate('click');
expect(store.getActions()[0].type).toEqual('stubbed');
});
test('neither is shown if there are no project changes or inline messages', () => {
const store = mockStore({
scratchGui: {
projectChanged: false,
alerts: {
alertsList: []
}
}
});
const wrapper = mountWithIntl(
<Provider store={store}>
<SaveStatus />
</Provider>
);
expect(wrapper.find(InlineMessages).exists()).not.toBe(true);
expect(wrapper.contains('Save Now')).not.toBe(true);
});
});
|