|
| 1 | +import React from 'react'; |
| 2 | +import {Provider} from 'react-redux'; |
| 3 | +import {mountWithIntl, shallowWithIntl, componentWithIntl} from '../../helpers/intl-helpers.jsx'; |
| 4 | +import configureStore from 'redux-mock-store'; |
| 5 | +import SBFileUploader from '../../../src/containers/sb-file-uploader.jsx'; |
| 6 | + |
| 7 | +describe('SBFileUploader', () => { |
| 8 | + const mockStore = configureStore(); |
| 9 | + let onLoadingFinished; |
| 10 | + let onLoadingStarted; |
| 11 | + let onUpdateProjectTitle; |
| 12 | + let store; |
| 13 | + |
| 14 | + // Wrap this in a function so it gets test specific states and can be reused. |
| 15 | + const getContainer = function () { |
| 16 | + return ( |
| 17 | + <SBFileUploader |
| 18 | + store={store} |
| 19 | + onLoadingFinished={onLoadingFinished} |
| 20 | + onLoadingStarted={onLoadingStarted} |
| 21 | + onUpdateProjectTitle={onUpdateProjectTitle} |
| 22 | + > |
| 23 | + {(renderFileInput, loadProject) => ( |
| 24 | + <div |
| 25 | + onClick={loadProject} |
| 26 | + /> |
| 27 | + )} |
| 28 | + </SBFileUploader> |
| 29 | + ); |
| 30 | + }; |
| 31 | + |
| 32 | + beforeEach(() => { |
| 33 | + store = mockStore({ |
| 34 | + scratchGui: { |
| 35 | + projectState: {} |
| 36 | + } |
| 37 | + }); |
| 38 | + onUpdateProjectTitle = jest.fn(); |
| 39 | + onLoadingFinished = jest.fn(); |
| 40 | + onLoadingStarted = jest.fn(); |
| 41 | + }); |
| 42 | + |
| 43 | + test('correctly sets title with .sb3 filename', () => { |
| 44 | + const component = mountWithIntl(getContainer()); |
| 45 | + const instance = component.instance(); |
| 46 | + const projectName = instance.getProjectTitleFromFilename('my project is great.sb3'); |
| 47 | + expect(projectName).toBe('my project is great'); |
| 48 | + }); |
| 49 | + |
| 50 | + test('correctly sets title with .sb3 filename', () => { |
| 51 | + const component = componentWithIntl(getContainer()); |
| 52 | + const projectName = component.getProjectTitleFromFilename('my project is great.sb3'); |
| 53 | + expect(projectName).toBe('my project is great'); |
| 54 | + }); |
| 55 | + |
| 56 | + test('sets blank title with .sb filename', () => { |
| 57 | + const component = componentWithIntl(getContainer()); |
| 58 | + const projectName = component.getProjectTitleFromFilename('my project is great.sb'); |
| 59 | + expect(projectName).toBe(''); |
| 60 | + }); |
| 61 | + |
| 62 | + test('sets blank title with filename with no extension', () => { |
| 63 | + const component = componentWithIntl(getContainer()); |
| 64 | + const projectName = component.getProjectTitleFromFilename('my project is great'); |
| 65 | + expect(projectName).toBe(''); |
| 66 | + }); |
| 67 | +}); |
0 commit comments