-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #18 from bindable-ui/timeline-webworkers
Web Workers for Timeline
- Loading branch information
Showing
7 changed files
with
353 additions
and
155 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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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,86 @@ | ||
import * as moment from 'moment'; | ||
|
||
import {filterEntriesDay, mapEntries} from './workers'; | ||
|
||
// Plop it right in the middle of the day | ||
const now = moment('12/12/2020', 'MM/DD/YYYY') | ||
.startOf('day') | ||
.add(12, 'hours'); | ||
const startDay = moment(now) | ||
.startOf('day') | ||
.toISOString(); | ||
const endDay = moment(now) | ||
.endOf('day') | ||
.toISOString(); | ||
|
||
const sortedEntries: any[] = [ | ||
{ | ||
duration: 240, | ||
start: now.toISOString(), | ||
}, | ||
{ | ||
duration: 120, | ||
start: moment(now) | ||
.add(3, 'minutes') | ||
.toISOString(), | ||
}, | ||
{ | ||
duration: 120, | ||
start: moment(now) | ||
.add(1, 'hour') | ||
.toISOString(), | ||
}, | ||
{ | ||
duration: 120, | ||
start: moment(now) | ||
.add(1, 'hour') | ||
.toISOString(), | ||
}, | ||
{ | ||
duration: 120, | ||
start: moment(now) | ||
.add(1, 'day') | ||
.toISOString(), | ||
}, | ||
]; | ||
|
||
describe('Web worker functions', () => { | ||
describe('#filterEntriesDay', () => { | ||
it('tests filtering entries for a day', async () => { | ||
const data = await filterEntriesDay(sortedEntries, startDay, endDay); | ||
|
||
expect(data.length).toBe(4); | ||
}); | ||
}); | ||
|
||
describe('#mapEntries', () => { | ||
it('tests formatting', async () => { | ||
const data = await mapEntries(sortedEntries, 2, startDay, endDay, 'day', '', now.toISOString()); | ||
|
||
expect(data[0].startTime).toBe('12:00'); | ||
expect(data[0].endTime).toBe('12:04'); | ||
}); | ||
|
||
it('tests positioning', async () => { | ||
const data = await mapEntries(sortedEntries, 2, startDay, endDay, 'day', '', now.toISOString()); | ||
|
||
expect(data[0].top).toBe(1441); | ||
expect(data[0].height).toBe(8); | ||
}); | ||
|
||
it('tests same time entries', async () => { | ||
const data = await mapEntries(sortedEntries, 2, startDay, endDay, 'day', '', now.toISOString()); | ||
|
||
expect(data[0].widthCalc).toBeUndefined(); | ||
expect(data[2].widthCalc).toBeDefined(); | ||
expect(data[3].widthCalc).toBeDefined(); | ||
}); | ||
|
||
it('tests nested entries', async () => { | ||
const data = await mapEntries(sortedEntries, 2, startDay, endDay, 'day', '', now.toISOString()); | ||
|
||
expect(data[0].widthCalc).toBeUndefined(); | ||
expect(data[1].widthCalc).toBeDefined(); | ||
}); | ||
}); | ||
}); |
Oops, something went wrong.