|
| 1 | +import { Complete } from "../../lib/Core/TypeModifiers"; |
| 2 | +import createDiscreteTimesFromIsoSegments from "../../lib/Core/createDiscreteTimes"; |
| 3 | + |
| 4 | +describe("createDiscreteTimesFromIsoSegments", () => { |
| 5 | + it("should not duplicate stop date", () => { |
| 6 | + const result: Complete<{ |
| 7 | + time?: string; |
| 8 | + tag?: string; |
| 9 | + }>[] = []; |
| 10 | + const value = "2018-02-07T00:00:00.000Z/2018-03-09T00:00:00.000Z/P15D"; |
| 11 | + const isoSegments = value.split("/"); |
| 12 | + const maxRefreshIntervals = 10; |
| 13 | + createDiscreteTimesFromIsoSegments( |
| 14 | + result, |
| 15 | + isoSegments[0], |
| 16 | + isoSegments[1], |
| 17 | + isoSegments[2], |
| 18 | + maxRefreshIntervals |
| 19 | + ); |
| 20 | + expect(result.length).toBe(3); |
| 21 | + expect(result[0].time).toBe("2018-02-07T00:00:00Z"); |
| 22 | + expect(result[1].time).toBe("2018-02-22T00:00:00Z"); |
| 23 | + expect(result[2].time).toBe("2018-03-09T00:00:00Z"); |
| 24 | + }); |
| 25 | + |
| 26 | + it("should include a stop date", () => { |
| 27 | + const result: Complete<{ |
| 28 | + time?: string; |
| 29 | + tag?: string; |
| 30 | + }>[] = []; |
| 31 | + const value = "2018-02-07T00:00:00.000Z/2018-03-10T00:00:00.000Z/P15D"; |
| 32 | + const isoSegments = value.split("/"); |
| 33 | + const maxRefreshIntervals = 10; |
| 34 | + createDiscreteTimesFromIsoSegments( |
| 35 | + result, |
| 36 | + isoSegments[0], |
| 37 | + isoSegments[1], |
| 38 | + isoSegments[2], |
| 39 | + maxRefreshIntervals |
| 40 | + ); |
| 41 | + expect(result.length).toBe(4); |
| 42 | + expect(result[0].time).toBe("2018-02-07T00:00:00Z"); |
| 43 | + expect(result[1].time).toBe("2018-02-22T00:00:00Z"); |
| 44 | + expect(result[2].time).toBe("2018-03-09T00:00:00Z"); |
| 45 | + expect(result[3].time).toBe("2018-03-10T00:00:00Z"); |
| 46 | + }); |
| 47 | + |
| 48 | + it("should limit time number to maxRefreshInterval", () => { |
| 49 | + const result: Complete<{ |
| 50 | + time?: string; |
| 51 | + tag?: string; |
| 52 | + }>[] = []; |
| 53 | + const value = "2018-02-07T00:00:00.000Z/2018-03-09T00:00:00.000Z/P15D"; |
| 54 | + const isoSegments = value.split("/"); |
| 55 | + const maxRefreshIntervals = 2; |
| 56 | + createDiscreteTimesFromIsoSegments( |
| 57 | + result, |
| 58 | + isoSegments[0], |
| 59 | + isoSegments[1], |
| 60 | + isoSegments[2], |
| 61 | + maxRefreshIntervals |
| 62 | + ); |
| 63 | + expect(result.length).toBe(maxRefreshIntervals); |
| 64 | + expect(result[0].time).toBe("2018-02-07T00:00:00Z"); |
| 65 | + expect(result[1].time).toBe("2018-02-22T00:00:00Z"); |
| 66 | + }); |
| 67 | +}); |
0 commit comments