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,45 @@ 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
+ const spyInitCornerstoneCore = vi
79
+ . spyOn ( App . methods , "initCornerstoneCore" )
80
+ . mockImplementation ( vi . fn ( ) ) ;
81
+
82
+ it ( "should not fetch overlay metadata when the url is not provided" , async ( ) => {
83
+ getWrapper ( ) ;
84
+ await flushPromises ( ) ;
85
+
86
+ expect ( spyAddWadouriPrefix ) . toHaveBeenCalledTimes ( 0 ) ;
87
+ expect ( spyFetchVipMetadataInformation ) . toHaveBeenCalledTimes ( 0 ) ;
88
+ expect ( spyFetchMetadataInformation ) . toHaveBeenCalledTimes ( 0 ) ;
89
+ expect ( spyInitCornerstoneCore ) . toHaveBeenCalled ( ) ;
90
+ } ) ;
91
+ it ( "should fetch overlay metadata when the url is provided" , async ( ) => {
92
+ getWrapper ( { props : { url : "https://test" } } ) ;
93
+ await flushPromises ( ) ;
94
+
95
+ expect ( spyAddWadouriPrefix ) . toHaveBeenCalledTimes ( 1 ) ;
96
+ expect ( spyFetchVipMetadataInformation ) . toHaveBeenCalledTimes ( 1 ) ;
97
+ expect ( spyFetchMetadataInformation ) . toHaveBeenCalledTimes ( 1 ) ;
98
+ expect ( spyInitCornerstoneCore ) . toHaveBeenCalled ( ) ;
99
+ } ) ;
100
+
63
101
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
102
const wrapper = getWrapper ( ) ;
71
-
72
103
describe ( "method: wadouri" , ( ) => {
104
+ beforeAll ( ( ) => {
105
+ spyAddWadouriPrefix . mockRestore ( ) ;
106
+ } ) ;
107
+
73
108
it ( 'should add "wadouri" prefix' , async ( ) => {
74
109
expect ( await wrapper . vm . addWadouriPrefix ( "https://dummy_url" ) ) . toBe (
75
110
"wadouri:https://dummy_url"
@@ -124,7 +159,9 @@ describe("App component", () => {
124
159
] ) (
125
160
`should return $expected for $description` ,
126
161
( { date, time, expected } ) => {
127
- expect ( wrapper . vm . formatOverlayDateAndTime ( date , time ) ) . toBe ( expected ) ;
162
+ expect ( wrapper . vm . formatOverlayDateAndTime ( date , time ) ) . toBe (
163
+ expected
164
+ ) ;
128
165
}
129
166
) ;
130
167
} ) ;
0 commit comments