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" ;
6
+ import { url } from "inspector" ;
5
7
6
8
vi . mock ( "vue3-gettext" , ( ) => ( {
7
9
useGettext : vi . fn ( ) . mockImplementation ( ( text ) => {
@@ -21,6 +23,12 @@ vi.mock("@cornerstonejs/core", () => {
21
23
return {
22
24
setStack : vi . fn ( ) ,
23
25
render : vi . fn ( ) ,
26
+ getCamera : vi . fn ( ) . mockImplementation ( ( ) => {
27
+ return { parallelScale : 137.3853139193763 } ;
28
+ } ) ,
29
+ getImageData : vi . fn ( ) . mockImplementation ( ( ) => {
30
+ return { dimensions : [ ] } ;
31
+ } ) ,
24
32
} ;
25
33
}
26
34
enableElement ( ) { }
@@ -31,7 +39,17 @@ vi.mock("@cornerstonejs/core", () => {
31
39
STACK : "" , // "stack",
32
40
} ,
33
41
} ,
34
- metaData : vi . fn ( ) ,
42
+ metaData : {
43
+ get : vi . fn ( ) . mockImplementation ( ( ) => {
44
+ return {
45
+ pixelRepresentation : "" ,
46
+ bitsAllocated : "" ,
47
+ bitsStored : "" ,
48
+ highBit : "" ,
49
+ samplesPerPixel : "" ,
50
+ } ;
51
+ } ) ,
52
+ } ,
35
53
init : vi . fn ( ) ,
36
54
getConfiguration : vi . fn ( ) . mockImplementation ( ( ) => {
37
55
return { rendering : "" } ;
@@ -60,16 +78,76 @@ vi.mock("dicom-parser", () => ({
60
78
} ) ) ;
61
79
62
80
describe ( "App component" , ( ) => {
81
+ const spyFetchVipMetadataInformation = vi
82
+ . spyOn ( App . methods , "fetchVipMetadataInformation" )
83
+ . mockImplementation ( vi . fn ( ) ) ;
84
+ const spyFetchMetadataInformation = vi
85
+ . spyOn ( App . methods , "fetchMetadataInformation" )
86
+ . mockImplementation ( vi . fn ( ) ) ;
87
+ const spyAddWadouriPrefix = vi
88
+ . spyOn ( App . methods , "addWadouriPrefix" )
89
+ . mockImplementation ( vi . fn ( ) ) ;
90
+
91
+ it ( "should not fetch overlay metadata" , ( ) => {
92
+ getWrapper ( ) ;
93
+ expect ( spyFetchVipMetadataInformation ) . toHaveBeenCalledTimes ( 0 ) ;
94
+ expect ( spyFetchMetadataInformation ) . toHaveBeenCalledTimes ( 0 ) ;
95
+ } ) ;
96
+ it ( "should fetch overlay metadata" , async ( ) => {
97
+ getWrapper ( { props : { url : "https://test" } } ) ;
98
+ await flushPromises ( ) ;
99
+
100
+ expect ( spyAddWadouriPrefix ) . toHaveBeenCalledTimes ( 1 ) ;
101
+ expect ( spyFetchVipMetadataInformation ) . toHaveBeenCalledTimes ( 1 ) ;
102
+ expect ( spyFetchMetadataInformation ) . toHaveBeenCalledTimes ( 1 ) ;
103
+ } ) ;
104
+
105
+ // describe("method: fetchVipMetadataInformation", () => {
106
+ // it("should fetch overlay metadata", async () => {
107
+ // const options = {
108
+ // data() {
109
+ // return {
110
+ // vipInformation: {
111
+ // patientName: "DemoPatient",
112
+ // patientBirthdate: "19951025",
113
+ // institutionName: "DemoInstitute",
114
+ // instanceCreationDate: "20241120",
115
+ // instanceCreationTime: "093801",
116
+ // },
117
+ // };
118
+ // },
119
+ // };
120
+
121
+ // const fetchDicomImageData = vi
122
+ // .spyOn(ExtractMetadata, "fetchDicomImageData")
123
+ // .mockImplementation(vi.fn());
124
+ // const findDicomTagByValue = vi
125
+ // .spyOn(ExtractMetadata, "findDicomTagByValue")
126
+ // .mockImplementation(vi.fn());
127
+ // const wrapper = getWrapper(options);
128
+
129
+ // // wrapper.vm.fetchVipMetadataInformation(
130
+ // // "https://host.docker.internal:9200/6b0a0207-3bb6-4a6c-ab8a-e6b8a4beb6c5"
131
+ // // );
132
+ // console.log(
133
+ // "isDicomImageDataFetched: ",
134
+ // wrapper.vm.isDicomImageDataFetched
135
+ // );
136
+ // console.log("dicomImageData: ", wrapper.vm.dicomImageData);
137
+
138
+ // expect(wrapper.vm.vipInformation.patientName).toBe("DemoPatient");
139
+ // expect(wrapper.vm.isDicomImageDataFetched).toBe(true);
140
+ // expect(findDicomTagByValue).toHaveBeenCalledTimes(1);
141
+ // expect(fetchDicomImageData).toHaveBeenCalled();
142
+ // });
143
+ // });
63
144
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
145
const wrapper = getWrapper ( ) ;
71
-
72
146
describe ( "method: wadouri" , ( ) => {
147
+ beforeAll ( ( ) => {
148
+ spyAddWadouriPrefix . mockRestore ( ) ;
149
+ } ) ;
150
+
73
151
it ( 'should add "wadouri" prefix' , async ( ) => {
74
152
expect ( await wrapper . vm . addWadouriPrefix ( "https://dummy_url" ) ) . toBe (
75
153
"wadouri:https://dummy_url"
@@ -124,7 +202,9 @@ describe("App component", () => {
124
202
] ) (
125
203
`should return $expected for $description` ,
126
204
( { date, time, expected } ) => {
127
- expect ( wrapper . vm . formatOverlayDateAndTime ( date , time ) ) . toBe ( expected ) ;
205
+ expect ( wrapper . vm . formatOverlayDateAndTime ( date , time ) ) . toBe (
206
+ expected
207
+ ) ;
128
208
}
129
209
) ;
130
210
} ) ;
0 commit comments