-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
105 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,24 @@ | ||
import { formatAPITime } from './utils'; | ||
import { formatAPITime, parseAPITime } from './utils'; | ||
|
||
describe('formatAPITime', () => { | ||
test('matches api format', () => { | ||
const d = new Date(2020, 1, 2); | ||
expect(formatAPITime(d)).toBe('20200202'); | ||
}); | ||
}); | ||
|
||
describe('parseAPITime', () => { | ||
test('default', () => { | ||
const d = new Date(2020, 1, 2); | ||
expect(parseAPITime(20200202).valueOf()).toBe(d.valueOf()); | ||
}); | ||
test('round trip', () => { | ||
const d = new Date(2020, 5, 8); | ||
expect(parseAPITime(formatAPITime(d)).valueOf()).toBe(d.valueOf()); | ||
}); | ||
test('strip to date', () => { | ||
const d = new Date(2020, 5, 8, 5, 2); | ||
const day = new Date(2020, 5, 8); | ||
expect(parseAPITime(formatAPITime(d)).valueOf()).toBe(day.valueOf()); | ||
}); | ||
}); |
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,20 @@ | ||
import { resolveColorScale, DEFAULT_COLOR_SCALE } from './colorScales'; | ||
import { interpolateBlues } from 'd3-scale-chromatic'; | ||
|
||
describe('colorScales', () => { | ||
test('default', () => { | ||
expect(typeof resolveColorScale()).toBe('function'); | ||
expect(typeof resolveColorScale()(0.5)).toBe('string'); | ||
expect(resolveColorScale()).toBe(DEFAULT_COLOR_SCALE); | ||
}); | ||
test('named', () => { | ||
expect(resolveColorScale('interpolateBlues')).toBe(interpolateBlues); | ||
}); | ||
test('invalid name', () => { | ||
expect(resolveColorScale('interpolateBluesX')).toBe(DEFAULT_COLOR_SCALE); | ||
}); | ||
test('function', () => { | ||
const v = () => 'red'; | ||
expect(resolveColorScale(v)).toBe(v); | ||
}); | ||
}); |
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,29 @@ | ||
/// <reference types="jest" /> | ||
import { defaultSensorId, EPIDATA_CASES_OR_DEATH_VALUES, getLevelInfo, sensorList } from './constants'; | ||
|
||
describe('defaultSensorId', () => { | ||
test('matches', () => { | ||
expect(defaultSensorId).toBe('doctor-visits'); | ||
}); | ||
}); | ||
|
||
describe('sensorList', () => { | ||
test.each(sensorList.map((d) => [d]))('has structure %s', (sensor) => { | ||
expect(typeof sensor.key).toBe('string'); | ||
expect(typeof sensor.name).toBe('string'); | ||
if (sensor.isCasesOrDeath) { | ||
expect(Object.keys(sensor.casesOrDeathSignals)).toEqual(EPIDATA_CASES_OR_DEATH_VALUES); | ||
} | ||
}); | ||
}); | ||
|
||
describe('getLevelInfo', () => { | ||
test('existing', () => { | ||
expect(getLevelInfo('county').id).toBe('county'); | ||
expect(getLevelInfo('county').label).toBe('County'); | ||
}); | ||
test('invalid', () => { | ||
expect(getLevelInfo('test').id).toBe('test'); | ||
expect(getLevelInfo('test').label).toBe('TEST'); | ||
}); | ||
}); |
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,33 @@ | ||
import { getTextColorBasedOnBackground, zip } from './util'; | ||
import { rgb } from 'd3-color'; | ||
|
||
describe('getTextColorBasedOnBackground', () => { | ||
test('white text on black bg', () => { | ||
expect(rgb(getTextColorBasedOnBackground('black')).formatHex()).toBe('#ffffff'); | ||
}); | ||
test('black text on dark grey bg', () => { | ||
expect(rgb(getTextColorBasedOnBackground('darkgrey')).formatHex()).toBe('#000000'); | ||
}); | ||
test('black text on white bg', () => { | ||
expect(rgb(getTextColorBasedOnBackground('white')).formatHex()).toBe('#000000'); | ||
}); | ||
}); | ||
|
||
describe('zip', () => { | ||
test('simple', () => { | ||
expect(zip([0, 1, 2], [1, 2, 4])).toEqual([ | ||
[0, 1], | ||
[1, 2], | ||
[2, 4], | ||
]); | ||
expect(zip([0, 1, 2], [1, 2])).toEqual([ | ||
[0, 1], | ||
[1, 2], | ||
[2, undefined], | ||
]); | ||
expect(zip([0, 1], [1, 2, 3])).toEqual([ | ||
[0, 1], | ||
[1, 2], | ||
]); | ||
}); | ||
}); |