Commit 9d2326c0 authored by Chaillet Maxime's avatar Chaillet Maxime

write first integration test

parent a2f532f5
import React from 'react';
import PropTypes from 'prop-types';
import { getOriginalEvent, getEventIcon, getLastCommentContent, getEventCreationDate, getEventHistoryCreationDate, getContent } from '../../../helpers/EventHelpers'
import { getOriginalEvent, getEventIcon, getLastCommentContent, getContent } from '../../../helpers/EventHelpers'
import EventContentDisplayer from '../EventContentDisplayer';
import { ANNOTATION, NOTIFICATION, EDIT_MODE, DOC_VIEW, EDIT_EVENT_CONTEXT, BASIC_EVENT_CONTEXT } from '../../../constants/EventTypes';
import { OverlayTrigger, Tooltip, Dropdown, MenuItem } from 'react-bootstrap';
import { ANNOTATION, NOTIFICATION, DOC_VIEW } from '../../../constants/EventTypes';
......
......@@ -24,6 +24,12 @@ class EventListMenu extends React.Component {
this.state = {
isNavbarExpanded: false
};
this.getSelectPickerData = this.getSelectPickerData.bind(this);
this.onSelectNavbar = this.onSelectNavbar.bind(this);
this.onToggleNavbar = this.onToggleNavbar.bind(this);
this.onSearch = this.onSearch.bind(this);
this.sortByDate = this.sortByDate.bind(this);
}
render() {
......@@ -66,18 +72,18 @@ class EventListMenu extends React.Component {
<Navbar.Collapse>
<Nav>
<NavItem eventKey={2} href="#" className="logbookNavItem" >
<DropdownButton onClick={(e) => { e.stopPropagation() }}
bsStyle={'primary'}
title={'View'}
bsSize='small'>
<MenuItem eventKey="1" onSelect={() => setView(DOC_VIEW)} > {view === DOC_VIEW ? <Radio checked> Classic (user's commented logs)</Radio> : <Radio checked={false}> Classic (user's commented logs)</Radio>} </MenuItem>
<MenuItem eventKey="2" onSelect={() => setView(LIST_VIEW)} > {view === LIST_VIEW ? <Radio checked> Full (all logs)</Radio> : <Radio checked={false}> Full (all logs)</Radio>} </MenuItem>
<MenuItem divider />
<MenuItem eventKey="3" onSelect={() => this.sortByDate(SORT_EVENTS_FROM_OLDEST)} > {getCurrentlyPressedSortButton() === SORT_EVENTS_FROM_OLDEST ? <Radio checked> Oldest log on top</Radio> : <Radio checked={false}> Oldest log on top</Radio>} </MenuItem>
<MenuItem eventKey="4" onSelect={() => this.sortByDate(SORT_EVENTS_FROM_YOUNGEST)} > {getCurrentlyPressedSortButton() === SORT_EVENTS_FROM_YOUNGEST ? <Radio checked> Latest log on top</Radio> : <Radio checked={false}> Latest log on top</Radio>} </MenuItem>
</DropdownButton>
</NavItem>
{/* <NavItem eventKey={2} href="#" className="logbookNavItem" > */}
<DropdownButton id='dropdownbuttonId' onClick={(e) => { e.stopPropagation() }}
bsStyle={'primary'}
title={'View'}
bsSize='small'>
<MenuItem eventKey="1" onSelect={() => setView(DOC_VIEW)} > {view === DOC_VIEW ? <Radio checked> Classic (user's commented logs)</Radio> : <Radio checked={false}> Classic (user's commented logs)</Radio>} </MenuItem>
<MenuItem eventKey="2" onSelect={() => setView(LIST_VIEW)} > {view === LIST_VIEW ? <Radio checked> Full (all logs)</Radio> : <Radio checked={false}> Full (all logs)</Radio>} </MenuItem>
<MenuItem divider />
<MenuItem eventKey="3" onSelect={() => this.sortByDate(SORT_EVENTS_FROM_OLDEST)} > {getCurrentlyPressedSortButton() === SORT_EVENTS_FROM_OLDEST ? <Radio checked> Oldest log on top</Radio> : <Radio checked={false}> Oldest log on top</Radio>} </MenuItem>
<MenuItem eventKey="4" onSelect={() => this.sortByDate(SORT_EVENTS_FROM_YOUNGEST)} > {getCurrentlyPressedSortButton() === SORT_EVENTS_FROM_YOUNGEST ? <Radio checked> Latest log on top</Radio> : <Radio checked={false}> Latest log on top</Radio>} </MenuItem>
</DropdownButton>
{/* </NavItem> */}
<NavItem eventKey={3} href={getPDF(sessionId, investigationId, selectionFilter)} target='_blank' className="logbookNavItem" >
<EventListMenuButton text='PDF' glyph='download' tooltipText='Download as PDF' isEnabled={!(isNewEventVisible === undefined || isNewEventVisible === true || numberOfMatchingEventsFound === 0)} />
</NavItem>
......
......@@ -258,7 +258,7 @@ class NewOrEditEventPanel extends React.Component {
NewOrEditEventPanel.propTypes = {
/* context in which this component is used */
context: PropTypes.oneOf({ NEW_EVENT_CONTEXT, EDIT_EVENT_CONTEXT }),
context: PropTypes.oneOf([ NEW_EVENT_CONTEXT, EDIT_EVENT_CONTEXT ]),
/* event to edit. Null when a new event is beaing created. */
event: PropTypes.object,
/* investigation identifier */
......
......@@ -2,7 +2,7 @@ import React, { Component } from 'react';
import PropTypes from 'prop-types'
import { connect } from 'react-redux';
import { bindActionCreators } from 'redux';
import { Grid, Row, Col, Tab, Glyphicon, Badge, Nav, NavItem } from 'react-bootstrap';
import { Grid, Row, Col, Tab, TabContainer, Glyphicon, Badge, Nav, NavItem } from 'react-bootstrap';
import DatasetTable from '../../components/Dataset/DatasetTable.js';
import { PERSPECTIVE } from '../../constants/Perspectives.js';
import { addDatasetById, removeDatasetById } from '../../actions/selection.js';
......@@ -139,7 +139,7 @@ class InvestigationContainer extends Component {
}
return (<Grid fluid>
<Tab.Container id="tabs" activeKey={this.state.activeTab} onSelect={this.handleSelect}>
<TabContainer id="tabs" activeKey={this.state.activeTab} onSelect={this.handleSelect}>
<Row >
<Col sm={12}>
<TabContainerMenu isLogBookTabDisplayed={!this.props.isDOI} datasetCount={this.props.datasets.data.length} />
......@@ -163,7 +163,7 @@ class InvestigationContainer extends Component {
</Tab.Content>
</Col>
</Row>
</Tab.Container>
</TabContainer>
</Grid>)
}
}
......
......@@ -45,6 +45,7 @@ class LogbookContainer extends React.Component {
view: LIST_VIEW,
};
this.getEvents = this.getEvents.bind(this);
this.isAppProperlyConfigured = this.isAppProperlyConfigured.bind(this);
this.onEventsReceptionFailure = this.onEventsReceptionFailure.bind(this);
this.onEventUpdated = this.onEventUpdated.bind(this);
......@@ -73,7 +74,7 @@ class LogbookContainer extends React.Component {
debugger;
return (
<div style={{ marginBottom: '40px' }}>
<OverlayBox open={this.state.errorMessage} onClose={() => { this.setState({ errorMessage: null }) }} classNames={{ modal: 'userMessageModalClass', closeButton: 'userMessageCloseButton' }}>
<OverlayBox open={this.state.errorMessage ? true : false} onClose={() => { this.setState({ errorMessage: null }) }} classNames={{ modal: 'userMessageModalClass', closeButton: 'userMessageCloseButton' }}>
<UserMessage type={ERROR_MESSAGE_TYPE} message={this.state.errorMessage} />
</OverlayBox>
......@@ -100,7 +101,7 @@ class LogbookContainer extends React.Component {
/>
</PeriodicRefresher>
<OverlayBox open={this.state.isNewEventVisible === true || (this.state.eventBeingEdited ? true : false)} classNames={{ overlay: 'newOrEditOverlayClass', modal: 'newOrEditModalClass' }}>
<OverlayBox open={this.state.isNewEventVisible === true || (this.state.eventBeingEdited ? true : false)} classNames={{ overlay: 'newOrEditOverlayClass', modal: 'newOrEditModalClass' }} onClose={() => null}>
<div style={{ height: this.getPanelHeightInPercent(NEW_EVENT_CONTEXT), paddingBottom: this.state.eventBeingEdited ? '5px' : '0px' }}>
{this.state.isNewEventVisible === true ?
<NewOrEditEventPanel
......@@ -218,8 +219,9 @@ class LogbookContainer extends React.Component {
};
//Get all events
this.setState({ eventReceptionStatus: 'fetching', isNewEventVisible: false });
const onSuccess = (data) => {
console.log(JSON.stringify(data.data))
this.setState({
downloadedEvents: data.data,
downloadedEventIndexes: {
......@@ -234,10 +236,10 @@ class LogbookContainer extends React.Component {
}
getEventsByInvestigationIdRequest(user.sessionId, investigationId, GUI_CONFIG().EVENTS_PER_DOWNLOAD, offset, selectionFilter, sortingFilter, onSuccess, this.onEventsReceptionFailure);
this.setState({ eventReceptionStatus: 'fetching', isNewEventVisible: false });
// then possibly get event count for the current active selection filter
if (isEventCountRequestNeeded) {
this.setState({ eventCountReceptionStatus: 'fetching' });
const onSuccess = (data) => {
this.setState({
foundEventCount: parseInt(data.data, 10),
......@@ -245,7 +247,6 @@ class LogbookContainer extends React.Component {
});
}
getEventCountByInvestigationIdRequest(investigationId, user.sessionId, selectionFilter, onSuccess, this.onEventsReceptionFailure);
this.setState({ eventCountReceptionStatus: 'fetching' });
}
// Then get count of all events in the logbook used for the autorefresh feature
......
......@@ -55,8 +55,8 @@ describe("NewlyAvailableEventsDialogue integration tests", () => {
it('refreshes the event list when the user clicks the refresh icon on the NewlyAvailableEventsDialogue', () => {
IORequestModule.getEventsByInvestigationId = jest.fn( async (sessionId, investigationId, limit, offset, selectionFilter, sortingFilter, onSuccess, onError) => {
await onSuccess({
IORequestModule.getEventsByInvestigationId = jest.fn((sessionId, investigationId, limit, offset, selectionFilter, sortingFilter, onSuccess, onError) => {
onSuccess({
data: [{
_id: 'testId1',
category: "comment",
......@@ -83,21 +83,85 @@ describe("NewlyAvailableEventsDialogue integration tests", () => {
})
});
IORequestModule.getEventCountByInvestigationId = jest.fn(async (investigationId, sessionId, selectionFilter, onSuccess, onEventsReceptionFailure) => {
await onSuccess({ data: '1' })
IORequestModule.getEventCountByInvestigationId = jest.fn((investigationId, sessionId, selectionFilter, onSuccess, onEventsReceptionFailure) => {
onSuccess({ data: '1' })
});
async function test() {
const wrapper = await getWrapper();
await wrapper.update();
await console.log(wrapper.debug());
await console.log(IORequestModule.getEventsByInvestigationId.mock.calls);
await console.log(IORequestModule.getEventsByInvestigationId.mock.results);
await console.log(wrapper.find('LogbookContainer').instance())
}
const wrapper = getWrapper();
wrapper.update();
expect(wrapper.find('Event')).toHaveLength(1); // thre is one event is the logbook to start with
// this simulate a click on the refresh glypgicon, and will add anther sa,e event in the event list
IORequestModule.getEventsByInvestigationId = jest.fn((sessionId, investigationId, limit, offset, selectionFilter, sortingFilter, onSuccess, onError) => {
onSuccess({
data: [{
_id: 'testId1',
category: "comment",
content: [
{ format: 'plainText', text: 'this is a test' },
{ format: 'html', text: '<p> this is a test </p>' }
],
createdAt: '2018-01-01T00:01:00.000Z',
creationDate: '2018-01-01T00:00:00.000Z',
datasetId: null,
file: [],
fileSize: null,
filename: null,
investigationId: 'testInvestigationId',
machine: null,
previousVersionEvent: null,
software: null,
tag: [],
title: 'test title',
type: "annotation",
updatedAt: "2018-01-01T00:00:00.000Z",
username: "mchaille"
}, {
_id: 'testId2',
category: "comment",
content: [
{ format: 'plainText', text: 'this is a test' },
{ format: 'html', text: '<p> this is a test </p>' }
],
createdAt: '2018-01-01T00:01:00.000Z',
creationDate: '2018-01-01T00:00:00.000Z',
datasetId: null,
file: [],
fileSize: null,
filename: null,
investigationId: 'testInvestigationId',
machine: null,
previousVersionEvent: null,
software: null,
tag: [],
title: 'test title',
type: "annotation",
updatedAt: "2018-01-01T00:00:00.000Z",
username: "mchaille"
}]
})
});
IORequestModule.getEventCountByInvestigationId = jest.fn((investigationId, sessionId, selectionFilter, onSuccess, onEventsReceptionFailure) => {
onSuccess({ data: '2' })
});
wrapper.find('EventListMenu').find('NewlyAvailableEventsDialogue').find('Glyphicon').simulate('click');
//console.log(wrapper.find('EventListMenu').find('NewlyAvailableEventsDialogue').find('Glyphicon').debug());
wrapper.update();
expect(wrapper.find('Event')).toHaveLength(2);
//console.log(wrapper.find('Event').debug());
//console.log(wrapper.find('LogbookContainer').instance())
// console.log(IORequestModule.getEventsByInvestigationId.mock.calls);
// console.log(IORequestModule.getEventsByInvestigationId.mock.results);
test()
// describe('testing callbacks', () => {
// it('onIConClicked', () => {
......
export const wait = (wrapper, predicate, timeout = 10) => {
return new Promise((resolve, reject) => {
if (predicate(wrapper)) {
return resolve(true);
}
setTimeout(() => {
wrapper.update();
return predicate(wrapper) ? resolve(true) : reject(new Error('Timeout expired'));
}, timeout);
});
};
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment