diff options
| author | Nick Van Doorn <vandoorn.nick@gmail.com> | 2019-04-05 15:04:36 -0700 |
|---|---|---|
| committer | Nick Van Doorn <vandoorn.nick@gmail.com> | 2019-04-05 15:04:36 -0700 |
| commit | 27baa97fb322fd6d7d56dc6e9c9d946868190e1d (patch) | |
| tree | e864531cac032d7cce48c0a11fadab0072ec8431 /src/use-sunlight.test.js | |
| parent | 3cb9cfa5c3b9401ed7cd4a7b8f5b4831f7027403 (diff) | |
Define deterministic tests
Diffstat (limited to 'src/use-sunlight.test.js')
| -rw-r--r-- | src/use-sunlight.test.js | 28 |
1 files changed, 24 insertions, 4 deletions
diff --git a/src/use-sunlight.test.js b/src/use-sunlight.test.js index e5708f2..9a862cc 100644 --- a/src/use-sunlight.test.js +++ b/src/use-sunlight.test.js @@ -1,15 +1,35 @@ -import { computeLightLevel } from './use-sunlight' // TODO figure out why this is required // (I'm assuming some transpiler magic // makes this "required") // eslint-disable-next-line import React from 'react' +import { addHours, addMinutes } from 'date-fns' + +import { computeLightLevel } from './use-sunlight' + +const DATE = new Date(2010, 8, 10) +const BC_FERRIES_SCHWARTZ_BAY = { + latitude: 48.6886, + longitude: 123.4114, + loading: false +} // Test the calculations used in the hook. // Not sure if it's worth testing the public hook // API test('computeLightLevel', () => { - expect( - computeLightLevel({ latitude: 0, longitude: 0, loading: false }) - ).toMatchSnapshot() + let max = 0 + for (let hour = 0; hour < 24; hour++) { + for (let minute = 0; minute < 60; minute++) { + const now = addMinutes(addHours(DATE, hour), minute) + const r = computeLightLevel(BC_FERRIES_SCHWARTZ_BAY, now) + expect(r).toMatchSnapshot() + if (r > max) max = r + } + } + // if we iterate over an + // entire day (minute by minute), + // we should see the max solar "height" + // at some point + expect(max).toBe(10) }) |
