-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest.js
84 lines (64 loc) · 1.8 KB
/
test.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
#! /usr/bin/env node
import expect from 'expect'
import { timer, pomodoro } from './modules/stores'
// should sum 1 second the each new call
const testUpdateTimer = () => {
const stateBefore = { minutes: 0, seconds: 0 }
const stateAfter = { minutes: 0, seconds: 1 }
const action = { type: 'UPDATE' }
expect(
timer(stateBefore, action)
).toEqual(stateAfter)
}
// should add 1 minute when to arrive in 60 seconds
const testUpdateTimerMinute = () => {
const stateBefore = { minutes: 0, seconds: 59 }
const stateAfter = { minutes: 1, seconds: 0 }
const action = { type: 'UPDATE' }
expect(
timer(stateBefore, action)
).toEqual(stateAfter)
}
// should zero timer when reset
const testResetTimer = () => {
const stateBefore = { minutes: 0, seconds: 59 }
const stateAfter = { minutes: 0, seconds: 0 }
const action = { type: 'RESET' }
expect(
timer(stateBefore, action)
).toEqual(stateAfter)
}
// should init timer when stop
const testStartTimer = () => {
const stateBefore = { start: false }
const stateAfter = { start: true }
const action = { type: 'START' }
expect(
pomodoro(stateBefore, action)
).toEqual(stateAfter)
}
// should restart timer when start
const testRestartTimer = () => {
const stateBefore = { start: true }
const stateAfter = { start: true }
const action = { type: 'START' }
expect(
pomodoro(stateBefore, action)
).toEqual(stateAfter)
}
// should stop timer when stop action pomodoro
const testStopTimer = () => {
const stateBefore = { start: true }
const stateAfter = { start: false }
const action = { type: 'STOP' }
expect(
pomodoro(stateBefore, action)
).toEqual(stateAfter)
}
testUpdateTimer()
testUpdateTimerMinute()
testResetTimer()
testStartTimer()
testRestartTimer()
testStopTimer()
console.log('All tests passed.')