|
| 1 | +import React from 'react'; |
| 2 | +import {mountWithIntl} from '../../helpers/intl-helpers'; |
| 3 | +import MenuBar from '../../../src/components/menu-bar/menu-bar'; |
| 4 | +import {menuInitialState} from '../../../src/reducers/menus'; |
| 5 | +import {LoadingState} from '../../../src/reducers/project-state'; |
| 6 | + |
| 7 | +import configureStore from 'redux-mock-store'; |
| 8 | +import {Provider} from 'react-redux'; |
| 9 | +import VM from 'scratch-vm'; |
| 10 | + |
| 11 | + |
| 12 | +describe('MenuBar Component', () => { |
| 13 | + const store = configureStore()({ |
| 14 | + locales: { |
| 15 | + isRtl: false, |
| 16 | + locale: 'en-US' |
| 17 | + }, |
| 18 | + scratchGui: { |
| 19 | + menus: menuInitialState, |
| 20 | + projectState: { |
| 21 | + loadingState: LoadingState.NOT_LOADED |
| 22 | + }, |
| 23 | + vm: new VM() |
| 24 | + } |
| 25 | + }); |
| 26 | + |
| 27 | + const getComponent = function (props = {}) { |
| 28 | + return <Provider store={store}><MenuBar {...props} /></Provider>; |
| 29 | + }; |
| 30 | + |
| 31 | + test('menu bar with no About handler has no About button', () => { |
| 32 | + const menuBar = mountWithIntl(getComponent()); |
| 33 | + const button = menuBar.find('AboutButton'); |
| 34 | + expect(button.exists()).toBe(false); |
| 35 | + }); |
| 36 | + |
| 37 | + test('menu bar with an About handler has an About button', () => { |
| 38 | + const onClickAbout = jest.fn(); |
| 39 | + const menuBar = mountWithIntl(getComponent({onClickAbout})); |
| 40 | + const button = menuBar.find('AboutButton'); |
| 41 | + expect(button.exists()).toBe(true); |
| 42 | + }); |
| 43 | + |
| 44 | + test('clicking on About button calls the handler', () => { |
| 45 | + const onClickAbout = jest.fn(); |
| 46 | + const menuBar = mountWithIntl(getComponent({onClickAbout})); |
| 47 | + const button = menuBar.find('AboutButton'); |
| 48 | + expect(onClickAbout).toHaveBeenCalledTimes(0); |
| 49 | + button.simulate('click'); |
| 50 | + expect(onClickAbout).toHaveBeenCalledTimes(1); |
| 51 | + }); |
| 52 | +}); |
0 commit comments