Commit 38f7cf50 authored by Maxime Chaillet's avatar Maxime Chaillet

clean the code

parent a66b07aa
......@@ -10,18 +10,11 @@ import reducer from '../../src/reducers'
import promise from "redux-promise-middleware"
import { LOGGED_IN } from '../../src/constants/ActionTypes';
import { GUI_CONFIG } from '../../src/config/gui.config';
//import NewlyAvailableEventsDialogue from '../../src/components/Logbook/Menu/NewlyAvailableEventsDialogue';
//import { getEventsByInvestigationId } from '../../src/containers/Logbook/IORequests';
const IORequestModule = require('../../src/containers/Logbook/IORequests')
import LogbookContainer from '../../src/containers/Logbook/LogbookContainer';
//jest.mock("../../src/containers/Logbook/LogbookContainer");
//const resources = require('../resources/newlyAvailableEventsDialogue.resource.js')
jest.mock("../../src/config/gui.config");
import LogbookContainer from '../../src/containers/Logbook/LogbookContainer';
require('it-each')({ testPerIteration: true });
const IORequestModule = require('../../src/containers/Logbook/IORequests')
const resources = require('./resources/NewlyAvailableEventsDialogue.resource.js');
beforeEach(() => {
Enzyme.configure({ adapter: new Adapter() })
......@@ -54,122 +47,31 @@ describe("NewlyAvailableEventsDialogue integration tests", () => {
};
it('refreshes the event list when the user clicks the refresh icon on the NewlyAvailableEventsDialogue', () => {
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"
}]
})
onSuccess(resources.refreshEventList.serverResponse1);
});
IORequestModule.getEventCountByInvestigationId = jest.fn((investigationId, sessionId, selectionFilter, onSuccess, onEventsReceptionFailure) => {
onSuccess({ data: '1' })
onSuccess(resources.refreshEventList.serverResponse2);
});
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
// Initialisation of the container. There is one event in the event lsit returned by the server
expect(wrapper.find('Event')).toHaveLength(1);
// Here we simulate that a new event was created. So the server returns 2 events
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"
}]
})
onSuccess(resources.refreshEventList.serverResponse3)
});
IORequestModule.getEventCountByInvestigationId = jest.fn((investigationId, sessionId, selectionFilter, onSuccess, onEventsReceptionFailure) => {
onSuccess({ data: '2' })
onSuccess(resources.refreshEventList.serverResponse4)
});
// Simulate a click on the refresh glyphicon
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);
// describe('testing callbacks', () => {
// it('onIConClicked', () => {
// const wrapper = getShallowedWrapper(0, null);
// expect(wrapper.instance().props.onIconClicked).toHaveBeenCalledTimes(0);
// wrapper.find('Glyphicon').simulate('click');
// expect(wrapper.instance().props.onIconClicked).toHaveBeenCalledTimes(1);
// })
// })
expect(wrapper.find('Event')).toHaveLength(2);
})
});
\ No newline at end of file
module.exports = {
refreshEventList: {
serverResponse1: {
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"
}]
},
serverResponse2: { data: '1' },
serverResponse3: {
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"
}]
},
serverResponse4: { data: '2' }
}
}
\ 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