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'
@@ -14,24 +14,39 @@ vi.mock('vue3-gettext', () => ({
14
14
15
15
vi . mock ( '@cornerstonejs/core' , ( ) => {
16
16
return {
17
- successCallback : vi . fn ( ) ,
18
- errorCallback : vi . fn ( ) ,
19
17
RenderingEngine : class RenderingEngine {
20
18
getViewport ( ) {
21
19
return {
22
20
setStack : vi . fn ( ) ,
23
- render : vi . fn ( )
21
+ render : vi . fn ( ) ,
22
+ getCamera : vi . fn ( ) . mockImplementation ( ( ) => {
23
+ return { parallelScale : 137.3853139193763 }
24
+ } ) ,
25
+ getImageData : vi . fn ( ) . mockImplementation ( ( ) => {
26
+ return { dimensions : [ ] }
27
+ } )
24
28
}
25
29
}
26
30
enableElement ( ) { }
27
31
} ,
28
32
Types : vi . fn ( ) ,
29
33
Enums : {
30
34
ViewportType : {
31
- STACK : '' // "stack",
35
+ STACK : ''
32
36
}
33
37
} ,
34
- metaData : vi . fn ( ) ,
38
+ metaData : {
39
+ get : vi . fn ( ) . mockImplementation ( ( ) => {
40
+ return {
41
+ pixelRepresentation : '' ,
42
+ bitsAllocated : '' ,
43
+ bitsStored : '' ,
44
+ highBit : '' ,
45
+ samplesPerPixel : ''
46
+ }
47
+ } )
48
+ } ,
49
+
35
50
init : vi . fn ( ) ,
36
51
getConfiguration : vi . fn ( ) . mockImplementation ( ( ) => {
37
52
return { rendering : '' }
@@ -60,12 +75,52 @@ vi.mock('dicom-parser', () => ({
60
75
} ) )
61
76
62
77
describe ( 'App component' , ( ) => {
78
+ const spyFetchVipMetadataInformation = vi
79
+ . spyOn ( App . methods , 'fetchVipMetadataInformation' )
80
+ . mockImplementation ( vi . fn ( ) )
81
+ const spyFetchMetadataInformation = vi
82
+ . spyOn ( App . methods , 'fetchMetadataInformation' )
83
+ . mockImplementation ( vi . fn ( ) )
84
+ const spyAddWadouriPrefix = vi
85
+ . spyOn ( App . methods , 'addWadouriPrefix' )
86
+ . mockReturnValue ( 'wadouri:https://test' )
87
+ const spyInitCornerstoneCore = vi
88
+ . spyOn ( App . methods , 'initCornerstoneCore' )
89
+ . mockImplementation ( vi . fn ( ) )
90
+
91
+ beforeEach ( ( ) => {
92
+ vi . clearAllMocks ( )
93
+ } )
94
+
95
+ it ( 'should not fetch overlay metadata when the url is not provided' , async ( ) => {
96
+ getWrapper ( )
97
+ await flushPromises ( )
98
+
99
+ expect ( spyAddWadouriPrefix ) . toHaveBeenCalledTimes ( 0 )
100
+ expect ( spyFetchVipMetadataInformation ) . toHaveBeenCalledTimes ( 0 )
101
+ expect ( spyFetchMetadataInformation ) . toHaveBeenCalledTimes ( 0 )
102
+ expect ( spyInitCornerstoneCore ) . toHaveBeenCalledTimes ( 1 )
103
+ } )
104
+ it ( 'should fetch overlay metadata when the url is provided' , async ( ) => {
105
+ getWrapper ( { props : { url : 'https://test' } } )
106
+ await flushPromises ( )
107
+
108
+ expect ( spyAddWadouriPrefix ) . toHaveBeenCalledTimes ( 1 )
109
+ expect ( spyAddWadouriPrefix ) . toHaveBeenCalledWith ( 'https://test' )
110
+ expect ( spyFetchVipMetadataInformation ) . toHaveBeenCalledTimes ( 1 )
111
+ expect ( spyFetchVipMetadataInformation ) . toHaveBeenCalledWith ( 'wadouri:https://test' )
112
+ expect ( spyFetchMetadataInformation ) . toHaveBeenCalledTimes ( 1 )
113
+ expect ( spyFetchMetadataInformation ) . toHaveBeenCalledWith ( 'wadouri:https://test' )
114
+ expect ( spyInitCornerstoneCore ) . toHaveBeenCalledTimes ( 1 )
115
+ } )
116
+
63
117
describe ( 'Methods' , ( ) => {
64
- vi . spyOn ( App . methods , 'fetchVipMetadataInformation' ) . mockImplementation ( vi . fn ( ) )
65
- vi . spyOn ( App . methods , 'fetchMetadataInformation' ) . mockImplementation ( vi . fn ( ) )
66
118
const wrapper = getWrapper ( )
67
-
68
119
describe ( 'method: wadouri' , ( ) => {
120
+ beforeAll ( ( ) => {
121
+ spyAddWadouriPrefix . mockRestore ( )
122
+ } )
123
+
69
124
it ( 'should add "wadouri" prefix' , async ( ) => {
70
125
expect ( await wrapper . vm . addWadouriPrefix ( 'https://dummy_url' ) ) . toBe (
71
126
'wadouri:https://dummy_url'
0 commit comments