-
Notifications
You must be signed in to change notification settings - Fork 34
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
217 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
107 changes: 107 additions & 0 deletions
107
src/components/AssetsUploadConfirm/AssetsUploadConfirm.test.jsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,107 @@ | ||
import React from 'react'; | ||
import { Button, StatusAlert } from '@edx/paragon'; | ||
|
||
import AssetUploadConfirm from './index'; | ||
import { mountWithIntl } from '../../utils/i18n/enzymeHelper'; | ||
|
||
const statusAlertIsClosed = (wrapper) => { | ||
expect(wrapper.state('statusAlertOpen')).toEqual(false); | ||
expect(wrapper.find(StatusAlert).prop('open')).toEqual(false); | ||
expect(wrapper.find(AssetUploadConfirm).prop('pre_upload_error')).toEqual(''); | ||
}; | ||
|
||
const statusAlertIsOpen = (wrapper) => { | ||
expect(wrapper.state('statusAlertOpen')).toEqual(true); | ||
expect(wrapper.find(StatusAlert).prop('open')).toEqual(true); | ||
expect(wrapper.find(AssetUploadConfirm).prop('pre_upload_error')).toBeTruthy(); | ||
}; | ||
|
||
const errorMessageHasCorrectFiles = (wrapper, files) => { | ||
const statusAlert = wrapper.find(AssetUploadConfirm); | ||
const statusAlertMessage = statusAlert.prop('pre_upload_error'); | ||
|
||
files.map(file => { | ||
expect(statusAlertMessage).toContain(file); | ||
}) | ||
}; | ||
|
||
const defaultProps = { | ||
files: [], | ||
uploadAssets: () => { }, | ||
clearPreUploadProps: () => {}, | ||
courseDetails: {}, | ||
pre_upload_error: '', | ||
}; | ||
|
||
let wrapper; | ||
|
||
describe('AssetsUploadConfirm', () => { | ||
describe('renders', () => { | ||
it('closed by default', () => { | ||
wrapper = mountWithIntl( | ||
<AssetUploadConfirm | ||
{...defaultProps} | ||
/>, | ||
); | ||
|
||
statusAlertIsClosed(wrapper) | ||
}); | ||
|
||
it('open if there is an error message', () => { | ||
wrapper = mountWithIntl( | ||
<AssetUploadConfirm | ||
{...defaultProps} | ||
/>, | ||
); | ||
wrapper.setProps({ | ||
pre_upload_error: 'The following files already exist: asset.jpg', | ||
}); | ||
|
||
statusAlertIsOpen(wrapper); | ||
errorMessageHasCorrectFiles(wrapper, ['asset.jpg']); | ||
}); | ||
}); | ||
describe('behaves', () => { | ||
it('Overwrite calls uploadAssets', () => { | ||
wrapper = mountWithIntl( | ||
<AssetUploadConfirm | ||
{...defaultProps} | ||
/>, | ||
); | ||
const mockUploadAssets = jest.fn(); | ||
const files = ['file1', 'file2']; | ||
const courseDetails = { | ||
id: 'course-v1:edX+DemoX+Demo_Course', | ||
}; | ||
wrapper.setProps({ | ||
files, | ||
courseDetails, | ||
uploadAssets: mockUploadAssets, | ||
}); | ||
|
||
wrapper.find(Button).filterWhere(button => button.text() === 'Overwrite').simulate('click'); | ||
expect(mockUploadAssets).toBeCalledWith(files, courseDetails) | ||
}); | ||
|
||
it('clicking close button closes the status alert', () => { | ||
wrapper = mountWithIntl( | ||
<AssetUploadConfirm | ||
{...defaultProps} | ||
/>, | ||
); | ||
wrapper.setProps({ | ||
pre_upload_error: 'The following files already exist: asset.jpg', | ||
clearPreUploadProps: () => { | ||
wrapper.setProps({ | ||
...defaultProps, | ||
}) | ||
}, | ||
}); | ||
|
||
const statusAlert = wrapper.find(StatusAlert); | ||
const closeStatusAlertButton = statusAlert.find('button').filterWhere(button => button.text() === '×'); | ||
closeStatusAlertButton.simulate('click'); | ||
statusAlertIsClosed(wrapper); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters