-
Notifications
You must be signed in to change notification settings - Fork 2.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
…910) * fix minimum start difference for same row computation (#886) (#909) * Add tests for DayEventLayout * Fix eslint on DayEventLayout
- Loading branch information
Showing
3 changed files
with
106 additions
and
6 deletions.
There are no files selected for viewing
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
import { getStyledEvents } from '../../src/utils/DayEventLayout' | ||
import { getSlotMetrics } from '../../src/utils/TimeSlots' | ||
import dates from '../../src/utils/dates' | ||
|
||
describe('getStyledEvents', () => { | ||
const d = (...args) => new Date(2015, 3, 1, ...args) | ||
const min = dates.startOf(d(), 'day') | ||
const max = dates.endOf(d(), 'day') | ||
const slotMetrics = getSlotMetrics({ min, max, step: 30, timeslots: 4 }) | ||
|
||
describe('matrix', () => { | ||
function compare(title, events, expectedResults) { | ||
it(title, () => { | ||
const styledEvents = getStyledEvents({ | ||
events, | ||
startAccessor: 'start', | ||
endAccessor: 'end', | ||
slotMetrics, | ||
minimumStartDifference: 10, | ||
}) | ||
const results = styledEvents.map(result => ({ | ||
width: Math.floor(result.style.width), | ||
xOffset: Math.floor(result.style.xOffset), | ||
})) | ||
expect(results).toEqual(expectedResults) | ||
}) | ||
} | ||
|
||
const toCheck = [ | ||
[ | ||
'single event', | ||
[{ start: d(11), end: d(12) }], | ||
[{ width: 100, xOffset: 0 }], | ||
], | ||
[ | ||
'two consecutive events', | ||
[ | ||
{ start: d(11), end: d(11, 10) }, | ||
{ start: d(11, 10), end: d(11, 20) }, | ||
], | ||
[{ width: 100, xOffset: 0 }, { width: 100, xOffset: 0 }], | ||
], | ||
[ | ||
'two consecutive events too close together', | ||
[{ start: d(11), end: d(11, 5) }, { start: d(11, 5), end: d(11, 10) }], | ||
[{ width: 85, xOffset: 0 }, { width: 50, xOffset: 50 }], | ||
], | ||
[ | ||
'two overlapping events', | ||
[{ start: d(11), end: d(12) }, { start: d(11), end: d(12) }], | ||
[{ width: 85, xOffset: 0 }, { width: 50, xOffset: 50 }], | ||
], | ||
[ | ||
'three overlapping events', | ||
[ | ||
{ start: d(11), end: d(12) }, | ||
{ start: d(11), end: d(12) }, | ||
{ start: d(11), end: d(12) }, | ||
], | ||
[ | ||
{ width: 56, xOffset: 0 }, | ||
{ width: 56, xOffset: 33 }, | ||
{ width: 33, xOffset: 66 }, | ||
], | ||
], | ||
[ | ||
'one big event overlapping with two consecutive events', | ||
[ | ||
{ start: d(11), end: d(12) }, | ||
{ start: d(11), end: d(11, 30) }, | ||
{ start: d(11, 30), end: d(12) }, | ||
], | ||
[ | ||
{ width: 85, xOffset: 0 }, | ||
{ width: 50, xOffset: 50 }, | ||
{ width: 50, xOffset: 50 }, | ||
], | ||
], | ||
[ | ||
'one big event overlapping with two consecutive events starting too close together', | ||
[ | ||
{ start: d(11), end: d(12) }, | ||
{ start: d(11), end: d(11, 5) }, | ||
{ start: d(11, 5), end: d(11, 10) }, | ||
], | ||
[ | ||
{ width: 56, xOffset: 0 }, | ||
{ width: 56, xOffset: 33 }, | ||
{ width: 33, xOffset: 66 }, | ||
], | ||
], | ||
] | ||
toCheck.forEach(args => compare(...args)) | ||
}) | ||
}) |