Commit 934059ab authored by Alejandro De Maria Antolinos's avatar Alejandro De Maria Antolinos
Browse files

Removed tests that has changed or disappeared

parent 16dad433
Pipeline #47533 passed with stage
in 3 minutes and 27 seconds
import Enzyme from 'enzyme';
import Adapter from 'enzyme-adapter-react-16';
import React from 'react';
import EventListMenu from '../../components/Logbook/Menu/EventListMenu';
const resources = require('./resources/EventListMenu.resource.js');
require('it-each')({ testPerIteration: true });
beforeEach(() => {
Enzyme.configure({ adapter: new Adapter() });
});
describe('EventListMenu unit tests', () => {
describe('renderingButtons', () => {
it.each(
resources.renderingButtons,
'%s',
['description'],
(element, next) => {
const NewButtonWrapper = getShallowWrapper({
isNewButtonEnabled: element.isNewButtonEnabled,
logbookContext: element.logbookContext,
eventCountBySelectionFilter: element.eventCountBySelectionFilter,
}).findWhere((n) => n.prop('text') === element.text);
expect(NewButtonWrapper.prop('isEnabled')).toEqual(
element.expected.isEnabled
);
if (element.text === 'New ' || element.text === 'Take a photo') {
expect(NewButtonWrapper.prop('isVisible')).toEqual(
element.expected.isVisible
);
}
next();
}
);
});
});
function getShallowWrapper(params) {
if (params) {
let { activePage, availableTags } = params;
let { eventCountBySelectionFilter, eventCountSinceLastRefresh } = params;
let { getEvents, investigationId, isNewButtonEnabled } = params;
let {
isSortingLatestEventsFirst,
automaticRefresh,
automaticCollapsing,
logbookContext,
} = params;
let { onPageClicked } = params;
let { filterEvents, searchEvents } = params;
let { selectionFilter, sessionId, setNewEventVisibility } = params;
activePage = activePage || 1;
availableTags = availableTags || [];
eventCountBySelectionFilter = eventCountBySelectionFilter || 0;
eventCountSinceLastRefresh = eventCountSinceLastRefresh || 0;
getEvents = getEvents || nullFunction;
investigationId = investigationId || 123456;
isNewButtonEnabled = !(isNewButtonEnabled === false);
isSortingLatestEventsFirst = isSortingLatestEventsFirst || true;
logbookContext = logbookContext || {
name: null,
isReleased: null,
};
automaticCollapsing = automaticCollapsing || true;
automaticRefresh = automaticRefresh || false;
onPageClicked = onPageClicked || nullFunction;
searchEvents = searchEvents || nullFunction;
selectionFilter = selectionFilter || {};
sessionId = sessionId || 'sessionIdForTests';
setNewEventVisibility = setNewEventVisibility || nullFunction;
filterEvents = filterEvents || nullFunction;
return Enzyme.shallow(
<EventListMenu
activePage={activePage}
availableTags={availableTags}
eventCountBySelectionFilter={eventCountBySelectionFilter}
eventCountSinceLastRefresh={eventCountSinceLastRefresh}
getEvents={getEvents}
investigationId={investigationId}
isNewButtonEnabled={isNewButtonEnabled}
isSortingLatestEventsFirst={isSortingLatestEventsFirst}
logbookContext={logbookContext}
onPageClicked={onPageClicked}
searchEvents={searchEvents}
selectionFilter={selectionFilter}
sessionId={sessionId}
setNewEventVisibility={setNewEventVisibility}
filterEvents={filterEvents}
automaticCollapsing={automaticCollapsing}
automaticRefresh={automaticRefresh}
/>
);
}
}
function nullFunction() {
return null;
}
import Enzyme from 'enzyme';
import Adapter from 'enzyme-adapter-react-16';
import React from 'react';
import axios from 'axios';
import { ANNOTATION } from '../../constants/eventTypes';
import getUIConfiguration from '../uiConfig';
import JestMockPromise from 'jest-mock-promise';
import { act } from 'react-dom/test-utils';
require('it-each')({ testPerIteration: true });
const resources = require('./resources/EventsProvider.resource.js');
beforeEach(() => {
Enzyme.configure({ adapter: new Adapter() });
});
describe('EventsProviderUnitTests', () => {
describe('Rendering', () => {
it.each(
resources.renderingLoadingAnimation,
'Renders an animation when user changes the page: %s',
['description'],
async (element, next) => {
const {
config,
getEventResponse,
isAnimationVisible,
clickedPage,
} = element;
configure(config);
let getEventPromise = Promise.resolve({ data: getEventResponse });
axios.post = () => getEventPromise;
let wrapper = null;
await act(async () => {
wrapper = getWrapper({});
await getEventPromise;
});
wrapper.update();
expect(wrapper.exists('Loader')).toBe(false);
expect(wrapper.exists('FakeEventList')).toBe(true);
getEventPromise = new JestMockPromise();
axios.post = () => getEventPromise;
// Click on a page
act(() => {
wrapper.setProps({ page: clickedPage });
});
wrapper.update();
// check that loading animation is rendered
expect(wrapper.exists('Loader')).toBe(isAnimationVisible);
expect(wrapper.exists('FakeEventList')).toBe(!isAnimationVisible);
// Once received, check that event list is rendered and loading animation not
if (isAnimationVisible) {
act(() => {
getEventPromise.resolve({ data: getEventResponse });
});
wrapper.update();
expect(wrapper.exists('Loader')).toBe(false);
expect(wrapper.exists('FakeEventList')).toBe(true);
}
next();
}
);
it.each(
resources.renderingEvents,
'It renders events: %s',
['description'],
async (element, next) => {
const {
config,
getEventsResponseOnStartingPage,
getEventsResponseForClickedPage,
startingPage,
clickedPage,
expected,
} = element;
const {
eventsOnStartingPage,
eventsOnClickedPage,
getEventsCallsCount,
} = expected;
configure(config);
let getEventsPromise = Promise.resolve({
data: getEventsResponseOnStartingPage,
});
const mockedAxiosPost = jest.fn(() => getEventsPromise);
axios.post = mockedAxiosPost;
let wrapper = null;
await act(async () => {
wrapper = getWrapper({ page: startingPage });
await getEventsPromise;
});
wrapper.update();
// Checks events before changing the page
expect(wrapper.find('FakeEventList').prop('events')).toEqual(
eventsOnStartingPage
);
mockedAxiosPost.mockClear(); // forget initial axios call at initialization
// Change the page
await act(async () => {
wrapper.setProps({ page: clickedPage });
getEventsPromise = Promise.resolve({
data: getEventsResponseForClickedPage,
});
if (getEventsResponseForClickedPage) {
await getEventsPromise;
}
});
wrapper.update();
// Check that no additional request is triggered when events are available locally
expect(mockedAxiosPost).toHaveBeenCalledTimes(getEventsCallsCount);
// Check events after changing the page
expect(wrapper.find('FakeEventList').prop('events')).toEqual(
eventsOnClickedPage
);
if (config.AUTOREFRESH_EVENTLIST) {
mockedAxiosPost.mockClear();
getEventsPromise = Promise.resolve({
data: getEventsResponseForClickedPage,
});
await act(async () => {
wrapper.setProps({ forceReload: true });
await getEventsPromise;
});
wrapper.update();
// Check events after reload
expect(wrapper.find('FakeEventList').prop('events')).toEqual(
eventsOnClickedPage
);
expect(mockedAxiosPost).toHaveBeenCalledTimes(1);
}
next();
}
);
});
});
/**
* Get the wrapper of the logbook
* @param {Object} props provided to the logbook
*/
function getWrapper(props) {
let { forceReload, investigationId, page, setErrorMessage } = props;
let { sessionId, searchCriteria, categoryTypes, sortingFilter } = props;
if (props) {
page = page || 1;
investigationId = investigationId || 123456;
sessionId = sessionId || 'sessionId';
setErrorMessage = setErrorMessage ? setErrorMessage : () => null;
sortingFilter = sortingFilter || { _id: -1 };
forceReload = forceReload || false;
searchCriteria = searchCriteria || [];
categoryTypes = categoryTypes || [{ type: ANNOTATION }];
const FakeEventList = function () {
return <div> </div>;
};
let EventsProvider = null;
jest.isolateModules(() => {
EventsProvider = require('../../containers/Logbook/EventsProvider')
.default;
});
return Enzyme.mount(
<EventsProvider
page={page}
investigationId={investigationId}
sessionId={sessionId}
sortingFilter={sortingFilter}
setErrorMessage={setErrorMessage}
searchCriteria={searchCriteria}
categoryTypes={categoryTypes}
forceReload={forceReload}
>
{(events) => <FakeEventList events={events} />}
</EventsProvider>
);
}
}
/** Overload the configuration file used for tests defined in uiConfig.js
* @param {object} config configuration object which will overload default configuration parameters
*/
function configure(config) {
//Since mockGetUIConfiguration is out of scope of jest.mock(), it must start with 'mock'.
const mockGetUIConfiguration = getUIConfiguration(config);
jest.mock('../../config/ui', () => mockGetUIConfiguration);
}
import Enzyme from 'enzyme';
import Adapter from 'enzyme-adapter-react-16';
import React from 'react';
import { LOGGED_IN } from '../../constants/actionTypes';
import { LOGBOOK_CONTAINER_CONTEXT } from '../../constants/eventTypes';
import getUIConfiguration from '../uiConfig';
require('it-each')({ testPerIteration: true });
const resources = require('./resources/LogbookContainer.resource.js');
beforeEach(() => {
Enzyme.configure({ adapter: new Adapter() });
jest.resetModules();
});
/* In these tests, redux store is not used. Tests involving the redux store should go in integration tests folder*/
describe('LogbookContainerUnitTests', () => {
describe('Rendering', () => {
it.each(
resources.rendering.eventList,
'[It renders eventlist: %s ]',
['description'],
async (element, next) => {
const { getEventCountResponse, expected, logbookContext } = element;
const getEventCountPromise = Promise.resolve(getEventCountResponse);
const wrapper = await initializeContainer(
{ AUTOREFRESH_EVENTLIST: false },
getEventCountPromise,
{ logbookContext }
);
expect(wrapper.exists('EventsProvider')).toBe(expected);
next();
}
);
});
});
/**
* Get the shallow wrapper of the logbook
* @param {Object} props provided to the logbook
*/
function getShallowWrapper(props) {
if (props) {
props.availableTags = props.availableTags ? props.availableTags : [];
props.clearAvailableTags = props.clearAvailableTags
? props.clearAvailableTags
: () => null;
props.logbookContext = props.logbookContext
? props.logbookContext
: { name: LOGBOOK_CONTAINER_CONTEXT, isReleased: false };
props.setLogbookContext = props.setLogbookContext
? props.setLogbookContext
: () => null;
props.user = props.user
? props.user
: { type: LOGGED_IN, username: 'username', sessionId: 'sessionId' };
props.automaticCollapsing = props.automaticCollapsing
? props.automaticCollapsing
: true;
props.automaticRefresh = props.automaticRefresh
? props.automaticRefresh
: false;
props.isSortingLatestEventsFirst = props.isSortingLatestEventsFirst
? props.isSortingLatestEventsFirst
: true;
const LogbookContainer = require('../../containers/Logbook/LogbookContainer')
.LogbookContainerClass;
return Enzyme.shallow(
<LogbookContainer
investigation={{ id: 123456, releaseDate: '2020-09-30T15:37:31.421Z' }}
/* redux props (redux not used here) */
availableTags={props.availableTags}
clearAvailableTags={props.clearAvailableTags}
logbookContext={props.logbookContext}
setLogbookContext={props.setLogbookContext}
user={props.user}
automaticCollapsing={props.automaticCollapsing}
automaticRefresh={props.automaticRefresh}
isSortingLatestEventsFirst={props.isSortingLatestEventsFirst}
/>
);
}
}
/**
* Iniitalize the logbook container.
* @param {object} config an object which can contain all the configuration parameters defined in src/config/ui.js file
* which needs to be specifically setup for the test. What is not setup has default values defined in src/tests/uiConfig.js
* @param {*} getEventCountPromise promise used to get fake event count from the server when mounting
* @param {*} props logbookContainer props
*/
async function initializeContainer(config, getEventCountPromise, props) {
//Since mockGetUIConfiguration is out of scope of jest.mock(), it must start with 'mock'.
const mockGetUIConfiguration = getUIConfiguration(config);
jest.mock('../../config/ui', () => mockGetUIConfiguration);
// require logbook class after the configuration mocking
const LogbookContainerClass = require('../../containers/Logbook/LogbookContainer')
.LogbookContainerClass;
LogbookContainerClass.prototype.getEventCountBySelectionFilter = jest.fn(
() => getEventCountPromise
);
const wrapper = getShallowWrapper(props);
await getEventCountPromise;
wrapper.update();
return wrapper;
}
import React from 'react';
import Enzyme from 'enzyme';
import Adapter from 'enzyme-adapter-react-16';
import NewOrEditEventPanel from '../../components/Logbook/NewOrEditEventPanel';
const resources = require('./resources/NewOrEditEventPanel.resource.js');
require('it-each')({ testPerIteration: true });
/* code executed before each test */
beforeEach(() => {
Enzyme.configure({ adapter: new Adapter() });
});
describe('NewOrEditEventPanelUnitTests', () => {
describe('rendering', () => {
it.each(
resources.renderingEventHeader,
'%s',
['description'],
(element, next) => {
expect(
getShallowedWrapper({ event: element.event })
.find('PanelHeading')
.find('b')
.text()
).toEqual(element.expected);
next();
}
);
it.each(
resources.renderingEditorWrapper,
'%s',
['description'],
(element, next) => {
expect(
getShallowedWrapper({
event: element.event,
investigationId: element.investigationId,
user: element.user,
})
.find('EditorWrapper')
.prop('event')
).toEqual(element.event);
expect(
getShallowedWrapper({
event: element.event,
investigationId: element.investigationId,
user: element.user,
})
.find('EditorWrapper')
.prop('investigationId')
).toEqual(element.investigationId);
expect(
getShallowedWrapper({
event: element.event,
investigationId: element.investigationId,
user: element.user,
})
.find('EditorWrapper')
.prop('user')
).toEqual(element.user);
next();
}
);
it.each(
resources.renderingAuthorAndTime,
'%s',
['description'],
(element, next) => {
expect(
getShallowedWrapper({ event: element.event })
.find('AuthorAndTime')
.prop('event')
).toEqual(element.event);
next();
}
);
it.each(
resources.renderingTagContainer,
'%s',
['description'],
(element, next) => {
if (element.event) {
expect(
getShallowedWrapper({
event: element.event,
investigationId: element.investigationId,
})
.find('Connect(TagsSelectorContainer)')
.prop('tags')
).toEqual(element.event.tag);
} else {
expect(
getShallowedWrapper({
event: element.event,
investigationId: element.investigationId,
})
.find('Connect(TagsSelectorContainer)')
.prop('tags')
).toEqual([]);
}
expect(
getShallowedWrapper({
event: element.event,
investigationId: element.investigationId,
})
.find('Connect(TagsSelectorContainer)')
.prop('investigationId')
).toEqual(element.investigationId);
next();
}
);
it.each(
resources.renderingEventFooter,
'%s',
['description'],
(element, next) => {
expect(
getShallowedWrapper({
context: element.context,
event: element.event,
}).find('EventFooter')
).toBeDefined();
next();
}
);
});
describe('testFunctionalProps', () => {
// The following feature has been desactivated for the time being
// test("onSaveButtonClicked() is called when the user clicks on 'save' button during edition", () => {
// let resource = resources.testFunctionalProps;
// let mockedOnSaveButtonClicked = jest.fn();
// let wrapper = getShallowedWrapper({ event: resource.event, investigationId: resource.investigationId, onSaveButtonClicked: mockedOnSaveButtonClicked, user: resource.user });
// expect(mockedOnSaveButtonClicked).toHaveBeenCalledTimes(0);
// wrapper.find("EventFooter").dive().find({ children: "Save" }).simulate("click");
// expect(mockedOnSaveButtonClicked).toHaveBeenCalledTimes(1);
// expect(mockedOnSaveButtonClicked).toHaveBeenCalledWith({
// _id: resource.event._id,
// category: resource.event.category,
// content: expect.anything(),
// creationDate: expect.anything(),
// type: resource.event.type,
// tag: resource.event.tag,
// title: resource.event.title,
// username: resource.user.username,
// previousVersionEvent: resource.event._id,
// });
// });
});
});
/**
* Get a shallowed wrapper
*/
function getShallowedWrapper(propsObject) {
return Enzyme.shallow(
<NewOrEditEventPanel
event={propsObject.event}
investigationId={
propsObject.investigationId
? propsObject.investigationId