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" ;
@@ -21,6 +21,12 @@ vi.mock("@cornerstonejs/core", () => {
21
21
return {
22
22
setStack : vi . fn ( ) ,
23
23
render : vi . fn ( ) ,
24
+ getCamera : vi . fn ( ) . mockImplementation ( ( ) => {
25
+ return { parallelScale : 137.3853139193763 } ;
26
+ } ) ,
27
+ getImageData : vi . fn ( ) . mockImplementation ( ( ) => {
28
+ return { dimensions : [ ] } ;
29
+ } ) ,
24
30
} ;
25
31
}
26
32
enableElement ( ) { }
@@ -60,16 +66,40 @@ vi.mock("dicom-parser", () => ({
60
66
} ) ) ;
61
67
62
68
describe ( "App component" , ( ) => {
69
+ const spyFetchVipMetadataInformation = vi
70
+ . spyOn ( App . methods , "fetchVipMetadataInformation" )
71
+ . mockImplementation ( vi . fn ( ) ) ;
72
+ const spyFetchMetadataInformation = vi
73
+ . spyOn ( App . methods , "fetchMetadataInformation" )
74
+ . mockImplementation ( vi . fn ( ) ) ;
75
+ const spyAddWadouriPrefix = vi
76
+ . spyOn ( App . methods , "addWadouriPrefix" )
77
+ . mockImplementation ( vi . fn ( ) ) ;
78
+
79
+ it ( "should not fetch overlay metadata when the url is not provided" , async ( ) => {
80
+ getWrapper ( ) ;
81
+ await flushPromises ( ) ;
82
+
83
+ expect ( spyAddWadouriPrefix ) . toHaveBeenCalledTimes ( 0 ) ;
84
+ expect ( spyFetchVipMetadataInformation ) . toHaveBeenCalledTimes ( 0 ) ;
85
+ expect ( spyFetchMetadataInformation ) . toHaveBeenCalledTimes ( 0 ) ;
86
+ } ) ;
87
+ it ( "should fetch overlay metadata when the url is provided" , async ( ) => {
88
+ getWrapper ( { props : { url : "https://test" } } ) ;
89
+ await flushPromises ( ) ;
90
+
91
+ expect ( spyAddWadouriPrefix ) . toHaveBeenCalledTimes ( 2 ) ;
92
+ expect ( spyFetchVipMetadataInformation ) . toHaveBeenCalledTimes ( 1 ) ;
93
+ expect ( spyFetchMetadataInformation ) . toHaveBeenCalledTimes ( 1 ) ;
94
+ } ) ;
95
+
63
96
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
97
const wrapper = getWrapper ( ) ;
71
-
72
98
describe ( "method: wadouri" , ( ) => {
99
+ beforeAll ( ( ) => {
100
+ spyAddWadouriPrefix . mockRestore ( ) ;
101
+ } ) ;
102
+
73
103
it ( 'should add "wadouri" prefix' , async ( ) => {
74
104
expect ( await wrapper . vm . addWadouriPrefix ( "https://dummy_url" ) ) . toBe (
75
105
"wadouri:https://dummy_url"
@@ -124,7 +154,9 @@ describe("App component", () => {
124
154
] ) (
125
155
`should return $expected for $description` ,
126
156
( { date, time, expected } ) => {
127
- expect ( wrapper . vm . formatOverlayDateAndTime ( date , time ) ) . toBe ( expected ) ;
157
+ expect ( wrapper . vm . formatOverlayDateAndTime ( date , time ) ) . toBe (
158
+ expected
159
+ ) ;
128
160
}
129
161
) ;
130
162
} ) ;
0 commit comments