|
1 |
| -import { shallowMount } from "@vue/test-utils"; |
| 1 | +import { shallowMount, flushPromises } from "@vue/test-utils"; |
2 | 2 | import App from "../../src/App.vue";
|
3 | 3 | import { vi } from "vitest";
|
4 | 4 | import { defaultPlugins } from "../../src/helper/defaultPlugins";
|
| 5 | +import * as ExtractMetadata from "../../src/helper/extractMetadata"; |
5 | 6 |
|
6 | 7 | vi.mock("vue3-gettext", () => ({
|
7 | 8 | useGettext: vi.fn().mockImplementation((text) => {
|
@@ -60,16 +61,40 @@ vi.mock("dicom-parser", () => ({
|
60 | 61 | }));
|
61 | 62 |
|
62 | 63 | describe("App component", () => {
|
| 64 | + const spyFetchVipMetadataInformation = vi |
| 65 | + .spyOn(App.methods, "fetchVipMetadataInformation") |
| 66 | + .mockImplementation(vi.fn()); |
| 67 | + const spyFetchMetadataInformation = vi |
| 68 | + .spyOn(App.methods, "fetchMetadataInformation") |
| 69 | + .mockImplementation(vi.fn()); |
| 70 | + const spyAddWadouriPrefix = vi |
| 71 | + .spyOn(App.methods, "addWadouriPrefix") |
| 72 | + .mockImplementation(vi.fn()); |
| 73 | + |
| 74 | + it("should not fetch overlay metadata", async () => { |
| 75 | + getWrapper(); |
| 76 | + await flushPromises(); |
| 77 | + |
| 78 | + expect(spyAddWadouriPrefix).toHaveBeenCalledTimes(0); |
| 79 | + expect(spyFetchVipMetadataInformation).toHaveBeenCalledTimes(0); |
| 80 | + expect(spyFetchMetadataInformation).toHaveBeenCalledTimes(0); |
| 81 | + }); |
| 82 | + it("should fetch overlay metadata", async () => { |
| 83 | + getWrapper({ props: { url: "https://test" } }); |
| 84 | + await flushPromises(); |
| 85 | + |
| 86 | + expect(spyAddWadouriPrefix).toHaveBeenCalledTimes(1); |
| 87 | + expect(spyFetchVipMetadataInformation).toHaveBeenCalledTimes(1); |
| 88 | + expect(spyFetchMetadataInformation).toHaveBeenCalledTimes(1); |
| 89 | + }); |
| 90 | + |
63 | 91 | describe("Methods", () => {
|
64 |
| - vi.spyOn(App.methods, "fetchVipMetadataInformation").mockImplementation( |
65 |
| - vi.fn() |
66 |
| - ); |
67 |
| - vi.spyOn(App.methods, "fetchMetadataInformation").mockImplementation( |
68 |
| - vi.fn() |
69 |
| - ); |
70 | 92 | const wrapper = getWrapper();
|
71 |
| - |
72 | 93 | describe("method: wadouri", () => {
|
| 94 | + beforeAll(() => { |
| 95 | + spyAddWadouriPrefix.mockRestore(); |
| 96 | + }); |
| 97 | + |
73 | 98 | it('should add "wadouri" prefix', async () => {
|
74 | 99 | expect(await wrapper.vm.addWadouriPrefix("https://dummy_url")).toBe(
|
75 | 100 | "wadouri:https://dummy_url"
|
@@ -124,7 +149,9 @@ describe("App component", () => {
|
124 | 149 | ])(
|
125 | 150 | `should return $expected for $description`,
|
126 | 151 | ({ date, time, expected }) => {
|
127 |
| - expect(wrapper.vm.formatOverlayDateAndTime(date, time)).toBe(expected); |
| 152 | + expect(wrapper.vm.formatOverlayDateAndTime(date, time)).toBe( |
| 153 | + expected |
| 154 | + ); |
128 | 155 | }
|
129 | 156 | );
|
130 | 157 | });
|
|
0 commit comments