Last active
April 2, 2020 16:29
-
-
Save lallmon/19ed2fc5515862db7b54216ab9b1df66 to your computer and use it in GitHub Desktop.
Test Issue
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
import React, { useState, useEffect } from 'react'; | |
import Timeline from 'react-calendar-timeline'; | |
import 'react-calendar-timeline/lib/Timeline.css'; | |
import moment from 'moment'; | |
import { DefaultApi } from 'mpt_api'; | |
const MxTimeline = () => { | |
const [items, setItems] = useState(null); | |
const [groups, setGroups] = useState(null); | |
const apiInstance = new DefaultApi(); | |
const loadData = () => { | |
const opts = {}; | |
apiInstance.getEvents(opts).then(data => { | |
const bunos = data | |
.map(b => b.buno) | |
.filter((val, index, self) => self.indexOf(val) === index) | |
.map(val => ({ | |
id: val, | |
title: val, | |
})); | |
const events = data.map(event => ({ | |
id: event.id, | |
group: event.buno, | |
title: event.name, | |
mx_type: event.mxType, | |
start_time: moment(event.startDate), | |
end_time: moment(event.endDate), | |
itemProps: { | |
style: { | |
background: 'gray', | |
}, | |
}, | |
})); | |
setGroups(bunos); | |
setItems(events); | |
}); | |
}; | |
useEffect(() => { | |
loadData(); | |
}, []); | |
return ( | |
<div className="mx-timeline"> | |
{groups && items && ( | |
<Timeline | |
groups={groups} | |
items={items} | |
defaultTimeStart={moment().add(-15, 'day')} | |
defaultTimeEnd={moment().add(15, 'day')} | |
stackItems | |
/> | |
)} | |
</div> | |
); | |
}; | |
export default MxTimeline; |
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
import React from 'react'; | |
import MxTimeline from '../MxTimeline'; | |
import { render } from '@testing-library/react'; | |
import { DefaultApi } from 'mpt_api' | |
jest.mock('mpt_api'); | |
describe('<MxTimeline />', () => { | |
it('return a mock api response', () => { | |
const apiInstance = new DefaultApi; | |
apiInstance.getEvents.mockResolvedValueOnce({}); | |
render(<MxTimeline />); | |
expect(apiInstance.getEvents).toHaveBeenCalledTimes(1); | |
//expect(jest.isMockFunction(getEvents)).toBeTruthy(); | |
//return apiInstance.getEvents({}).then(data => expect(data).toEqual({})); | |
}) | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment