-
Notifications
You must be signed in to change notification settings - Fork 116
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(archive-viewer): add tests and address comments
- Loading branch information
Mingze Xiao
committed
Dec 11, 2019
1 parent
dc7dcb6
commit 7ee396c
Showing
16 changed files
with
765 additions
and
77 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
import { configure } from 'enzyme'; | ||
import Adapter from 'enzyme-adapter-react-16'; | ||
|
||
configure({ adapter: new Adapter() }); | ||
|
||
function importAll(r) { | ||
r.keys().forEach(r); | ||
} | ||
|
||
importAll(require.context('../src/lib/viewers/archive/__tests__', true, /-test-react\.js$/)); |
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
110 changes: 110 additions & 0 deletions
110
src/lib/viewers/archive/__tests__/ArchiveExplorer-test-react.js
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,110 @@ | ||
import React from 'react'; | ||
import { shallow } from 'enzyme'; | ||
import sinon from 'sinon'; | ||
import ArchiveExplorer from '../ArchiveExplorer'; | ||
import { TABLE_COLUMNS } from '../constants'; | ||
|
||
const sandbox = sinon.sandbox.create(); | ||
let data; | ||
|
||
describe('lib/viewers/archive/ArchiveExplorer', () => { | ||
beforeEach(() => { | ||
data = [ | ||
{ | ||
type: 'folder', | ||
absolute_path: 'test/', | ||
name: 'test', | ||
modified_at: '19-Dec-02 16:43', | ||
size: 0, | ||
path_collection: { total_count: 0, entries: [] }, | ||
parent: null, | ||
item_collection: { | ||
total_count: 3, | ||
entries: [ | ||
{ | ||
type: 'file', | ||
absolute_path: 'test/csv-level-1.csv', | ||
name: 'csv-level-1.csv', | ||
}, | ||
{ | ||
type: 'file', | ||
absolute_path: 'test/test-level-1.jpg', | ||
name: 'test-level-1.jpg', | ||
}, | ||
], | ||
}, | ||
}, | ||
{ | ||
type: 'file', | ||
absolute_path: 'test/csv-level-1.csv', | ||
name: 'csv-level-1.csv', | ||
modified_at: '19-Nov-04 16:11', | ||
size: 133, | ||
path_collection: { | ||
total_count: 1, | ||
entries: [{ type: 'folder', absolute_path: 'test/', name: 'test' }], | ||
}, | ||
parent: 'test', | ||
item_collection: null, | ||
}, | ||
{ | ||
type: 'file', | ||
absolute_path: 'test/test-level-1.jpg', | ||
name: 'test-level-1.jpg', | ||
modified_at: '19-Nov-08 15:08', | ||
size: 57379, | ||
path_collection: { | ||
total_count: 1, | ||
entries: [{ type: 'folder', absolute_path: 'test/', name: 'test' }], | ||
}, | ||
parent: 'test', | ||
item_collection: null, | ||
}, | ||
]; | ||
}); | ||
|
||
afterEach(() => { | ||
sandbox.verifyAndRestore(); | ||
}); | ||
|
||
describe('render()', () => { | ||
it('should render VirtualizedTable', () => { | ||
const component = shallow(<ArchiveExplorer itemCollection={data} />); | ||
|
||
expect(component.find('Internationalize').length).to.equal(1); | ||
expect(component.find('InjectIntl(VirtualizedTable)').length).to.equal(1); | ||
}); | ||
}); | ||
|
||
describe('handleClick()', () => { | ||
it('should set state when handleClick() is called', () => { | ||
const component = shallow(<ArchiveExplorer itemCollection={data} />); | ||
|
||
component.instance().handleClick({ name: 'subfolder' }); | ||
|
||
expect(component.state().fullPath).to.equal('test/subfolder/'); | ||
}); | ||
}); | ||
|
||
describe('getRowData()', () => { | ||
it('should return correct row data', () => { | ||
const component = shallow(<ArchiveExplorer itemCollection={data} />); | ||
|
||
const rowData = component.instance().getRowData(data)({ index: 0 }); | ||
|
||
const { KEY_NAME, KEY_MODIFIED_AT, KEY_SIZE } = TABLE_COLUMNS; | ||
const { modified_at: modifiedAt, name, size, type, ...rest } = data[0]; | ||
|
||
expect(rowData).to.eql({ | ||
[KEY_NAME]: { | ||
isExternal: false, | ||
name, | ||
type, | ||
}, | ||
[KEY_MODIFIED_AT]: `20${modifiedAt}`, | ||
[KEY_SIZE]: size, | ||
...rest, | ||
}); | ||
}); | ||
}); | ||
}); |
Oops, something went wrong.