11import React from 'react' ;
22import { Provider } from 'react-redux' ;
3+ import { mount , shallow } from 'enzyme' ;
4+
35import { mountWithIntl , shallowWithIntl , componentWithIntl } from '../../helpers/intl-helpers.jsx' ;
46import configureStore from 'redux-mock-store' ;
57import SBFileUploader from '../../../src/containers/sb-file-uploader' ;
@@ -17,19 +19,17 @@ describe('SBFileUploader Container', () => {
1719 // Wrap this in a function so it gets test specific states and can be reused.
1820 const getContainer = function ( ) {
1921 return (
20- < Provider store = { store } >
21- < SBFileUploader
22- onLoadingFinished = { onLoadingFinished }
23- onLoadingStarted = { onLoadingStarted }
24- onUpdateProjectTitle = { onUpdateProjectTitle }
25- >
26- { ( renderFileInput , loadProject ) => (
27- < div
28- onClick = { loadProject }
29- />
30- ) }
31- </ SBFileUploader >
32- </ Provider >
22+ < SBFileUploader
23+ onLoadingFinished = { onLoadingFinished }
24+ onLoadingStarted = { onLoadingStarted }
25+ onUpdateProjectTitle = { onUpdateProjectTitle }
26+ >
27+ { ( renderFileInput , loadProject ) => (
28+ < div
29+ onClick = { loadProject }
30+ />
31+ ) }
32+ </ SBFileUploader >
3333 ) ;
3434 } ;
3535
@@ -48,28 +48,42 @@ describe('SBFileUploader Container', () => {
4848 } ) ;
4949
5050 test ( 'correctly sets title with .sb3 filename' , ( ) => {
51- const wrapper = mountWithIntl ( getContainer ( ) ) ;
52- const instance = wrapper . find ( SBFileUploader ) . component ( ) ;
53- expect ( instance ) . toBe ( true ) ;
51+ const wrapper = shallowWithIntl ( getContainer ( ) , { context : { store} } ) ;
52+ const instance = wrapper
53+ . dive ( ) // unwrap redux Connect(InjectIntl(SBFileUploader))
54+ . dive ( ) // unwrap InjectIntl(SBFileUploader)
55+ . instance ( ) ; // SBFileUploader
5456 const projectName = instance . getProjectTitleFromFilename ( 'my project is great.sb3' ) ;
5557 expect ( projectName ) . toBe ( 'my project is great' ) ;
5658 } ) ;
5759
58- // test('correctly sets title with .sb3 filename', () => {
59- // const component = componentWithIntl(getContainer());
60- // const projectName = component.getProjectTitleFromFilename('my project is great.sb3');
61- // expect(projectName).toBe('my project is great');
62- // });
63- //
64- // test('sets blank title with .sb filename', () => {
65- // const component = componentWithIntl(getContainer());
66- // const projectName = component.getProjectTitleFromFilename('my project is great.sb');
67- // expect(projectName).toBe('');
68- // });
69- //
70- // test('sets blank title with filename with no extension', () => {
71- // const component = componentWithIntl(getContainer());
72- // const projectName = component.getProjectTitleFromFilename('my project is great');
73- // expect(projectName).toBe('');
74- // });
60+ test ( 'correctly sets title with .sb2 filename' , ( ) => {
61+ const wrapper = shallowWithIntl ( getContainer ( ) , { context : { store} } ) ;
62+ const instance = wrapper
63+ . dive ( ) // unwrap redux Connect(InjectIntl(SBFileUploader))
64+ . dive ( ) // unwrap InjectIntl(SBFileUploader)
65+ . instance ( ) ; // SBFileUploader
66+ const projectName = instance . getProjectTitleFromFilename ( 'my project is great.sb2' ) ;
67+ expect ( projectName ) . toBe ( 'my project is great' ) ;
68+ } ) ;
69+
70+ test ( 'sets blank title with .sb filename' , ( ) => {
71+ const wrapper = shallowWithIntl ( getContainer ( ) , { context : { store} } ) ;
72+ const instance = wrapper
73+ . dive ( ) // unwrap redux Connect(InjectIntl(SBFileUploader))
74+ . dive ( ) // unwrap InjectIntl(SBFileUploader)
75+ . instance ( ) ; // SBFileUploader
76+ const projectName = instance . getProjectTitleFromFilename ( 'my project is great.sb' ) ;
77+ expect ( projectName ) . toBe ( '' ) ;
78+ } ) ;
79+
80+ test ( 'sets blank title with filename with no extension' , ( ) => {
81+ const wrapper = shallowWithIntl ( getContainer ( ) , { context : { store} } ) ;
82+ const instance = wrapper
83+ . dive ( ) // unwrap redux Connect(InjectIntl(SBFileUploader))
84+ . dive ( ) // unwrap InjectIntl(SBFileUploader)
85+ . instance ( ) ; // SBFileUploader
86+ const projectName = instance . getProjectTitleFromFilename ( 'my project is great' ) ;
87+ expect ( projectName ) . toBe ( '' ) ;
88+ } ) ;
7589} ) ;
0 commit comments