From ec8b6e4c60fa3221bf5df9ee39e755bf45fba875 Mon Sep 17 00:00:00 2001 From: Mingze Xiao Date: Fri, 10 Jan 2020 16:52:12 -0800 Subject: [PATCH 1/6] feat(archive): Add root folder --- src/i18n/en-US.properties | 2 ++ src/lib/viewers/archive/ArchiveExplorer.js | 14 +++++++++----- src/lib/viewers/archive/Breadcrumbs.js | 17 ++++++++++++----- .../archive/__tests__/Breadcrumbs-test-react.js | 8 ++++++-- src/lib/viewers/archive/constants.js | 4 +++- 5 files changed, 32 insertions(+), 13 deletions(-) diff --git a/src/i18n/en-US.properties b/src/i18n/en-US.properties index 3f99af0fc..230a8de7b 100644 --- a/src/i18n/en-US.properties +++ b/src/i18n/en-US.properties @@ -84,6 +84,8 @@ error_flash_not_enabled=We’re sorry, the preview didn’t load because Flash i filename=Filename # Label for last modified date column name last_modified_date=Last modified date +# Label for the root folder +root_folder=Root Folder # Label for size column name size=Size # Shown as search accessibility label. diff --git a/src/lib/viewers/archive/ArchiveExplorer.js b/src/lib/viewers/archive/ArchiveExplorer.js index cb127f553..35c7e5c59 100644 --- a/src/lib/viewers/archive/ArchiveExplorer.js +++ b/src/lib/viewers/archive/ArchiveExplorer.js @@ -15,7 +15,7 @@ import { import { addLocaleData } from 'react-intl'; import Breadcrumbs from './Breadcrumbs'; import SearchBar from './SearchBar'; -import { TABLE_COLUMNS, VIEWS } from './constants'; +import { ROOT_FOLDER, TABLE_COLUMNS, VIEWS } from './constants'; import './ArchiveExplorer.scss'; const language = __LANGUAGE__; // eslint-disable-line @@ -47,10 +47,7 @@ class ArchiveExplorer extends React.Component { addLocaleData(intlLocaleData); this.state = { - // Trying to find the root folder - // The only way to tell what the root folder is - // is by comparing the name and absolute path, which differs by '/' - fullPath: props.itemCollection.find(info => info.name === info.absolute_path.slice(0, -1)).absolute_path, + fullPath: ROOT_FOLDER, searchQuery: '', sortBy: '', sortDirection: SortDirection.ASC, @@ -66,6 +63,13 @@ class ArchiveExplorer extends React.Component { * @return {Array} filtered itemlist for target folder */ getItemList = (itemCollection, fullPath) => { + if (fullPath === ROOT_FOLDER) { + // Trying to find the root items + // The only way to tell what the root items are + // is by comparing the name and absolute path, which differs by '/' + return itemCollection.filter(info => info.name === info.absolute_path.slice(0, -1)); + } + const { item_collection: folderItems = [] } = itemCollection.find(item => item.absolute_path === fullPath); return itemCollection.filter(item => folderItems.includes(item.absolute_path)); }; diff --git a/src/lib/viewers/archive/Breadcrumbs.js b/src/lib/viewers/archive/Breadcrumbs.js index dd3189808..ad80050ec 100644 --- a/src/lib/viewers/archive/Breadcrumbs.js +++ b/src/lib/viewers/archive/Breadcrumbs.js @@ -2,7 +2,7 @@ import React from 'react'; import PropTypes from 'prop-types'; import Breadcrumb from 'box-ui-elements/es/components/breadcrumb'; import PlainButton from 'box-ui-elements/es/components/plain-button/PlainButton'; -import { VIEWS } from './constants'; +import { ROOT_FOLDER, VIEWS } from './constants'; import './Breadcrumbs.scss'; class Breadcrumbs extends React.PureComponent { @@ -19,14 +19,21 @@ class Breadcrumbs extends React.PureComponent { * @return {Array} path items including name and path string */ getPathItems = fullPath => { + if (fullPath === ROOT_FOLDER) { + return [{ name: __('root_folder'), path: ROOT_FOLDER }]; + } + const pathNames = fullPath.split('/').slice(0, -1); // join path names from root to current index to get absolute path const getAbsolutePath = index => pathNames.slice(0, index + 1).join('/'); - return pathNames.map((name, index) => ({ - name, - path: `${getAbsolutePath(index)}/`, - })); + return [ + { name: __('root_folder'), path: ROOT_FOLDER }, + ...pathNames.map((name, index) => ({ + name, + path: `${getAbsolutePath(index)}/`, + })), + ]; }; /** diff --git a/src/lib/viewers/archive/__tests__/Breadcrumbs-test-react.js b/src/lib/viewers/archive/__tests__/Breadcrumbs-test-react.js index 7c507dbee..cf99df0f1 100644 --- a/src/lib/viewers/archive/__tests__/Breadcrumbs-test-react.js +++ b/src/lib/viewers/archive/__tests__/Breadcrumbs-test-react.js @@ -2,7 +2,7 @@ import React from 'react'; import { shallow } from 'enzyme'; import sinon from 'sinon'; import Breadcrumbs from '../Breadcrumbs'; -import { VIEWS } from '../constants'; +import { ROOT_FOLDER, VIEWS } from '../constants'; const sandbox = sinon.sandbox.create(); let fullPath; @@ -26,7 +26,7 @@ describe('lib/viewers/archive/Breadcrumbs', () => { expect(component.find('.bp-Breadcrumbs').length).to.equal(1); expect(component.find('InjectIntl(Breadcrumb)').length).to.equal(1); - expect(component.find('PlainButton').length).to.equal(2); + expect(component.find('PlainButton').length).to.equal(3); }); it('should render search result if view is search', () => { @@ -43,6 +43,10 @@ describe('lib/viewers/archive/Breadcrumbs', () => { const pathItems = component.instance().getPathItems(fullPath); expect(pathItems).to.eql([ + { + name: __('root_folder'), + path: ROOT_FOLDER, + }, { name: 'test', path: 'test/', diff --git a/src/lib/viewers/archive/constants.js b/src/lib/viewers/archive/constants.js index 9b6d16efa..87848ccc6 100644 --- a/src/lib/viewers/archive/constants.js +++ b/src/lib/viewers/archive/constants.js @@ -9,4 +9,6 @@ const VIEWS = { VIEW_SEARCH: 'search', }; -export { TABLE_COLUMNS, VIEWS }; +const ROOT_FOLDER = 'root/'; + +export { ROOT_FOLDER, TABLE_COLUMNS, VIEWS }; From 7c579cf5df35e452653a89770a14f1ff4f7dd6f7 Mon Sep 17 00:00:00 2001 From: Mingze Xiao Date: Mon, 13 Jan 2020 10:15:59 -0800 Subject: [PATCH 2/6] feat(archive): Address comments --- .../__tests__/Breadcrumbs-test-react.js | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/src/lib/viewers/archive/__tests__/Breadcrumbs-test-react.js b/src/lib/viewers/archive/__tests__/Breadcrumbs-test-react.js index cf99df0f1..acc5b832c 100644 --- a/src/lib/viewers/archive/__tests__/Breadcrumbs-test-react.js +++ b/src/lib/viewers/archive/__tests__/Breadcrumbs-test-react.js @@ -9,6 +9,8 @@ let fullPath; let onClick; let view; +const getComponent = props => shallow(); + describe('lib/viewers/archive/Breadcrumbs', () => { beforeEach(() => { fullPath = 'test/subfolder/'; @@ -22,7 +24,7 @@ describe('lib/viewers/archive/Breadcrumbs', () => { describe('render()', () => { it('should render correct components', () => { - const component = shallow(); + const component = getComponent({ fullPath, onClick, view }); expect(component.find('.bp-Breadcrumbs').length).to.equal(1); expect(component.find('InjectIntl(Breadcrumb)').length).to.equal(1); @@ -30,7 +32,7 @@ describe('lib/viewers/archive/Breadcrumbs', () => { }); it('should render search result if view is search', () => { - const component = shallow(); + const component = getComponent({ fullPath, onClick, view: VIEWS.VIEW_SEARCH }); expect(component.find('span').text()).to.equal(__('search_results')); }); @@ -38,9 +40,18 @@ describe('lib/viewers/archive/Breadcrumbs', () => { describe('getPathItems()', () => { it('should return correct path items', () => { - const component = shallow(); + const component = getComponent({ fullPath, onClick, view }); + + let pathItems = component.instance().getPathItems(ROOT_FOLDER); + + expect(pathItems).to.eql([ + { + name: __('root_folder'), + path: ROOT_FOLDER, + }, + ]); - const pathItems = component.instance().getPathItems(fullPath); + pathItems = component.instance().getPathItems(fullPath); expect(pathItems).to.eql([ { From 0da359b7498c385da232dc2e8338581b3f562847 Mon Sep 17 00:00:00 2001 From: Mingze Xiao Date: Mon, 13 Jan 2020 12:43:01 -0800 Subject: [PATCH 3/6] feat(archive): Add missed files for root folder --- src/lib/viewers/archive/ArchiveExplorer.js | 7 +++++-- .../__tests__/ArchiveExplorer-test-react.js | 16 ++++++++++++++-- 2 files changed, 19 insertions(+), 4 deletions(-) diff --git a/src/lib/viewers/archive/ArchiveExplorer.js b/src/lib/viewers/archive/ArchiveExplorer.js index 35c7e5c59..df9cc47dd 100644 --- a/src/lib/viewers/archive/ArchiveExplorer.js +++ b/src/lib/viewers/archive/ArchiveExplorer.js @@ -66,8 +66,11 @@ class ArchiveExplorer extends React.Component { if (fullPath === ROOT_FOLDER) { // Trying to find the root items // The only way to tell what the root items are - // is by comparing the name and absolute path, which differs by '/' - return itemCollection.filter(info => info.name === info.absolute_path.slice(0, -1)); + // is by comparing the name and absolute path, + // which are the same for files and differ by '/' for folders + return itemCollection.filter( + info => info.name === info.absolute_path || info.name === info.absolute_path.slice(0, -1), + ); } const { item_collection: folderItems = [] } = itemCollection.find(item => item.absolute_path === fullPath); diff --git a/src/lib/viewers/archive/__tests__/ArchiveExplorer-test-react.js b/src/lib/viewers/archive/__tests__/ArchiveExplorer-test-react.js index 6a32f8236..4661256ef 100644 --- a/src/lib/viewers/archive/__tests__/ArchiveExplorer-test-react.js +++ b/src/lib/viewers/archive/__tests__/ArchiveExplorer-test-react.js @@ -2,7 +2,7 @@ import React from 'react'; import { shallow } from 'enzyme'; import sinon from 'sinon'; import ArchiveExplorer from '../ArchiveExplorer'; -import { TABLE_COLUMNS, VIEWS } from '../constants'; +import { TABLE_COLUMNS, VIEWS, ROOT_FOLDER } from '../constants'; const sandbox = sinon.sandbox.create(); let data; @@ -44,6 +44,14 @@ describe('lib/viewers/archive/ArchiveExplorer', () => { size: 57379, item_collection: null, }, + { + type: 'file', + absolute_path: 'level-0.txt', + name: 'level-0.txt', + modified_at: '19-Nov-04 16:11', + size: 1, + item_collection: null, + }, ]; }); @@ -114,7 +122,11 @@ describe('lib/viewers/archive/ArchiveExplorer', () => { it('should return correct item list', () => { const component = getComponent({ itemCollection: data }); - const itemList = component.instance().getItemList(data, 'test/'); + let itemList = component.instance().getItemList(data, ROOT_FOLDER); + + expect(itemList).to.eql([data[0], data[4]]); + + itemList = component.instance().getItemList(data, 'test/'); expect(itemList).to.eql([data[1], data[2]]); }); From cdeab6b62548f6ac3f8586eeb2d0f4e600465ca5 Mon Sep 17 00:00:00 2001 From: Mingze Xiao Date: Mon, 13 Jan 2020 14:25:43 -0800 Subject: [PATCH 4/6] feat(archive): Address comments --- src/lib/viewers/archive/ArchiveExplorer.js | 2 +- src/lib/viewers/archive/Breadcrumbs.js | 9 +++++---- .../archive/__tests__/Breadcrumbs-test-react.js | 11 +++++++---- 3 files changed, 13 insertions(+), 9 deletions(-) diff --git a/src/lib/viewers/archive/ArchiveExplorer.js b/src/lib/viewers/archive/ArchiveExplorer.js index df9cc47dd..09a3a9f10 100644 --- a/src/lib/viewers/archive/ArchiveExplorer.js +++ b/src/lib/viewers/archive/ArchiveExplorer.js @@ -69,7 +69,7 @@ class ArchiveExplorer extends React.Component { // is by comparing the name and absolute path, // which are the same for files and differ by '/' for folders return itemCollection.filter( - info => info.name === info.absolute_path || info.name === info.absolute_path.slice(0, -1), + ({ name, absolute_path: path }) => name === path || name === path.slice(0, -1), ); } diff --git a/src/lib/viewers/archive/Breadcrumbs.js b/src/lib/viewers/archive/Breadcrumbs.js index ad80050ec..750dd741c 100644 --- a/src/lib/viewers/archive/Breadcrumbs.js +++ b/src/lib/viewers/archive/Breadcrumbs.js @@ -19,21 +19,22 @@ class Breadcrumbs extends React.PureComponent { * @return {Array} path items including name and path string */ getPathItems = fullPath => { + const pathItems = [{ name: __('root_folder'), path: ROOT_FOLDER }]; if (fullPath === ROOT_FOLDER) { - return [{ name: __('root_folder'), path: ROOT_FOLDER }]; + return pathItems; } const pathNames = fullPath.split('/').slice(0, -1); // join path names from root to current index to get absolute path const getAbsolutePath = index => pathNames.slice(0, index + 1).join('/'); - return [ - { name: __('root_folder'), path: ROOT_FOLDER }, + pathItems.push( ...pathNames.map((name, index) => ({ name, path: `${getAbsolutePath(index)}/`, })), - ]; + ); + return pathItems; }; /** diff --git a/src/lib/viewers/archive/__tests__/Breadcrumbs-test-react.js b/src/lib/viewers/archive/__tests__/Breadcrumbs-test-react.js index acc5b832c..630fae4cf 100644 --- a/src/lib/viewers/archive/__tests__/Breadcrumbs-test-react.js +++ b/src/lib/viewers/archive/__tests__/Breadcrumbs-test-react.js @@ -39,10 +39,9 @@ describe('lib/viewers/archive/Breadcrumbs', () => { }); describe('getPathItems()', () => { - it('should return correct path items', () => { + it('should return root folder', () => { const component = getComponent({ fullPath, onClick, view }); - - let pathItems = component.instance().getPathItems(ROOT_FOLDER); + const pathItems = component.instance().getPathItems(ROOT_FOLDER); expect(pathItems).to.eql([ { @@ -50,8 +49,12 @@ describe('lib/viewers/archive/Breadcrumbs', () => { path: ROOT_FOLDER, }, ]); + }); + + it('should return correct path items', () => { + const component = getComponent({ fullPath, onClick, view }); - pathItems = component.instance().getPathItems(fullPath); + const pathItems = component.instance().getPathItems(fullPath); expect(pathItems).to.eql([ { From a2b5c5df5e8cfde36c2e1b0186f73166de2f48f3 Mon Sep 17 00:00:00 2001 From: Mingze Xiao Date: Mon, 13 Jan 2020 14:48:13 -0800 Subject: [PATCH 5/6] feat(archive): Address comments --- src/lib/viewers/archive/Breadcrumbs.js | 23 +++++++---------------- 1 file changed, 7 insertions(+), 16 deletions(-) diff --git a/src/lib/viewers/archive/Breadcrumbs.js b/src/lib/viewers/archive/Breadcrumbs.js index 750dd741c..8900bdf53 100644 --- a/src/lib/viewers/archive/Breadcrumbs.js +++ b/src/lib/viewers/archive/Breadcrumbs.js @@ -19,22 +19,13 @@ class Breadcrumbs extends React.PureComponent { * @return {Array} path items including name and path string */ getPathItems = fullPath => { - const pathItems = [{ name: __('root_folder'), path: ROOT_FOLDER }]; - if (fullPath === ROOT_FOLDER) { - return pathItems; - } - - const pathNames = fullPath.split('/').slice(0, -1); - // join path names from root to current index to get absolute path - const getAbsolutePath = index => pathNames.slice(0, index + 1).join('/'); - - pathItems.push( - ...pathNames.map((name, index) => ({ - name, - path: `${getAbsolutePath(index)}/`, - })), - ); - return pathItems; + const pathNames = fullPath === ROOT_FOLDER ? [] : fullPath.split('/').slice(0, -1); + const getPath = index => pathNames.slice(0, index + 1).join('/'); + const pathItems = pathNames.map((name, index) => ({ + name, + path: `${getPath(index)}/`, + })); + return [{ name: __('root_folder'), path: ROOT_FOLDER }, ...pathItems]; }; /** From ead5f5bd9253311aefdaaf0a6614286783deff27 Mon Sep 17 00:00:00 2001 From: Mingze Xiao Date: Tue, 14 Jan 2020 11:55:49 -0800 Subject: [PATCH 6/6] feat(archive): Change root folder name to filename --- src/i18n/en-US.properties | 2 -- src/lib/viewers/archive/ArchiveExplorer.js | 10 +++++-- src/lib/viewers/archive/ArchiveViewer.js | 2 +- src/lib/viewers/archive/BoxArchive.js | 7 +++-- src/lib/viewers/archive/Breadcrumbs.js | 4 ++- .../__tests__/ArchiveExplorer-test-react.js | 26 ++++++++++--------- .../archive/__tests__/BoxArchive-test.js | 4 +-- .../__tests__/Breadcrumbs-test-react.js | 14 +++++----- src/lib/viewers/archive/constants.js | 4 +-- 9 files changed, 43 insertions(+), 30 deletions(-) diff --git a/src/i18n/en-US.properties b/src/i18n/en-US.properties index 230a8de7b..3f99af0fc 100644 --- a/src/i18n/en-US.properties +++ b/src/i18n/en-US.properties @@ -84,8 +84,6 @@ error_flash_not_enabled=We’re sorry, the preview didn’t load because Flash i filename=Filename # Label for last modified date column name last_modified_date=Last modified date -# Label for the root folder -root_folder=Root Folder # Label for size column name size=Size # Shown as search accessibility label. diff --git a/src/lib/viewers/archive/ArchiveExplorer.js b/src/lib/viewers/archive/ArchiveExplorer.js index 09a3a9f10..8541ac219 100644 --- a/src/lib/viewers/archive/ArchiveExplorer.js +++ b/src/lib/viewers/archive/ArchiveExplorer.js @@ -24,6 +24,7 @@ const { VIEW_FOLDER, VIEW_SEARCH } = VIEWS; class ArchiveExplorer extends React.Component { static propTypes = { + filename: PropTypes.string.isRequired, itemCollection: PropTypes.arrayOf( PropTypes.shape({ type: PropTypes.string.isRequired, @@ -183,7 +184,7 @@ class ArchiveExplorer extends React.Component { * @return {jsx} VirtualizedTable */ render() { - const { itemCollection } = this.props; + const { filename, itemCollection } = this.props; const { fullPath, searchQuery, sortBy, sortDirection, view } = this.state; const itemList = this.sortItemList( view === VIEW_SEARCH @@ -195,7 +196,12 @@ class ArchiveExplorer extends React.Component {
- +
{({ height }) => ( diff --git a/src/lib/viewers/archive/ArchiveViewer.js b/src/lib/viewers/archive/ArchiveViewer.js index 22eeaf28f..ddd8fd0af 100644 --- a/src/lib/viewers/archive/ArchiveViewer.js +++ b/src/lib/viewers/archive/ArchiveViewer.js @@ -71,7 +71,7 @@ class ArchiveViewer extends BaseViewer { try { /* global BoxArchive loaded from archive.js */ - this.archiveComponent = new BoxArchive(this.archiveEl, data); + this.archiveComponent = new BoxArchive(this.archiveEl, this.options.file.name, data); } catch (error) { throw new PreviewError(ERROR_CODE.LOAD_VIEWER, __('error_reupload'), error); } diff --git a/src/lib/viewers/archive/BoxArchive.js b/src/lib/viewers/archive/BoxArchive.js index 9c4227660..37cf0e697 100644 --- a/src/lib/viewers/archive/BoxArchive.js +++ b/src/lib/viewers/archive/BoxArchive.js @@ -10,9 +10,12 @@ class BoxArchive { * @param {Object} data - Archive data * @return {BoxArchive} Instance */ - constructor(archiveEl, data) { + constructor(archiveEl, filename, data) { this.archiveEl = archiveEl; - ReactDOM.render(, this.archiveEl); + ReactDOM.render( + , + this.archiveEl, + ); } /** diff --git a/src/lib/viewers/archive/Breadcrumbs.js b/src/lib/viewers/archive/Breadcrumbs.js index 8900bdf53..56140280b 100644 --- a/src/lib/viewers/archive/Breadcrumbs.js +++ b/src/lib/viewers/archive/Breadcrumbs.js @@ -7,6 +7,7 @@ import './Breadcrumbs.scss'; class Breadcrumbs extends React.PureComponent { static propTypes = { + filename: PropTypes.string.isRequired, fullPath: PropTypes.string.isRequired, onClick: PropTypes.func.isRequired, view: PropTypes.string.isRequired, @@ -19,13 +20,14 @@ class Breadcrumbs extends React.PureComponent { * @return {Array} path items including name and path string */ getPathItems = fullPath => { + const { filename } = this.props; const pathNames = fullPath === ROOT_FOLDER ? [] : fullPath.split('/').slice(0, -1); const getPath = index => pathNames.slice(0, index + 1).join('/'); const pathItems = pathNames.map((name, index) => ({ name, path: `${getPath(index)}/`, })); - return [{ name: __('root_folder'), path: ROOT_FOLDER }, ...pathItems]; + return [{ name: filename, path: ROOT_FOLDER }, ...pathItems]; }; /** diff --git a/src/lib/viewers/archive/__tests__/ArchiveExplorer-test-react.js b/src/lib/viewers/archive/__tests__/ArchiveExplorer-test-react.js index 4661256ef..2e53cf4b5 100644 --- a/src/lib/viewers/archive/__tests__/ArchiveExplorer-test-react.js +++ b/src/lib/viewers/archive/__tests__/ArchiveExplorer-test-react.js @@ -6,11 +6,13 @@ import { TABLE_COLUMNS, VIEWS, ROOT_FOLDER } from '../constants'; const sandbox = sinon.sandbox.create(); let data; +let filename; const getComponent = props => shallow(); // eslint-disable-line describe('lib/viewers/archive/ArchiveExplorer', () => { beforeEach(() => { + filename = 'test.zip'; data = [ { type: 'folder', @@ -61,7 +63,7 @@ describe('lib/viewers/archive/ArchiveExplorer', () => { describe('render()', () => { it('should render correct components', () => { - const component = getComponent({ itemCollection: data }); + const component = getComponent({ filename, itemCollection: data }); expect(component.find('.bp-ArchiveExplorer').length).to.equal(1); expect(component.find('SearchBar').length).to.equal(1); @@ -72,7 +74,7 @@ describe('lib/viewers/archive/ArchiveExplorer', () => { describe('handleItemClick()', () => { it('should set state when handleItemClick() is called', () => { - const component = getComponent({ itemCollection: data }); + const component = getComponent({ filename, itemCollection: data }); component.instance().handleItemClick({ fullPath: 'test/subfolder/' }); @@ -84,7 +86,7 @@ describe('lib/viewers/archive/ArchiveExplorer', () => { describe('handleBreadcrumbClick()', () => { it('should set state when handleBreadcrumbClick() is called', () => { - const component = getComponent({ itemCollection: data }); + const component = getComponent({ filename, itemCollection: data }); component.instance().handleBreadcrumbClick('test/subfolder/'); @@ -94,7 +96,7 @@ describe('lib/viewers/archive/ArchiveExplorer', () => { describe('getRowData()', () => { it('should return correct row data', () => { - const component = getComponent({ itemCollection: data }); + const component = getComponent({ filename, itemCollection: data }); const rowData = component.instance().getRowData(data)({ index: 0 }); @@ -120,7 +122,7 @@ describe('lib/viewers/archive/ArchiveExplorer', () => { describe('getItemList()', () => { it('should return correct item list', () => { - const component = getComponent({ itemCollection: data }); + const component = getComponent({ filename, itemCollection: data }); let itemList = component.instance().getItemList(data, ROOT_FOLDER); @@ -134,7 +136,7 @@ describe('lib/viewers/archive/ArchiveExplorer', () => { describe('handleSearch()', () => { it('should set correct state when search query is not empty', () => { - const component = getComponent({ itemCollection: data }); + const component = getComponent({ filename, itemCollection: data }); component.instance().handleSearch('test'); expect(component.state().searchQuery).to.equal('test'); @@ -152,7 +154,7 @@ describe('lib/viewers/archive/ArchiveExplorer', () => { describe('getSearchResult()', () => { it('should return correct item list', () => { - const component = getComponent({ itemCollection: data }); + const component = getComponent({ filename, itemCollection: data }); const itemList = component.instance().getSearchResult(data, 'level-1'); const fuzzyList = component.instance().getSearchResult(data, 'leel1'); @@ -164,7 +166,7 @@ describe('lib/viewers/archive/ArchiveExplorer', () => { describe('handleSort()', () => { it('should set the sort direction and type', () => { - const component = getComponent({ itemCollection: data }); + const component = getComponent({ filename, itemCollection: data }); const instance = component.instance(); instance.handleSort({ sortBy: 'name', sortDirection: 'DESC' }); @@ -176,7 +178,7 @@ describe('lib/viewers/archive/ArchiveExplorer', () => { describe('sortItemList()', () => { it('should sort itemList by size and be in ASC order', () => { - const component = getComponent({ itemCollection: data }); + const component = getComponent({ filename, itemCollection: data }); const instance = component.instance(); const itemList = instance.getItemList(data, 'test/'); @@ -187,7 +189,7 @@ describe('lib/viewers/archive/ArchiveExplorer', () => { }); it('should sort itemList by name and be in DESC order', () => { - const component = getComponent({ itemCollection: data }); + const component = getComponent({ filename, itemCollection: data }); const instance = component.instance(); const itemList = instance.getItemList(data, 'test/'); @@ -198,7 +200,7 @@ describe('lib/viewers/archive/ArchiveExplorer', () => { }); it('should sort itemList by name and be in ASC order', () => { - const component = getComponent({ itemCollection: data }); + const component = getComponent({ filename, itemCollection: data }); const instance = component.instance(); const itemList = instance.getItemList(data, 'test/'); @@ -209,7 +211,7 @@ describe('lib/viewers/archive/ArchiveExplorer', () => { }); it('should not sort itemList', () => { - const component = getComponent({ itemCollection: data }); + const component = getComponent({ filename, itemCollection: data }); const instance = component.instance(); const itemList = instance.getItemList(data, 'test/'); diff --git a/src/lib/viewers/archive/__tests__/BoxArchive-test.js b/src/lib/viewers/archive/__tests__/BoxArchive-test.js index 8c79e2a7f..cf6ff2495 100644 --- a/src/lib/viewers/archive/__tests__/BoxArchive-test.js +++ b/src/lib/viewers/archive/__tests__/BoxArchive-test.js @@ -31,7 +31,7 @@ describe('lib/viewers/archive/BoxArchive', () => { sandbox.stub(ReactDOM, 'render'); sandbox.stub(ReactDOM, 'unmountComponentAtNode'); - archiveComponent = new BoxArchive(containerEl, []); + archiveComponent = new BoxArchive(containerEl, 'test.zip', []); archiveComponent.archiveExplorer = {}; archiveComponent.destroy(); archiveComponent = null; @@ -45,7 +45,7 @@ describe('lib/viewers/archive/BoxArchive', () => { const renderStub = sandbox.stub(ReactDOM, 'render'); const data = [{ name: 'test.json' }]; - archiveComponent = new BoxArchive(containerEl, data); + archiveComponent = new BoxArchive(containerEl, 'test.zip', data); const archiveExplorer = renderStub.firstCall.args[0]; expect(archiveExplorer.props.itemCollection).to.equal(data); diff --git a/src/lib/viewers/archive/__tests__/Breadcrumbs-test-react.js b/src/lib/viewers/archive/__tests__/Breadcrumbs-test-react.js index 630fae4cf..861655c83 100644 --- a/src/lib/viewers/archive/__tests__/Breadcrumbs-test-react.js +++ b/src/lib/viewers/archive/__tests__/Breadcrumbs-test-react.js @@ -5,6 +5,7 @@ import Breadcrumbs from '../Breadcrumbs'; import { ROOT_FOLDER, VIEWS } from '../constants'; const sandbox = sinon.sandbox.create(); +let filename; let fullPath; let onClick; let view; @@ -13,6 +14,7 @@ const getComponent = props => shallow(); describe('lib/viewers/archive/Breadcrumbs', () => { beforeEach(() => { + filename = 'test.zip'; fullPath = 'test/subfolder/'; onClick = sandbox.stub(); view = VIEWS.VIEW_FOLDER; @@ -24,7 +26,7 @@ describe('lib/viewers/archive/Breadcrumbs', () => { describe('render()', () => { it('should render correct components', () => { - const component = getComponent({ fullPath, onClick, view }); + const component = getComponent({ filename, fullPath, onClick, view }); expect(component.find('.bp-Breadcrumbs').length).to.equal(1); expect(component.find('InjectIntl(Breadcrumb)').length).to.equal(1); @@ -32,7 +34,7 @@ describe('lib/viewers/archive/Breadcrumbs', () => { }); it('should render search result if view is search', () => { - const component = getComponent({ fullPath, onClick, view: VIEWS.VIEW_SEARCH }); + const component = getComponent({ filename, fullPath, onClick, view: VIEWS.VIEW_SEARCH }); expect(component.find('span').text()).to.equal(__('search_results')); }); @@ -40,25 +42,25 @@ describe('lib/viewers/archive/Breadcrumbs', () => { describe('getPathItems()', () => { it('should return root folder', () => { - const component = getComponent({ fullPath, onClick, view }); + const component = getComponent({ filename, fullPath, onClick, view }); const pathItems = component.instance().getPathItems(ROOT_FOLDER); expect(pathItems).to.eql([ { - name: __('root_folder'), + name: filename, path: ROOT_FOLDER, }, ]); }); it('should return correct path items', () => { - const component = getComponent({ fullPath, onClick, view }); + const component = getComponent({ filename, fullPath, onClick, view }); const pathItems = component.instance().getPathItems(fullPath); expect(pathItems).to.eql([ { - name: __('root_folder'), + name: filename, path: ROOT_FOLDER, }, { diff --git a/src/lib/viewers/archive/constants.js b/src/lib/viewers/archive/constants.js index 87848ccc6..0f6ca7d19 100644 --- a/src/lib/viewers/archive/constants.js +++ b/src/lib/viewers/archive/constants.js @@ -1,3 +1,5 @@ +const ROOT_FOLDER = 'root/'; + const TABLE_COLUMNS = { KEY_MODIFIED_AT: 'modified_at', KEY_NAME: 'name', @@ -9,6 +11,4 @@ const VIEWS = { VIEW_SEARCH: 'search', }; -const ROOT_FOLDER = 'root/'; - export { ROOT_FOLDER, TABLE_COLUMNS, VIEWS };