1
1
import SnapshotControls from './SnapshotControls.vue'
2
2
import { autSnapshot } from '../../cypress/support/fixtures'
3
3
import { useSnapshotStore } from './snapshot-store'
4
+ import { createEventManager , createTestAutIframe } from '../../cypress/e2e/support/ctSupport'
4
5
5
- describe ( 'SnapshotControls' , ( ) => {
6
- const mountSnapshotControls = ( ) => {
7
- const eventManager = { } as typeof window . UnifiedRunner . eventManager
6
+ // function createTestAutIframe () {
7
+ // return new class {
8
+ // removeHighlights () {}
9
+ // }
10
+ // }
8
11
9
- return cy . mount ( ( ) => < SnapshotControls eventManager = { eventManager } /> )
12
+ describe ( 'SnapshotControls' , ( ) => {
13
+ const mountSnapshotControls = (
14
+ eventManager = createEventManager ( ) ,
15
+ autIframe = createTestAutIframe ( ) ,
16
+ ) => {
17
+ return cy . mount ( ( ) => (
18
+ < SnapshotControls
19
+ eventManager = { eventManager }
20
+ getAutIframe = { ( ) => autIframe }
21
+ />
22
+ ) )
10
23
}
11
24
12
- beforeEach ( ( ) => {
13
- return mountSnapshotControls ( )
14
- } )
15
-
16
25
it ( 'renders nothing when messageTitle is undefined' , ( ) => {
26
+ mountSnapshotControls ( )
17
27
cy . get ( '[data-cy="snapshot-highlight-controls"]' ) . should ( 'not.exist' )
18
28
cy . get ( '[data-cy="snapshot-message"]' ) . should ( 'not.exist' )
19
29
cy . get ( '[data-cy="snapshot-change-state"]' ) . should ( 'not.exist' )
20
30
} )
21
31
22
32
it ( 'renders snapshot title when one is pinned' , ( ) => {
33
+ mountSnapshotControls ( )
23
34
const snapshotStore = useSnapshotStore ( )
24
35
25
36
snapshotStore . pinSnapshot ( autSnapshot )
@@ -28,6 +39,7 @@ describe('SnapshotControls', () => {
28
39
} )
29
40
30
41
it ( 'renders snapshot pinned status' , ( ) => {
42
+ mountSnapshotControls ( )
31
43
const snapshotStore = useSnapshotStore ( )
32
44
33
45
snapshotStore . pinSnapshot ( autSnapshot )
@@ -40,6 +52,7 @@ describe('SnapshotControls', () => {
40
52
} )
41
53
42
54
it ( 'clears snapshot message' , ( ) => {
55
+ mountSnapshotControls ( )
43
56
const snapshotStore = useSnapshotStore ( )
44
57
45
58
snapshotStore . pinSnapshot ( autSnapshot )
@@ -49,6 +62,7 @@ describe('SnapshotControls', () => {
49
62
} )
50
63
51
64
it ( 'shows snapshot with custom message' , ( ) => {
65
+ mountSnapshotControls ( )
52
66
const message = 'This is a custom message'
53
67
const snapshotStore = useSnapshotStore ( )
54
68
@@ -57,6 +71,7 @@ describe('SnapshotControls', () => {
57
71
} )
58
72
59
73
it ( 'does not show highlight controls if no element present on snapshot' , ( ) => {
74
+ mountSnapshotControls ( )
60
75
const snapshotStore = useSnapshotStore ( )
61
76
62
77
snapshotStore . pinSnapshot ( autSnapshot )
@@ -65,19 +80,38 @@ describe('SnapshotControls', () => {
65
80
66
81
it ( 'toggles highlight controls if snapshot has an element' , ( ) => {
67
82
const snapshotStore = useSnapshotStore ( )
83
+ const eventManager = createEventManager ( )
84
+ const autIframe = createTestAutIframe ( )
85
+ const removeHighlights = cy . stub ( autIframe , 'removeHighlights' )
68
86
87
+ // we don't have an iframe-model since this is a CT test, but we can
88
+ // simulate it by registering the same unpin:snapshot event it does.
89
+ eventManager . on ( 'unpin:snapshot' , ( ) => snapshotStore . unpinSnapshot ( ) )
69
90
snapshotStore . pinSnapshot ( { ...autSnapshot , $el : 'some element' } )
91
+
92
+ mountSnapshotControls ( eventManager , autIframe )
70
93
cy . get ( '[data-cy="snapshot-highlight-controls"]' ) . should ( 'exist' )
94
+ cy . get ( '[data-cy="toggle-snapshot-highlights"]' ) . as ( 'toggle' )
95
+ cy . get ( '@toggle' ) . should ( 'have.attr' , 'title' , 'Hide highlights' )
96
+ cy . get ( '@toggle' ) . click ( ) . then ( ( ) => {
97
+ expect ( removeHighlights ) . to . have . been . calledOnce
98
+ } )
99
+
100
+ cy . get ( '@toggle' ) . should ( 'have.attr' , 'title' , 'Show highlights' )
101
+ cy . get ( '[data-cy="unpin-snapshot"]' ) . click ( )
102
+ cy . get ( '[data-cy="snapshot-highlight-controls"]' ) . should ( 'not.exist' )
71
103
} )
72
104
73
105
it ( 'shows running test error' , ( ) => {
106
+ mountSnapshotControls ( )
74
107
const snapshotStore = useSnapshotStore ( )
75
108
76
109
snapshotStore . setTestsRunningError ( )
77
110
cy . get ( '[data-cy="snapshot-message"]' ) . contains ( 'Cannot show Snapshot while tests are running' )
78
111
} )
79
112
80
113
it ( 'shows snapshot missing error' , ( ) => {
114
+ mountSnapshotControls ( )
81
115
const snapshotStore = useSnapshotStore ( )
82
116
83
117
snapshotStore . setMissingSnapshotMessage ( )
0 commit comments