@@ -10,6 +10,10 @@ import {
1010} from '@mongodb-js/compass-connections/provider' ;
1111import { createDefaultConnectionInfo } from '@mongodb-js/testing-library-compass' ;
1212
13+ // Importing this to stub showConfirmation
14+ import * as updateViewSlice from './update-view' ;
15+ import * as searchIndexesSlice from './search-indexes' ;
16+
1317const TEST_CONNECTION_INFO = { ...createDefaultConnectionInfo ( ) , title : '' } ;
1418
1519describe ( 'update-view module' , function ( ) {
@@ -48,10 +52,20 @@ describe('update-view module', function () {
4852 let stateMock : any ;
4953 let getStateMock : ( ) => any ;
5054 let updateCollectionFake = sinon . fake ( ) ;
55+ let showConfirmationStub : sinon . SinonStub ;
56+ let namespaceHasSearchIndexesStub : sinon . SinonStub ;
5157
52- beforeEach ( async function ( ) {
58+ beforeEach ( function ( ) {
5359 dispatchFake = sinon . fake ( ) ;
5460 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+
5569 stateMock = {
5670 pipelineBuilder : { pipelineMode : 'builder-ui' } ,
5771 focusMode : { isEnabled : false } ,
@@ -62,20 +76,57 @@ describe('update-view module', function () {
6276 updateCollection : updateCollectionFake ,
6377 } ,
6478 } ,
79+ serverVersion : '8.1.0' ,
6580 } ;
6681 getStateMock = ( ) => stateMock ;
82+ } ) ;
6783
84+ afterEach ( function ( ) {
85+ showConfirmationStub . restore ( ) ;
86+ namespaceHasSearchIndexesStub . restore ( ) ;
87+ } ) ;
88+
89+ it ( 'first it calls to dismiss any existing error' , async function ( ) {
6890 const runUpdateView = updateView ( ) ;
6991 await runUpdateView ( dispatchFake , getStateMock , thunkArg as any ) ;
70- } ) ;
7192
72- it ( 'first it calls to dismiss any existing error' , function ( ) {
7393 expect ( dispatchFake . firstCall . args [ 0 ] ) . to . deep . equal ( {
7494 type : 'aggregations/update-view/DISMISS_VIEW_UPDATE_ERROR' ,
7595 } ) ;
7696 } ) ;
7797
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+
79130 expect ( updateCollectionFake . firstCall . args [ 0 ] ) . to . equal ( 'aa.bb' ) ;
80131 expect ( updateCollectionFake . firstCall . args [ 1 ] ) . to . deep . equal ( {
81132 viewOn : 'bb' ,
0 commit comments