save-status.test.jsx 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. import React from 'react';
  2. import {Provider} from 'react-redux';
  3. import configureStore from 'redux-mock-store';
  4. import {mountWithIntl} from '../../helpers/intl-helpers.jsx';
  5. import SaveStatus from '../../../src/components/menu-bar/save-status.jsx';
  6. import InlineMessages from '../../../src/containers/inline-messages.jsx';
  7. import {AlertTypes} from '../../../src/lib/alerts/index.jsx';
  8. // Stub the manualUpdateProject action creator for later testing
  9. jest.mock('../../../src/reducers/project-state', () => ({
  10. manualUpdateProject: jest.fn(() => ({type: 'stubbed'}))
  11. }));
  12. describe('SaveStatus container', () => {
  13. const mockStore = configureStore();
  14. test('if there are inline messages, they are shown instead of save now', () => {
  15. const store = mockStore({
  16. scratchGui: {
  17. projectChanged: true,
  18. alerts: {
  19. alertsList: [
  20. {alertId: 'saveSuccess', alertType: AlertTypes.INLINE}
  21. ]
  22. }
  23. }
  24. });
  25. const wrapper = mountWithIntl(
  26. <Provider store={store}>
  27. <SaveStatus />
  28. </Provider>
  29. );
  30. expect(wrapper.find(InlineMessages).exists()).toBe(true);
  31. expect(wrapper.contains('Save Now')).not.toBe(true);
  32. });
  33. test('save now is shown if there are project changes and no inline messages', () => {
  34. const store = mockStore({
  35. scratchGui: {
  36. projectChanged: true,
  37. alerts: {
  38. alertsList: []
  39. }
  40. }
  41. });
  42. const wrapper = mountWithIntl(
  43. <Provider store={store}>
  44. <SaveStatus />
  45. </Provider>
  46. );
  47. expect(wrapper.find(InlineMessages).exists()).not.toBe(true);
  48. expect(wrapper.contains('Save Now')).toBe(true);
  49. // Clicking save now should dispatch the manualUpdateProject action (stubbed above)
  50. wrapper.find('[children="Save Now"]').simulate('click');
  51. expect(store.getActions()[0].type).toEqual('stubbed');
  52. });
  53. test('neither is shown if there are no project changes or inline messages', () => {
  54. const store = mockStore({
  55. scratchGui: {
  56. projectChanged: false,
  57. alerts: {
  58. alertsList: []
  59. }
  60. }
  61. });
  62. const wrapper = mountWithIntl(
  63. <Provider store={store}>
  64. <SaveStatus />
  65. </Provider>
  66. );
  67. expect(wrapper.find(InlineMessages).exists()).not.toBe(true);
  68. expect(wrapper.contains('Save Now')).not.toBe(true);
  69. });
  70. });