|
1 | 1 | // @flow |
2 | 2 | import {parseHours} from '../parse-hours' |
3 | | -import {dayMoment, hourMoment, moment} from './moment.helper' |
| 3 | +import {dayMoment, plainMoment, hourMoment, moment} from './moment.helper' |
4 | 4 |
|
5 | 5 | it('returns an {open, close} tuple', () => { |
6 | | - let now = hourMoment('10:01am') |
7 | | - let input = {days: [], from: '10:00am', to: '4:00pm'} |
8 | | - let actual = parseHours(input, now) |
| 6 | + const now = hourMoment('10:01am') |
| 7 | + const input = {days: [], from: '10:00am', to: '4:00pm'} |
| 8 | + const actual = parseHours(input, now) |
9 | 9 |
|
10 | 10 | expect(actual).toBeDefined() |
11 | 11 | expect(actual.open).toBeDefined() |
12 | 12 | expect(actual.close).toBeDefined() |
13 | 13 | }) |
14 | 14 |
|
15 | 15 | it('returns a Moment for .open', () => { |
16 | | - let now = hourMoment('10:01am') |
17 | | - let input = {days: [], from: '10:00am', to: '4:00pm'} |
18 | | - let {open} = parseHours(input, now) |
| 16 | + const now = hourMoment('10:01am') |
| 17 | + const input = {days: [], from: '10:00am', to: '4:00pm'} |
| 18 | + const {open} = parseHours(input, now) |
19 | 19 | expect(moment.isMoment(open)).toBe(true) |
20 | 20 | }) |
21 | 21 |
|
22 | 22 | it('returns a Moment for .close', () => { |
23 | | - let now = hourMoment('10:01am') |
24 | | - let input = {days: [], from: '10:00am', to: '4:00pm'} |
25 | | - let {close} = parseHours(input, now) |
| 23 | + const now = hourMoment('10:01am') |
| 24 | + const input = {days: [], from: '10:00am', to: '4:00pm'} |
| 25 | + const {close} = parseHours(input, now) |
26 | 26 | expect(moment.isMoment(close)).toBe(true) |
27 | 27 | }) |
28 | 28 |
|
29 | 29 | it('will add a day to the close time with nextDay:true', () => { |
30 | | - let now = hourMoment('10:01am') |
31 | | - let input = {days: [], from: '10:00am', to: '2:00am'} |
32 | | - let {open, close} = parseHours(input, now) |
| 30 | + const now = hourMoment('10:01am') |
| 31 | + const input = {days: [], from: '10:00am', to: '2:00am'} |
| 32 | + const {open, close} = parseHours(input, now) |
33 | 33 |
|
34 | 34 | expect(close.isAfter(open)).toBe(true) |
35 | 35 | expect(close.isAfter(now)).toBe(true) |
36 | 36 | }) |
37 | 37 |
|
38 | 38 | describe('handles wierd times', () => { |
39 | 39 | it('handles Friday at 4:30pm', () => { |
40 | | - let now = dayMoment('Fri 4:30pm') |
41 | | - let input = {days: [], from: '10:00am', to: '2:00am'} |
42 | | - let {open, close} = parseHours(input, now) |
| 40 | + const now = dayMoment('Fri 4:30pm') |
| 41 | + const input = {days: [], from: '10:00am', to: '2:00am'} |
| 42 | + const {open, close} = parseHours(input, now) |
43 | 43 |
|
44 | 44 | expect(now.isBetween(open, close)).toBe(true) |
45 | 45 | }) |
46 | 46 |
|
47 | 47 | it('handles Saturday at 1:30am', () => { |
48 | | - let now = dayMoment('Sat 1:30am') |
49 | | - let input = {days: [], from: '10:00am', to: '2:00am'} |
50 | | - let {open, close} = parseHours(input, now) |
| 48 | + const now = dayMoment('Sat 1:30am') |
| 49 | + const input = {days: [], from: '10:00am', to: '2:00am'} |
| 50 | + const {open, close} = parseHours(input, now) |
51 | 51 |
|
52 | 52 | expect(now.isBetween(open, close)).toBe(true) |
53 | 53 | }) |
54 | 54 | }) |
| 55 | + |
| 56 | +describe('checks a list of schedules to see if any are open', () => { |
| 57 | + const schedule = {days: ['Fr', 'Sa'], from: '10:30am', to: '2:00am'} |
| 58 | + |
| 59 | + it('in normal, non-dst situations', () => { |
| 60 | + const now = plainMoment('06-24-2017 12:00am', 'MM-DD-YYYY h:mma') |
| 61 | + const {open, close} = parseHours(schedule, now) |
| 62 | + expect(open.format('HH:mm')).toBe('10:30') |
| 63 | + expect(close.format('HH:mm')).toBe('02:00') |
| 64 | + }) |
| 65 | + |
| 66 | + it('during the spring-forward dst', () => { |
| 67 | + const now = plainMoment('03-12-2017 12:00am', 'MM-DD-YYYY h:mma') |
| 68 | + const {open, close} = parseHours(schedule, now) |
| 69 | + expect(open.format('HH:mm')).toBe('10:30') |
| 70 | + expect(close.format('HH:mm')).toBe('01:00') |
| 71 | + }) |
| 72 | + |
| 73 | + it('during the fall-back dst', () => { |
| 74 | + const now = plainMoment('11-4-2017 12:00am', 'MM-DD-YYYY h:mma') |
| 75 | + const {open, close} = parseHours(schedule, now) |
| 76 | + expect(open.format('HH:mm')).toBe('10:30') |
| 77 | + expect(close.format('HH:mm')).toBe('02:00') |
| 78 | + }) |
| 79 | +}) |
0 commit comments