Commit c8db32a3 authored by Maxime Chaillet's avatar Maxime Chaillet
parent 750176ef
......@@ -3,7 +3,7 @@ import PropTypes from 'prop-types'
import _ from 'lodash'
import Moment from 'moment'
import { Table, OverlayTrigger, Tooltip, Glyphicon, Button, Label } from 'react-bootstrap'
import { getContent, convertImagesToThumbnails } from '../../../helpers/EventHelpers';
import { getContent, convertImagesToThumbnails, getPreviousVersionNumber } from '../../../helpers/EventHelpers';
import { getOriginalEvent } from '../../../helpers/EventHelpers'
import EventIcon from './EventIcon.js';
import LazyLoad from 'react-lazyload';
......@@ -59,9 +59,9 @@ class EventList extends React.Component {
<tbody>
{this.getItems().map((event, index) => {
if (event.type === "date") {
return <tr><td style={{ borderTop: '1px solid #f2f2f2', textAlign: 'center', fontSize: '18px', fontWeight: 'bold' }} colSpan={3} ><a name={event.anchor}></a> {event.text}</td></tr>;
return <tr key={index}><td style={{ borderTop: '1px solid #f2f2f2', textAlign: 'center', fontSize: '18px', fontWeight: 'bold' }} colSpan={3} ><a name={event.anchor}></a> {event.text}</td></tr>;
}
return <Event event={event} onEventClicked={this.props.onEventClicked} ></Event>
return <Event key={index} event={event} onEventClicked={this.props.onEventClicked} ></Event>
})}
</tbody>
</Table>
......@@ -70,7 +70,9 @@ class EventList extends React.Component {
EventList.propTypes = {
/** the array of unsorted events as provided by the ICAT+ server */
events: PropTypes.array.isRequired
events: PropTypes.array.isRequired,
/** Callback function triggered when the user clicks the edit icon */
onEventCliked: PropTypes.func
}
export default EventList;
......@@ -100,9 +102,10 @@ class Event extends React.Component {
events = events.concat(this.props.event.events);
};
return events.map((event, index) => {
return <tr id='contentDocList'>
return <tr key={index} id='contentDocList'>
<td style={{ width: '16px', borderTop: '0' }}>
<EventIcon event={event} />
</td>
<td style={{ width: '16px', borderTop: '0', borderRight: '1px solid #f2f2f2' }}>
<OverlayTrigger placement="right" overlay={<Tooltip id="tooltip"> <p> Events created on {Moment(getOriginalEvent(event).creationDate).format("MMMM Do YYYY, h:mm:ss a")} </p> </Tooltip>}>
......@@ -115,7 +118,7 @@ class Event extends React.Component {
</td>
<td classNmae='eventActionBox' style={{ width: '50px', border: 0 }}>
<Button bsStyle="link" bsSize="small" style={{ padding: '0px' }} onClick={() => this.props.onEventClicked(event)}>
<Glyphicon glyph='edit' style={{ width: '40px', position:'static' }} />
<Glyphicon glyph={getPreviousVersionNumber(event) === 0 ? 'plus' : 'edit'} style={{ width: '40px', position: 'static' }} />
</Button>
</td>
</tr>;
......
......@@ -134,15 +134,15 @@ class LogbookContainer extends React.Component {
<UserMessage message='The logbook is empty.' type={INFO_MESSAGE_TYPE} isTextCentered={true} />
: <EventList
events={this.state.pageEvents}
investigationId={investigationId}
onEventUpdated={this.onEventUpdated}
// investigationId={investigationId}
// onEventUpdated={this.onEventUpdated}
onEventClicked={this.onEventClicked}
reloadEvents={this.downloadEvents}
reverseEventsSortingByCreationDate={this.reverseEventsSortingByCreationDate}
selectedEventId={this.state.selectedEventId}
updateEvent={this.updateEvent}
user={user}
view={this.state.view}
// reloadEvents={this.downloadEvents}
// reverseEventsSortingByCreationDate={this.reverseEventsSortingByCreationDate}
// selectedEventId={this.state.selectedEventId}
// updateEvent={this.updateEvent}
// user={user}
// view={this.state.view}
/>}
<EventPager
......
......@@ -65,7 +65,6 @@ export function getEventHistoryCreationDate(event) {
* @return {event} the original event. If there is no original event (ie the provided event is the original event) returns itself.
*/
export function getOriginalEvent(event) {
let e = event;
if (e) {
while (e.previousVersionEvent) {
......
import React from 'react'
import Enzyme from 'enzyme'
import Adapter from 'enzyme-adapter-react-16'
import EventList from '../src/components/Event/EventList';
import { LOGGED_IN } from '../src/constants/ActionTypes';
import { LIST_VIEW } from '../src/constants/EventTypes';
import { INFO_MESSAGE_TYPE } from '../src/constants/UserMessages';
import EventList from '../src/components/Event/List/EventList';
const resources = require('./resources/eventList.resource.js')
require('it-each')({ testPerIteration: true });
beforeEach(() => {
Enzyme.configure({ adapter: new Adapter() });
})
describe("EventList tests", () => {
describe("Tests on EventList component", () => {
describe("rendering", () => {
function getWrapper(events, view) {
function getShallowedWrapper(events) {
return Enzyme.shallow(<EventList
events={events}
investigationId="testInvestigationId"
onEventUpdated={() => null}
reloadEvents={() => null}
reverseEventsSortingByCreationDate={() => null}
user={{
type: LOGGED_IN,
username: 'username',
sessionId: 'sessionId'
}}
view={view}
/>)
onEventClicked={() => null}
/>
)
}
describe("there is no event", () => {
it("render a user message when there is no event in the logbook", () => {
let actualEvents = [];
let actualView = LIST_VIEW;
expect(getWrapper(actualEvents, actualView).find("UserMessage").prop("message")).toEqual("The logbook is currently empty.");
expect(getWrapper(actualEvents, actualView).find("UserMessage").prop("type")).toEqual(INFO_MESSAGE_TYPE);
})
})
describe("there are events", () => {
/**
* creates a new event object
* @param {*} id the event id
* @param {*} title the event title
* @param {*} creationDate the creation date
*/
function createEvent(id, title, creationDate) {
return ({
_id: id,
category: "comment",
content: [{
format: 'plainText',
text: 'this is a test'
}, {
format: 'html',
text: '<p> this is a test </p>'
}],
createdAt: creationDate, // was "2018-01-01T00:00:00.000Z"
creationDate: creationDate,
datasetId: null,
file: [],
fileSize: null,
filename: null,
investigationId: 'testInvestigationId',
machine: null,
previousVersionEvent: null,
software: null,
tag: [],
title: title,
type: "annotation",
updatedAt: "2018-01-01T00:00:00.000Z",
username: "mchaille"
})
}
function createEvents(amount) {
let events = []
for (let index = 1; index <= amount; index++) {
events.push(createEvent(index, "title" + index, new Date('0' + index + ' Jan 2018 00:00:00 GMT')));
}
return events;
}
it("renders events", () => {
let actualEvents = createEvents(2); // create 2 events
let actualView = LIST_VIEW;
expect(getWrapper(actualEvents, actualView).find("Event").length).toBe(2);
})
it("does not render the user message when there is no event", () => {
let actualEvents = createEvents(2); // create 2 events
let actualView = LIST_VIEW;
expect(getWrapper(actualEvents, actualView).find("UserMessage").length).toBe(0);
it.each(resources.rendering.editingIcon, '[note: %s ]', ['aboutThisTest'],
function (element, next) {
expect(getShallowedWrapper([element.event]).find('Event').dive().find('Glyphicon').prop('glyph')).toEqual(element.expected);
next();
})
})
// function getWrapper(events, view) {
// return Enzyme.shallow(<EventList
// events={events}
// investigationId="testInvestigationId"
// onEventUpdated={() => null}
// reloadEvents={() => null}
// reverseEventsSortingByCreationDate={() => null}
// user={{
// type: LOGGED_IN,
// username: 'username',
// sessionId: 'sessionId'
// }}
// view={view}
// />)
// }
// describe("there is no event", () => {
// it("render a user message when there is no event in the logbook", () => {
// let actualEvents = [];
// let actualView = LIST_VIEW;
// expect(getWrapper(actualEvents, actualView).find("UserMessage").prop("message")).toEqual("The logbook is currently empty.");
// expect(getWrapper(actualEvents, actualView).find("UserMessage").prop("type")).toEqual(INFO_MESSAGE_TYPE);
// })
// })
// describe("there are events", () => {
// /**
// * creates a new event object
// * @param {*} id the event id
// * @param {*} title the event title
// * @param {*} creationDate the creation date
// */
// function createEvent(id, title, creationDate) {
// return ({
// _id: id,
// category: "comment",
// content: [{
// format: 'plainText',
// text: 'this is a test'
// }, {
// format: 'html',
// text: '<p> this is a test </p>'
// }],
// createdAt: creationDate, // was "2018-01-01T00:00:00.000Z"
// creationDate: creationDate,
// datasetId: null,
// file: [],
// fileSize: null,
// filename: null,
// investigationId: 'testInvestigationId',
// machine: null,
// previousVersionEvent: null,
// software: null,
// tag: [],
// title: title,
// type: "annotation",
// updatedAt: "2018-01-01T00:00:00.000Z",
// username: "mchaille"
// })
// }
// function createEvents(amount) {
// let events = []
// for (let index = 1; index <= amount; index++) {
// events.push(createEvent(index, "title" + index, new Date('0' + index + ' Jan 2018 00:00:00 GMT')));
// }
// return events;
// }
// it("renders events", () => {
// let actualEvents = createEvents(2); // create 2 events
// let actualView = LIST_VIEW;
// expect(getWrapper(actualEvents, actualView).find("Event").length).toBe(2);
// })
// it("does not render the user message when there is no event", () => {
// let actualEvents = createEvents(2); // create 2 events
// let actualView = LIST_VIEW;
// expect(getWrapper(actualEvents, actualView).find("UserMessage").length).toBe(0);
// })
// })
})
})
\ No newline at end of file
module.exports = {
rendering: {
editingIcon: [
{
aboutThisTest: "editing icon is a + because the comment has no previous version",
event: {
_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"
},
expected: 'plus'
},
{
aboutThisTest: "editing icon is an edit because the comment has one previous version",
event: {
_id: 'testId2',
category: "comment",
content: [
{ format: 'plainText', text: 'this is an updated comment' },
{ format: 'html', text: '<p> this is an updated comment </p>' }
],
createdAt: '2018-01-02T00:01:00.000Z',
creationDate: '2018-01-02T00:00:00.000Z',
datasetId: null,
file: [],
fileSize: null,
filename: null,
investigationId: 'testInvestigationId',
machine: null,
previousVersionEvent: {
_id: 'testId1',
category: "comment",
content: [
{ format: 'plainText', text: 'this is a comment' },
{ format: 'html', text: '<p> this is a comment </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:01:00.000Z",
username: "mchaille"
},
software: null,
tag: [],
title: 'test title',
type: "annotation",
updatedAt: "2018-01-02T00:01:00.000Z",
username: "mchaille"
},
expected: 'edit'
}
]
}
}
\ 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