|
| 1 | +const { announceMachines } = process.env.TEST_SOLUTIONS |
| 2 | + ? require("./solution") |
| 3 | + : require("./index"); |
| 4 | + |
| 5 | +describe(announceMachines, () => { |
| 6 | + it("announces a machine's label when the label exists", () => { |
| 7 | + const announce = jest.fn(); |
| 8 | + const label = "test label"; |
| 9 | + |
| 10 | + announceMachines(announce, { label }); |
| 11 | + |
| 12 | + expect(announce).toHaveBeenCalledWith(label); |
| 13 | + }); |
| 14 | + |
| 15 | + it("announces a machine's make and model when it does not have a label", () => { |
| 16 | + const announce = jest.fn(); |
| 17 | + const make = "test make"; |
| 18 | + const model = "test model"; |
| 19 | + |
| 20 | + announceMachines(announce, { make, model }); |
| 21 | + |
| 22 | + expect(announce).toHaveBeenCalledWith(`Make: test make; Model: test model`); |
| 23 | + }); |
| 24 | + |
| 25 | + it("returns an increased count when a machine has a label", () => { |
| 26 | + const announce = jest.fn(); |
| 27 | + |
| 28 | + const labelsCount = announceMachines(announce, { label: "test label" }); |
| 29 | + |
| 30 | + expect(labelsCount).toBe(1); |
| 31 | + }); |
| 32 | + |
| 33 | + it("returns a non-increased count when a machine does not has a label", () => { |
| 34 | + const announce = jest.fn(); |
| 35 | + |
| 36 | + const labelsCount = announceMachines(announce, { make: "", model: "" }); |
| 37 | + |
| 38 | + expect(labelsCount).toBe(0); |
| 39 | + }); |
| 40 | + |
| 41 | + it("returns an increased count for labels when only some machines have label", () => { |
| 42 | + const announce = jest.fn(); |
| 43 | + |
| 44 | + const labelsCount = announceMachines( |
| 45 | + announce, |
| 46 | + { label: "test label" }, |
| 47 | + { make: "", model: "" }, |
| 48 | + { label: "test label" } |
| 49 | + ); |
| 50 | + |
| 51 | + expect(labelsCount).toBe(2); |
| 52 | + }); |
| 53 | +}); |
0 commit comments