This repository has been archived by the owner on Sep 4, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
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
21 changed files
with
1,140 additions
and
170 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import React from 'react' | ||
import Enzyme from 'enzyme' | ||
import renderer from 'react-test-renderer' | ||
import { shallow } from 'enzyme' | ||
import Adapter from 'enzyme-adapter-react-16' | ||
|
||
import CalloutAlert from '../src/CalloutAlert' | ||
|
||
Enzyme.configure({ adapter: new Adapter() }) | ||
|
||
describe(`CalloutAlert`, () => { | ||
const props = { | ||
error: { | ||
description: `A human-readable description of the error, hopefully useful to the user`, | ||
name: `Error name`, | ||
message: `Error message` | ||
} | ||
} | ||
|
||
it(`prints all the relevant error information`, () => { | ||
const wrapper = shallow(<CalloutAlert {...props} />) | ||
expect(wrapper.text()).toMatch(props.error.description) | ||
expect(wrapper.text()).toMatch(props.error.name) | ||
expect(wrapper.text()).toMatch(props.error.message) | ||
}) | ||
|
||
it(`matches snapshot`, () => { | ||
const tree = renderer.create(<CalloutAlert {...props} />).toJSON() | ||
expect(tree).toMatchSnapshot() | ||
}) | ||
}) |
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,121 @@ | ||
import React from 'react' | ||
import Enzyme from 'enzyme' | ||
import {shallow, mount} from 'enzyme' | ||
import Adapter from 'enzyme-adapter-react-16' | ||
import {getRandomInt, TableCellDiv, data, tableHeader} from './TestUtils' | ||
import ExperimentTable from '../src/ExperimentTable' | ||
import TableFooter from '../src/TableFooter' | ||
import TableHeaderCells from '../src/TableHeaderCells' | ||
import { Table } from 'evergreen-ui' | ||
import _ from "lodash" | ||
|
||
Enzyme.configure({ adapter: new Adapter() }) | ||
|
||
describe(`ExperimentTable`, () => { | ||
const props = { | ||
data: data, | ||
tableHeader: tableHeader, | ||
host: `fool`, | ||
resource: `bool`, | ||
enableDownload: true, | ||
enableIndex: true, | ||
TableCellDiv: TableCellDiv | ||
} | ||
|
||
test(`should render three search general boxes and a table with head and body and two bottom info boxes`, () => { | ||
const wrapper = shallow(<ExperimentTable {...props}/>) | ||
expect(wrapper.find(`.small-8.columns`)).toHaveLength(3) | ||
|
||
expect(wrapper.find(Table)).toHaveLength(1) | ||
expect(wrapper.find(Table.Head)).toHaveLength(1) | ||
expect(wrapper.find(Table.Body)).toHaveLength(1) | ||
|
||
expect(wrapper.find(TableFooter)).toHaveLength(1) | ||
expect(wrapper.find(TableHeaderCells)).toHaveLength(1) | ||
}) | ||
|
||
|
||
test(`should sort table content and change header text icon`, () => { | ||
const randomColumn = getRandomInt(1, tableHeader.length) | ||
props.tableHeader[randomColumn].type=`sort` | ||
const wrapper = mount(<ExperimentTable {...props}/>) | ||
|
||
expect(wrapper.find(`.icon.icon-common.icon-sort-up`)).toHaveLength(1) | ||
expect(wrapper.find(`.icon.icon-common.icon-sort-down`)).toHaveLength(0) | ||
|
||
const sortedHeader = wrapper.find(`.header${randomColumn}`).at(0) | ||
sortedHeader.simulate('click') | ||
wrapper.update() | ||
expect(wrapper.find(`.icon.icon-common.icon-sort-up`)).toHaveLength(0) | ||
sortedHeader.simulate('click') | ||
wrapper.update() | ||
expect(wrapper.find(`.icon.icon-common.icon-sort-up`)).toHaveLength(1) | ||
}) | ||
|
||
test(`should filter based on kingdom selection`, () => { | ||
const event = {target: {name: `pollName`, value: `animals`}} | ||
const wrapper = mount(<ExperimentTable {...props}/>) | ||
const kingdomSearch = wrapper.find(`.kingdom`).at(0) | ||
kingdomSearch.simulate(`change`, event) | ||
|
||
expect(wrapper.state(`selectedKingdom`)).toEqual(`animals`) | ||
expect(wrapper.find(Table.Row).length).toBeLessThanOrEqual(data.length) | ||
}) | ||
|
||
test(`should filter based on table header search`, () => { | ||
const randomValue = `si` | ||
const randomColumn = getRandomInt(1, tableHeader.length) | ||
props.tableHeader[randomColumn].type=`search` | ||
|
||
const wrapper = mount(<ExperimentTable {...props}/>) | ||
expect(wrapper.find(`.searchheader${randomColumn}`).exists()).toBe(true) | ||
wrapper.setState({searchQuery: randomValue}) | ||
wrapper.update() | ||
expect(wrapper.find(Table.Row).length).toBeLessThanOrEqual(data.length) | ||
}) | ||
|
||
test(`should change page by clicking buttons`, () => { | ||
const wrapper = mount(<ExperimentTable {...props}/>) | ||
const currentPage = wrapper.state().currentPage | ||
wrapper.setState({selectedNumber: 1, currentPage: 1}) | ||
wrapper.update() | ||
|
||
const nextButton = wrapper.find('a.next') | ||
nextButton.simulate('click') | ||
wrapper.update() | ||
expect(wrapper.state().currentPage).toEqual(currentPage+1) | ||
|
||
const prevButton = wrapper.find('a.previous') | ||
prevButton.simulate('click') | ||
expect(wrapper.state().currentPage).toEqual(currentPage) | ||
|
||
const pageNumberButton = wrapper.find(`.paginate_button.number a`) | ||
const currentNumberButton = wrapper.find(`.paginate_button.number.current`) | ||
expect(pageNumberButton).toHaveLength(data.length-1) | ||
expect(currentNumberButton).toHaveLength(1) | ||
}) | ||
|
||
test(`should show/hide download based on props`, () => { | ||
const wrapper = shallow(<ExperimentTable {...props} enableDownload={true}/>) | ||
expect(wrapper.find(`.downloadHeader`)).toHaveLength(1) | ||
|
||
const wrapperNoDownload= shallow(<ExperimentTable {...props} enableDownload={false}/>) | ||
expect(wrapperNoDownload.find(`.downloadHeader`)).toHaveLength(0) | ||
}) | ||
|
||
test(`should save experiment accession by check download box`, () => { | ||
const randomRow = getRandomInt(0, data.length) | ||
|
||
const wrapper = mount(<ExperimentTable {...props} enableDownload={true}/>) | ||
const propKey = tableHeader[wrapper.state(`orderedColumn`)].dataParam | ||
const filteredElements = _.sortBy(data, propKey) | ||
|
||
expect(wrapper.state(`checkedArray`)).toEqual([]) | ||
const checkbox = wrapper.find(`.checkbox`).at(randomRow) | ||
checkbox.simulate(`change`) | ||
expect(wrapper.state(`checkedArray`)).toEqual([filteredElements[randomRow].experimentAccession]) | ||
checkbox.simulate(`change`) | ||
expect(wrapper.state(`checkedArray`)).toEqual([]) | ||
}) | ||
|
||
}) |
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,104 @@ | ||
import React from 'react' | ||
import Enzyme from 'enzyme' | ||
import { shallow } from 'enzyme' | ||
import Adapter from 'enzyme-adapter-react-16' | ||
import fetchMock from 'fetch-mock' | ||
|
||
import { getRandomInt } from './TestUtils' | ||
|
||
import FetchLoader from '../src/FetchLoader' | ||
import CalloutAlert from '../src/CalloutAlert' | ||
|
||
Enzyme.configure({ adapter: new Adapter() }) | ||
|
||
const DummyComponentClass = () => <div></div> | ||
|
||
describe(`FetchLoader`, () => { | ||
beforeEach(() => { | ||
fetchMock.restore() | ||
}) | ||
|
||
const props = { | ||
host: `glip/`, | ||
resource: `glops`, | ||
noResultsMessageFormatter: DummyComponentClass | ||
} | ||
|
||
const getRandomHttpErrorCode = () => getRandomInt(400, 600) | ||
|
||
test(`until the fetch promise is not resolved a loading message is displayed, then goes away`, async () => { | ||
fetchMock.get(`*`, `{"results":[]}`) | ||
const wrapper = shallow(<FetchLoader {...props} />) | ||
|
||
expect(wrapper.find(`#loader`)).toHaveLength(1) | ||
expect(wrapper.find(CalloutAlert)).toHaveLength(0) | ||
|
||
await wrapper.instance().componentDidMount() | ||
wrapper.update() | ||
|
||
expect(wrapper.find(`#loader`)).toHaveLength(0) | ||
expect(wrapper.find(CalloutAlert)).toHaveLength(0) | ||
}) | ||
|
||
test(`renders an error message if request to the server returns 4xx or 5xx`, async () => { | ||
fetchMock.get(`*`, getRandomHttpErrorCode) | ||
const wrapper = shallow(<FetchLoader {...props} />) | ||
|
||
await wrapper.instance().componentDidMount() | ||
wrapper.update() | ||
expect(wrapper.find(CalloutAlert)).toHaveLength(1) | ||
}) | ||
|
||
test(`renders an error message if the component does not receive JSON`, async () => { | ||
fetchMock.get(`*`, `Break the cycle, Morty. Rise above. Focus on the science`) | ||
const wrapper = shallow(<FetchLoader {...props} />) | ||
|
||
await wrapper.instance().componentDidMount() | ||
wrapper.update() | ||
expect(wrapper.find(CalloutAlert)).toHaveLength(1) | ||
}) | ||
|
||
test(`renders an error message if the child receives invalid JSON (and the error boundary kicks in)`, async () => { | ||
fetchMock.get(`*`, `{}`) | ||
const wrapper = shallow(<FetchLoader {...props} />) | ||
|
||
const e = new Error(`They’re inside you building a monument to compromise!`) | ||
wrapper.instance().componentDidCatch(e, `Ruben’s seen some rough years, Morty.`) | ||
wrapper.update() | ||
expect(wrapper.find(CalloutAlert)).toHaveLength(1) | ||
}) | ||
|
||
test(`re-fetches on props change and recovers from error if new fetch succeeds`, async () => { | ||
fetchMock.get(`/glip/glops`, getRandomHttpErrorCode) | ||
const wrapper = shallow(<FetchLoader {...props} />) | ||
|
||
await wrapper.instance().componentDidMount() | ||
wrapper.update() | ||
expect(wrapper.find(CalloutAlert)).toHaveLength(1) | ||
|
||
fetchMock.get(`/glops/glip`, `{"results":[]}`) | ||
wrapper.setProps({ | ||
host: `glops/`, | ||
resource: `glip` | ||
}) | ||
|
||
await wrapper.instance().componentDidUpdate() | ||
wrapper.update() | ||
expect(wrapper.find(CalloutAlert)).toHaveLength(0) | ||
}) | ||
|
||
test(`passes JSON payload to prop noResultsMessageFormatter`, async () => { | ||
fetchMock.get(`*`, `{"results":[], "reason": "Rubber baby bubby bunkers!"}`) | ||
const wrapper = | ||
shallow( | ||
<FetchLoader | ||
{...props} | ||
noResultsMessageFormatter={(data) => `No results: ${data.reason}`} />) | ||
|
||
await wrapper.instance().componentDidMount() | ||
wrapper.update() | ||
|
||
expect(wrapper.find(`h5`).text()).toBe(`No results: Rubber baby bubby bunkers!`) | ||
}) | ||
|
||
}) |
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.