Skip to content

Commit 4347088

Browse files
committed
add unit test for fetchVipMetadataInformation method
1 parent 7571778 commit 4347088

File tree

2 files changed

+45
-22
lines changed

2 files changed

+45
-22
lines changed

src/App.vue

+9-13
Original file line numberDiff line numberDiff line change
@@ -226,13 +226,12 @@ export default defineComponent({
226226
// get resource, ensure resource url is not empty!
227227
if (this.url != null && this.url != undefined && this.url != '') {
228228
this.dicomUrl = await this.addWadouriPrefix(this.url)
229-
}
230-
231-
// get vip metadata
232-
await this.fetchVipMetadataInformation(await this.addWadouriPrefix(this.url))
229+
// get vip metadata
230+
await this.fetchVipMetadataInformation(this.dicomUrl)
233231
234-
// prefetch all other metadata (in separate function for performance reasons)
235-
await this.fetchMetadataInformation(await this.addWadouriPrefix(this.url))
232+
// prefetch all other metadata (in separate function for performance reasons)
233+
await this.fetchMetadataInformation(this.dicomUrl)
234+
}
236235
},
237236
async mounted() {
238237
// check if cornerstone core is initialized
@@ -268,11 +267,10 @@ export default defineComponent({
268267
this.viewport = <Types.IStackViewport>this.renderingEngine.getViewport(viewportId)
269268
270269
// add resource to stack, ensure resource url is not empty!
271-
if (this.url != null && this.url != undefined && this.url != '') {
272-
let dicomResourceUrl = await this.addWadouriPrefix(this.url)
270+
if (this.dicomUrl){
273271
274272
// define a stack containing a single image
275-
const dicomStack = [dicomResourceUrl]
273+
const dicomStack = [this.dicomUrl]
276274
277275
// set stack on the viewport (currently only one image in the stack, therefore no frame # required)
278276
await this.viewport.setStack(dicomStack)
@@ -282,7 +280,7 @@ export default defineComponent({
282280
this.setViewportCameraParallelScaleFactor()
283281
284282
// getting image metadata from viewport
285-
this.getImageMetadataFromViewport(dicomResourceUrl)
283+
this.getImageMetadataFromViewport(this.dicomUrl)
286284
}
287285
},
288286
updated() {
@@ -291,7 +289,7 @@ export default defineComponent({
291289
// this.setViewportCameraParallelScaleFactor()
292290
},
293291
beforeUnmount() {
294-
this.renderingEngine.destroy()
292+
this.renderingEngine.destroy
295293
this.isVipMetadataFetched = false
296294
this.isMetadataFetched = false
297295
this.isImageMetadataExtractedFromViewport = false
@@ -312,11 +310,9 @@ export default defineComponent({
312310
313311
if (!this.isDicomImageDataFetched) {
314312
this.dicomImageData = await fetchDicomImageData(imageId)
315-
if (!this.isDicomImageDataFetched) {
316313
if (this.dicomImageData != null){
317314
this.isDicomImageDataFetched = true
318315
}
319-
}
320316
}
321317
322318
this.vipInformation.patientName = this.dicomImageData.string(findDicomTagByValue('patientName'))

tests/unit/App.spec.ts

+36-9
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
1-
import { shallowMount } from "@vue/test-utils";
1+
import { shallowMount, flushPromises } from "@vue/test-utils";
22
import App from "../../src/App.vue";
33
import { vi } from "vitest";
44
import { defaultPlugins } from "../../src/helper/defaultPlugins";
5+
import * as ExtractMetadata from "../../src/helper/extractMetadata";
56

67
vi.mock("vue3-gettext", () => ({
78
useGettext: vi.fn().mockImplementation((text) => {
@@ -60,16 +61,40 @@ vi.mock("dicom-parser", () => ({
6061
}));
6162

6263
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+
6391
describe("Methods", () => {
64-
vi.spyOn(App.methods, "fetchVipMetadataInformation").mockImplementation(
65-
vi.fn()
66-
);
67-
vi.spyOn(App.methods, "fetchMetadataInformation").mockImplementation(
68-
vi.fn()
69-
);
7092
const wrapper = getWrapper();
71-
7293
describe("method: wadouri", () => {
94+
beforeAll(() => {
95+
spyAddWadouriPrefix.mockRestore();
96+
});
97+
7398
it('should add "wadouri" prefix', async () => {
7499
expect(await wrapper.vm.addWadouriPrefix("https://dummy_url")).toBe(
75100
"wadouri:https://dummy_url"
@@ -124,7 +149,9 @@ describe("App component", () => {
124149
])(
125150
`should return $expected for $description`,
126151
({ date, time, expected }) => {
127-
expect(wrapper.vm.formatOverlayDateAndTime(date, time)).toBe(expected);
152+
expect(wrapper.vm.formatOverlayDateAndTime(date, time)).toBe(
153+
expected
154+
);
128155
}
129156
);
130157
});

0 commit comments

Comments
 (0)