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.
Merge pull request #1 from ebi-gene-expression-group/feature/16241679…
…2-create-new-experiment-table Feature/162416792 create new experiment table
- Loading branch information
Showing
19 changed files
with
3,261 additions
and
2,010 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,107 @@ | ||
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 TableContent from '../src/TableContent' | ||
import TableSearchHeader from '../src/TableSearchHeader' | ||
import { Table } from 'evergreen-ui' | ||
import _ from "lodash" | ||
|
||
Enzyme.configure({ adapter: new Adapter() }) | ||
|
||
describe(`ExperimentTable`, () => { | ||
const props = { | ||
aaData: 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(TableSearchHeader)).toHaveLength(1) | ||
expect(wrapper.find(TableContent)).toHaveLength(1) | ||
expect(wrapper.find(TableFooter)).toHaveLength(1) | ||
}) | ||
|
||
|
||
test(`should sort table content and change header text icon`, () => { | ||
const randomColumnIndex = getRandomInt(1, tableHeader.length) | ||
props.tableHeader[randomColumnIndex].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${randomColumnIndex}`).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(`select`).first().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({entriesPerPage: 1, currentPage: 1}) | ||
wrapper.update() | ||
|
||
const nextButton = wrapper.find('.pagination li').last() | ||
nextButton.children().simulate(`click`) | ||
wrapper.update() | ||
expect(wrapper.state().currentPage).toEqual(currentPage + 1) | ||
|
||
const prevButton = wrapper.find('.pagination li').first() | ||
prevButton.children().simulate(`click`) | ||
expect(wrapper.state().currentPage).toEqual(currentPage) | ||
|
||
const currentNumberButton = wrapper.find(`.current`) | ||
expect(currentNumberButton).toHaveLength(1) | ||
}) | ||
|
||
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(`orderedColumnIndex`)].dataParam | ||
const sortedElements = _.sortBy(data, propKey) | ||
|
||
expect(wrapper.state(`checkedRows`)).toEqual([]) | ||
const checkbox = wrapper.find(`.checkbox`).at(randomRow) | ||
checkbox.simulate(`change`) | ||
expect(wrapper.state(`checkedRows`)).toEqual([sortedElements[randomRow].experimentAccession]) | ||
checkbox.simulate(`change`) | ||
expect(wrapper.state(`checkedRows`)).toEqual([]) | ||
}) | ||
|
||
}) |
This file was deleted.
Oops, something went wrong.
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,56 @@ | ||
import React from 'react' | ||
import Enzyme from 'enzyme' | ||
import {shallow} from 'enzyme' | ||
import Adapter from 'enzyme-adapter-react-16' | ||
import { data } from './TestUtils' | ||
|
||
import TableContent from '../src/TableContent' | ||
import { Table } from 'evergreen-ui' | ||
|
||
Enzyme.configure({ adapter: new Adapter() }) | ||
|
||
describe(`TableContent`, () => { | ||
const props = { | ||
enableIndex: true, | ||
tableHeader: [{ | ||
type: `search`, | ||
title: `title1`, | ||
width: 12, | ||
dataParam: `hello` | ||
}, | ||
{ | ||
type: `search`, | ||
title: `title2`, | ||
width: 3, | ||
dataParam: `hi` | ||
}], | ||
searchedColumnIndex: 2, | ||
searchQuery: `search`, | ||
orderedColumnIndex: 1, | ||
ascendingOrder: true, | ||
enableDownload: true, | ||
checkedRows: [1, 2], | ||
currentPageData: data, | ||
host: `boo`, | ||
entriesPerPage: 2, | ||
currentPage: 1, | ||
tableHeaderOnClick: () => {}, | ||
tableHeaderOnChange: () => {}, | ||
downloadOnChange: () => {} | ||
} | ||
|
||
test(`should render a previous button, a next button and information text`, () => { | ||
const wrapper = shallow(<TableContent {...props}/>) | ||
expect(wrapper.find(Table)).toHaveLength(1) | ||
expect(wrapper.find(Table.Head)).toHaveLength(1) | ||
expect(wrapper.find(Table.Body)).toHaveLength(1) | ||
}) | ||
|
||
test(`should show/hide download based on props`, () => { | ||
const wrapper = shallow(<TableContent {...props} enableDownload={true}/>) | ||
expect(wrapper.find(`.downloadHeader`)).toHaveLength(1) | ||
|
||
const wrapperNoDownload= shallow(<TableContent {...props} enableDownload={false}/>) | ||
expect(wrapperNoDownload.find(`.downloadHeader`)).toHaveLength(0) | ||
}) | ||
}) |
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,26 @@ | ||
import React from 'react' | ||
import Enzyme from 'enzyme' | ||
import {shallow} from 'enzyme' | ||
import Adapter from 'enzyme-adapter-react-16' | ||
import { data } from './TestUtils' | ||
import TableFooter from '../src/TableFooter' | ||
|
||
Enzyme.configure({ adapter: new Adapter() }) | ||
|
||
describe(`TableFooter`, () => { | ||
const props = { | ||
dataArrayLength: Math.random() * 10, | ||
entriesPerPage: 1, | ||
selectedNumber: 2, | ||
dataLength: data.length, | ||
currentPage: 1, | ||
onChange: () => {} | ||
} | ||
|
||
test(`should render a previous button, a next button and information text`, () => { | ||
const wrapper = shallow(<TableFooter {...props}/>) | ||
expect(wrapper.find(`li`).first().key()).toBe(`previous`) | ||
expect(wrapper.find(`li`).last().key()).toBe(`next`) | ||
}) | ||
|
||
}) |
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,27 @@ | ||
import React from 'react' | ||
import Enzyme from 'enzyme' | ||
import {shallow} from 'enzyme' | ||
import Adapter from 'enzyme-adapter-react-16' | ||
import { data } from './TestUtils' | ||
import TableSearchHeader from '../src/TableSearchHeader' | ||
|
||
Enzyme.configure({ adapter: new Adapter() }) | ||
|
||
describe(`TableSearchHeader`, () => { | ||
const props = { | ||
kingdomOptions: [`hello`, `bonjour`], | ||
entriesPerPageOptions: [1, 4, 5, 100], | ||
aaData: data, | ||
searchAllOnChange: () => {}, | ||
numberOfEntriesPerPageOnChange: () => {}, | ||
kingdomOnChange: () => {}, | ||
totalNumberOfRows: 2 | ||
} | ||
|
||
test(`should render two dropdown menues and a search box`, () => { | ||
const wrapper = shallow(<TableSearchHeader {...props}/>) | ||
expect(wrapper.find(`select`)).toHaveLength(2) | ||
expect(wrapper.find(`input`)).toHaveLength(1) | ||
}) | ||
|
||
}) |
Oops, something went wrong.