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'
@@ -20,7 +20,13 @@ vi.mock('@cornerstonejs/core', () => {
20
20
getViewport ( ) {
21
21
return {
22
22
setStack : vi . fn ( ) ,
23
- render : vi . fn ( )
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,12 +66,48 @@ 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 . spyOn ( App . methods , 'addWadouriPrefix' ) . mockImplementation ( vi . fn ( ) )
76
+ const spyInitCornerstoneCore = vi
77
+ . spyOn ( App . methods , 'initCornerstoneCore' )
78
+ . mockImplementation ( vi . fn ( ) )
79
+
80
+ beforeEach ( ( ) => {
81
+ vi . clearAllMocks ( )
82
+ } )
83
+
84
+ it ( 'should not fetch overlay metadata when the url is not provided' , async ( ) => {
85
+ getWrapper ( )
86
+ await flushPromises ( )
87
+
88
+ expect ( spyAddWadouriPrefix ) . toHaveBeenCalledTimes ( 0 )
89
+ expect ( spyFetchVipMetadataInformation ) . toHaveBeenCalledTimes ( 0 )
90
+ expect ( spyFetchMetadataInformation ) . toHaveBeenCalledTimes ( 0 )
91
+ expect ( spyInitCornerstoneCore ) . toHaveBeenCalledTimes ( 1 )
92
+ } )
93
+ it ( 'should fetch overlay metadata when the url is provided' , async ( ) => {
94
+ getWrapper ( { props : { url : 'https://test' } } )
95
+ await flushPromises ( )
96
+
97
+ expect ( spyAddWadouriPrefix ) . toHaveBeenCalledTimes ( 1 )
98
+ expect ( spyAddWadouriPrefix ) . toHaveBeenCalledWith ( 'https://test' )
99
+ expect ( spyFetchVipMetadataInformation ) . toHaveBeenCalledTimes ( 1 )
100
+ expect ( spyFetchMetadataInformation ) . toHaveBeenCalledTimes ( 1 )
101
+ expect ( spyInitCornerstoneCore ) . toHaveBeenCalledTimes ( 1 )
102
+ } )
103
+
63
104
describe ( 'Methods' , ( ) => {
64
- vi . spyOn ( App . methods , 'fetchVipMetadataInformation' ) . mockImplementation ( vi . fn ( ) )
65
- vi . spyOn ( App . methods , 'fetchMetadataInformation' ) . mockImplementation ( vi . fn ( ) )
66
105
const wrapper = getWrapper ( )
67
-
68
106
describe ( 'method: wadouri' , ( ) => {
107
+ beforeAll ( ( ) => {
108
+ spyAddWadouriPrefix . mockRestore ( )
109
+ } )
110
+
69
111
it ( 'should add "wadouri" prefix' , async ( ) => {
70
112
expect ( await wrapper . vm . addWadouriPrefix ( 'https://dummy_url' ) ) . toBe (
71
113
'wadouri:https://dummy_url'
0 commit comments