|
| 1 | +/*global chrome*/ |
| 2 | +import History from "../history"; |
| 3 | + |
| 4 | +const mockResponse = { |
| 5 | + date: "2007-09-05", |
| 6 | + explanation: "On September 1, Aurigid meteors filled the sky...", |
| 7 | + hdurl: "https://apod.nasa.gov/apod/image/0709/AurigidVaubaillon.jpg", |
| 8 | + media_type: "image", |
| 9 | + service_version: "v1", |
| 10 | + title: "Aurigids from 47,000 Feet", |
| 11 | + url: "https://apod.nasa.gov/apod/image/0709/AurigidVaubaillon720.jpg" |
| 12 | +}; |
| 13 | + |
| 14 | +const mockResponse2 = { ...mockResponse, date: "2015-10-12" }; |
| 15 | + |
| 16 | +describe("History Helper Utility", () => { |
| 17 | + let history; |
| 18 | + |
| 19 | + beforeEach(() => { |
| 20 | + history = new History(); |
| 21 | + }); |
| 22 | + |
| 23 | + it("creates a new object", () => { |
| 24 | + expect(history.responses.length).toBe(0); |
| 25 | + expect(history.currentIdx).toBe(0); |
| 26 | + }); |
| 27 | + |
| 28 | + it("adds response to history", () => { |
| 29 | + history.add(mockResponse); |
| 30 | + expect(history.responses.length).toBe(1); |
| 31 | + expect(history.currentIdx).toBe(0); |
| 32 | + }); |
| 33 | + |
| 34 | + it("adds multiple responses to history", () => { |
| 35 | + history.add(mockResponse); |
| 36 | + history.add(mockResponse2); |
| 37 | + expect(history.responses.length).toBe(2); |
| 38 | + expect(history.currentIdx).toBe(1); |
| 39 | + }); |
| 40 | + |
| 41 | + it("will not add existing response to history", () => { |
| 42 | + history.add(mockResponse); |
| 43 | + history.add(mockResponse); |
| 44 | + expect(history.responses.length).toBe(1); |
| 45 | + expect(history.currentIdx).toBe(0); |
| 46 | + }); |
| 47 | + |
| 48 | + it("gets previous date", () => { |
| 49 | + history.add(mockResponse); |
| 50 | + history.add(mockResponse2); |
| 51 | + |
| 52 | + const response = history.getPreviousDate(); |
| 53 | + expect(response).toMatchObject(history.responses[0]); |
| 54 | + }); |
| 55 | + |
| 56 | + it("no previous dates responds false", () => { |
| 57 | + history.add(mockResponse); |
| 58 | + history.add(mockResponse2); |
| 59 | + |
| 60 | + history.getPreviousDate(); |
| 61 | + const response = history.getPreviousDate(); |
| 62 | + expect(response).toBe(false); |
| 63 | + }); |
| 64 | + |
| 65 | + it("gets next date", () => { |
| 66 | + history.add(mockResponse); |
| 67 | + history.add(mockResponse2); |
| 68 | + |
| 69 | + history.getPreviousDate(); |
| 70 | + const response = history.getNextDate(); |
| 71 | + expect(response).toMatchObject(history.responses[1]); |
| 72 | + }); |
| 73 | + |
| 74 | + it("no next date responds false", () => { |
| 75 | + history.add(mockResponse); |
| 76 | + history.add(mockResponse2); |
| 77 | + |
| 78 | + const response = history.getNextDate(); |
| 79 | + expect(response).toBe(false); |
| 80 | + }); |
| 81 | +}); |
0 commit comments