@@ -10,6 +10,10 @@ import {
10
10
} from '@mongodb-js/compass-connections/provider' ;
11
11
import { createDefaultConnectionInfo } from '@mongodb-js/testing-library-compass' ;
12
12
13
+ // Importing this to stub showConfirmation
14
+ import * as updateViewSlice from './update-view' ;
15
+ import * as searchIndexesSlice from './search-indexes' ;
16
+
13
17
const TEST_CONNECTION_INFO = { ...createDefaultConnectionInfo ( ) , title : '' } ;
14
18
15
19
describe ( 'update-view module' , function ( ) {
@@ -48,10 +52,20 @@ describe('update-view module', function () {
48
52
let stateMock : any ;
49
53
let getStateMock : ( ) => any ;
50
54
let updateCollectionFake = sinon . fake ( ) ;
55
+ let showConfirmationStub : sinon . SinonStub ;
56
+ let namespaceHasSearchIndexesStub : sinon . SinonStub ;
51
57
52
- beforeEach ( async function ( ) {
58
+ beforeEach ( function ( ) {
53
59
dispatchFake = sinon . fake ( ) ;
54
60
updateCollectionFake = sinon . fake . resolves ( undefined ) ;
61
+ showConfirmationStub = sinon
62
+ . stub ( updateViewSlice , 'showConfirmation' )
63
+ . resolves ( true ) ;
64
+
65
+ namespaceHasSearchIndexesStub = sinon
66
+ . stub ( searchIndexesSlice , 'namespaceHasSearchIndexes' )
67
+ . resolves ( true ) ;
68
+
55
69
stateMock = {
56
70
pipelineBuilder : { pipelineMode : 'builder-ui' } ,
57
71
focusMode : { isEnabled : false } ,
@@ -62,20 +76,57 @@ describe('update-view module', function () {
62
76
updateCollection : updateCollectionFake ,
63
77
} ,
64
78
} ,
79
+ serverVersion : '8.1.0' ,
65
80
} ;
66
81
getStateMock = ( ) => stateMock ;
82
+ } ) ;
67
83
84
+ afterEach ( function ( ) {
85
+ showConfirmationStub . restore ( ) ;
86
+ namespaceHasSearchIndexesStub . restore ( ) ;
87
+ } ) ;
88
+
89
+ it ( 'first it calls to dismiss any existing error' , async function ( ) {
68
90
const runUpdateView = updateView ( ) ;
69
91
await runUpdateView ( dispatchFake , getStateMock , thunkArg as any ) ;
70
- } ) ;
71
92
72
- it ( 'first it calls to dismiss any existing error' , function ( ) {
73
93
expect ( dispatchFake . firstCall . args [ 0 ] ) . to . deep . equal ( {
74
94
type : 'aggregations/update-view/DISMISS_VIEW_UPDATE_ERROR' ,
75
95
} ) ;
76
96
} ) ;
77
97
78
- it ( 'calls the data service to update the view for the provided ns' , function ( ) {
98
+ it ( 'does not shows confirmation banner if search indexes are not present' , async function ( ) {
99
+ namespaceHasSearchIndexesStub . resolves ( false ) ;
100
+ const runUpdateView = updateView ( ) ;
101
+ await runUpdateView ( dispatchFake , getStateMock , thunkArg as any ) ;
102
+
103
+ expect ( showConfirmationStub . calledOnce ) . to . be . false ;
104
+ } ) ;
105
+
106
+ it ( 'shows confirmation banner when search indexes are present' , async function ( ) {
107
+ const runUpdateView = updateView ( ) ;
108
+ await runUpdateView ( dispatchFake , getStateMock , thunkArg as any ) ;
109
+
110
+ expect ( showConfirmationStub . calledOnce ) . to . be . true ;
111
+ expect ( showConfirmationStub . firstCall . args [ 0 ] ) . to . deep . include ( {
112
+ title : `Are you sure you want to update the view?` ,
113
+ buttonText : 'Update' ,
114
+ } ) ;
115
+ } ) ;
116
+
117
+ it ( 'does not update view if not confirmed' , async function ( ) {
118
+ showConfirmationStub . resolves ( false ) ;
119
+
120
+ const runUpdateView = updateView ( ) ;
121
+ await runUpdateView ( dispatchFake , getStateMock , thunkArg as any ) ;
122
+
123
+ expect ( updateCollectionFake . calledOnce ) . to . be . false ;
124
+ } ) ;
125
+
126
+ it ( 'calls the data service to update the view for the provided ns' , async function ( ) {
127
+ const runUpdateView = updateView ( ) ;
128
+ await runUpdateView ( dispatchFake , getStateMock , thunkArg as any ) ;
129
+
79
130
expect ( updateCollectionFake . firstCall . args [ 0 ] ) . to . equal ( 'aa.bb' ) ;
80
131
expect ( updateCollectionFake . firstCall . args [ 1 ] ) . to . deep . equal ( {
81
132
viewOn : 'bb' ,
0 commit comments