Skip to content
Snippets Groups Projects
Commit 76e11e0e authored by Ben Wheeler's avatar Ben Wheeler
Browse files

got sb-file-uploader tests working

parent bde0f7aa
No related branches found
No related tags found
No related merge requests found
import React from 'react'; import React from 'react';
import {Provider} from 'react-redux'; import {Provider} from 'react-redux';
import {mount, shallow} from 'enzyme';
import {mountWithIntl, shallowWithIntl, componentWithIntl} from '../../helpers/intl-helpers.jsx'; import {mountWithIntl, shallowWithIntl, componentWithIntl} from '../../helpers/intl-helpers.jsx';
import configureStore from 'redux-mock-store'; import configureStore from 'redux-mock-store';
import SBFileUploader from '../../../src/containers/sb-file-uploader'; import SBFileUploader from '../../../src/containers/sb-file-uploader';
...@@ -17,19 +19,17 @@ describe('SBFileUploader Container', () => { ...@@ -17,19 +19,17 @@ describe('SBFileUploader Container', () => {
// Wrap this in a function so it gets test specific states and can be reused. // Wrap this in a function so it gets test specific states and can be reused.
const getContainer = function () { const getContainer = function () {
return ( return (
<Provider store={store}> <SBFileUploader
<SBFileUploader onLoadingFinished={onLoadingFinished}
onLoadingFinished={onLoadingFinished} onLoadingStarted={onLoadingStarted}
onLoadingStarted={onLoadingStarted} onUpdateProjectTitle={onUpdateProjectTitle}
onUpdateProjectTitle={onUpdateProjectTitle} >
> {(renderFileInput, loadProject) => (
{(renderFileInput, loadProject) => ( <div
<div onClick={loadProject}
onClick={loadProject} />
/> )}
)} </SBFileUploader>
</SBFileUploader>
</Provider>
); );
}; };
...@@ -48,28 +48,42 @@ describe('SBFileUploader Container', () => { ...@@ -48,28 +48,42 @@ describe('SBFileUploader Container', () => {
}); });
test('correctly sets title with .sb3 filename', () => { test('correctly sets title with .sb3 filename', () => {
const wrapper = mountWithIntl(getContainer()); const wrapper = shallowWithIntl(getContainer(), {context: {store}});
const instance = wrapper.find(SBFileUploader).component(); const instance = wrapper
expect(instance).toBe(true); .dive() // unwrap redux Connect(InjectIntl(SBFileUploader))
.dive() // unwrap InjectIntl(SBFileUploader)
.instance(); // SBFileUploader
const projectName = instance.getProjectTitleFromFilename('my project is great.sb3'); const projectName = instance.getProjectTitleFromFilename('my project is great.sb3');
expect(projectName).toBe('my project is great'); expect(projectName).toBe('my project is great');
}); });
// test('correctly sets title with .sb3 filename', () => { test('correctly sets title with .sb2 filename', () => {
// const component = componentWithIntl(getContainer()); const wrapper = shallowWithIntl(getContainer(), {context: {store}});
// const projectName = component.getProjectTitleFromFilename('my project is great.sb3'); const instance = wrapper
// expect(projectName).toBe('my project is great'); .dive() // unwrap redux Connect(InjectIntl(SBFileUploader))
// }); .dive() // unwrap InjectIntl(SBFileUploader)
// .instance(); // SBFileUploader
// test('sets blank title with .sb filename', () => { const projectName = instance.getProjectTitleFromFilename('my project is great.sb2');
// const component = componentWithIntl(getContainer()); expect(projectName).toBe('my project is great');
// const projectName = component.getProjectTitleFromFilename('my project is great.sb'); });
// expect(projectName).toBe('');
// }); test('sets blank title with .sb filename', () => {
// const wrapper = shallowWithIntl(getContainer(), {context: {store}});
// test('sets blank title with filename with no extension', () => { const instance = wrapper
// const component = componentWithIntl(getContainer()); .dive() // unwrap redux Connect(InjectIntl(SBFileUploader))
// const projectName = component.getProjectTitleFromFilename('my project is great'); .dive() // unwrap InjectIntl(SBFileUploader)
// expect(projectName).toBe(''); .instance(); // SBFileUploader
// }); const projectName = instance.getProjectTitleFromFilename('my project is great.sb');
expect(projectName).toBe('');
});
test('sets blank title with filename with no extension', () => {
const wrapper = shallowWithIntl(getContainer(), {context: {store}});
const instance = wrapper
.dive() // unwrap redux Connect(InjectIntl(SBFileUploader))
.dive() // unwrap InjectIntl(SBFileUploader)
.instance(); // SBFileUploader
const projectName = instance.getProjectTitleFromFilename('my project is great');
expect(projectName).toBe('');
});
}); });
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment