|
| 1 | +import { getStyledEvents } from '../../src/utils/DayEventLayout' |
| 2 | +import { getSlotMetrics } from '../../src/utils/TimeSlots' |
| 3 | +import dates from '../../src/utils/dates' |
| 4 | + |
| 5 | +describe('getStyledEvents', () => { |
| 6 | + const d = (...args) => new Date(2015, 3, 1, ...args) |
| 7 | + const min = dates.startOf(d(), 'day') |
| 8 | + const max = dates.endOf(d(), 'day') |
| 9 | + const slotMetrics = getSlotMetrics({ min, max, step: 30, timeslots: 4 }) |
| 10 | + |
| 11 | + describe('matrix', () => { |
| 12 | + function compare(title, events, expectedResults) { |
| 13 | + it(title, () => { |
| 14 | + const styledEvents = getStyledEvents({ |
| 15 | + events, |
| 16 | + startAccessor: 'start', |
| 17 | + endAccessor: 'end', |
| 18 | + slotMetrics, |
| 19 | + minimumStartDifference: 10, |
| 20 | + }) |
| 21 | + const results = styledEvents.map(result => ({ |
| 22 | + width: Math.floor(result.style.width), |
| 23 | + xOffset: Math.floor(result.style.xOffset), |
| 24 | + })) |
| 25 | + expect(results).toEqual(expectedResults) |
| 26 | + }) |
| 27 | + } |
| 28 | + |
| 29 | + const toCheck = [ |
| 30 | + [ |
| 31 | + 'single event', |
| 32 | + [{ start: d(11), end: d(12) }], |
| 33 | + [{ width: 100, xOffset: 0 }], |
| 34 | + ], |
| 35 | + [ |
| 36 | + 'two consecutive events', |
| 37 | + [ |
| 38 | + { start: d(11), end: d(11, 10) }, |
| 39 | + { start: d(11, 10), end: d(11, 20) }, |
| 40 | + ], |
| 41 | + [{ width: 100, xOffset: 0 }, { width: 100, xOffset: 0 }], |
| 42 | + ], |
| 43 | + [ |
| 44 | + 'two consecutive events too close together', |
| 45 | + [{ start: d(11), end: d(11, 5) }, { start: d(11, 5), end: d(11, 10) }], |
| 46 | + [{ width: 85, xOffset: 0 }, { width: 50, xOffset: 50 }], |
| 47 | + ], |
| 48 | + [ |
| 49 | + 'two overlapping events', |
| 50 | + [{ start: d(11), end: d(12) }, { start: d(11), end: d(12) }], |
| 51 | + [{ width: 85, xOffset: 0 }, { width: 50, xOffset: 50 }], |
| 52 | + ], |
| 53 | + [ |
| 54 | + 'three overlapping events', |
| 55 | + [ |
| 56 | + { start: d(11), end: d(12) }, |
| 57 | + { start: d(11), end: d(12) }, |
| 58 | + { start: d(11), end: d(12) }, |
| 59 | + ], |
| 60 | + [ |
| 61 | + { width: 56, xOffset: 0 }, |
| 62 | + { width: 56, xOffset: 33 }, |
| 63 | + { width: 33, xOffset: 66 }, |
| 64 | + ], |
| 65 | + ], |
| 66 | + [ |
| 67 | + 'one big event overlapping with two consecutive events', |
| 68 | + [ |
| 69 | + { start: d(11), end: d(12) }, |
| 70 | + { start: d(11), end: d(11, 30) }, |
| 71 | + { start: d(11, 30), end: d(12) }, |
| 72 | + ], |
| 73 | + [ |
| 74 | + { width: 85, xOffset: 0 }, |
| 75 | + { width: 50, xOffset: 50 }, |
| 76 | + { width: 50, xOffset: 50 }, |
| 77 | + ], |
| 78 | + ], |
| 79 | + [ |
| 80 | + 'one big event overlapping with two consecutive events starting too close together', |
| 81 | + [ |
| 82 | + { start: d(11), end: d(12) }, |
| 83 | + { start: d(11), end: d(11, 5) }, |
| 84 | + { start: d(11, 5), end: d(11, 10) }, |
| 85 | + ], |
| 86 | + [ |
| 87 | + { width: 56, xOffset: 0 }, |
| 88 | + { width: 56, xOffset: 33 }, |
| 89 | + { width: 33, xOffset: 66 }, |
| 90 | + ], |
| 91 | + ], |
| 92 | + ] |
| 93 | + toCheck.forEach(args => compare(...args)) |
| 94 | + }) |
| 95 | +}) |
0 commit comments