summaryrefslogtreecommitdiff
path: root/src/use-sunlight.test.js
diff options
context:
space:
mode:
Diffstat (limited to 'src/use-sunlight.test.js')
-rw-r--r--src/use-sunlight.test.js28
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)
})