@@ -26,6 +26,13 @@ jest.mock('../../services/conversationsService', () => ({
2626// short-circuit debounce
2727jest . mock ( 'debounce' , ( ) => jest . fn ( ) . mockImplementation ( fn => fn ) )
2828
29+ window . navigator . locks = {
30+ request : jest . fn ( ) . mockImplementation ( ( name , callback ) => {
31+ callback ( )
32+ return new Promise ( ( ) => { } )
33+ } ) ,
34+ }
35+
2936describe ( 'LeftSidebar.vue' , ( ) => {
3037 let store
3138 let localVue
@@ -38,8 +45,8 @@ describe('LeftSidebar.vue', () => {
3845
3946 const SEARCH_TERM = 'search'
4047
41- const mountComponent = ( ) => {
42- return mount ( LeftSidebar , {
48+ const mountComponent = async ( ) => {
49+ const wrapper = mount ( LeftSidebar , {
4350 localVue,
4451 router,
4552 store,
@@ -51,6 +58,8 @@ describe('LeftSidebar.vue', () => {
5158 NcModal : true ,
5259 } ,
5360 } )
61+ await flushPromises ( )
62+ return wrapper
5463 }
5564
5665 beforeEach ( ( ) => {
@@ -129,7 +138,7 @@ describe('LeftSidebar.vue', () => {
129138 EventBus . $once ( 'conversations-received' , conversationsReceivedEvent )
130139 fetchConversationsAction . mockResolvedValueOnce ( )
131140
132- const wrapper = mountComponent ( )
141+ const wrapper = await mountComponent ( )
133142
134143 expect ( fetchConversationsAction ) . toHaveBeenCalledWith ( expect . anything ( ) , expect . anything ( ) )
135144 expect ( conversationsListMock ) . toHaveBeenCalled ( )
@@ -138,14 +147,10 @@ describe('LeftSidebar.vue', () => {
138147 expect ( conversationListItems ) . toHaveLength ( conversationsList . length )
139148
140149 expect ( wrapper . vm . searchText ) . toBe ( '' )
141- expect ( wrapper . vm . initialisedConversations ) . toBeFalsy ( )
150+ expect ( wrapper . vm . initialisedConversations ) . toBeTruthy ( )
142151
143- expect ( conversationsReceivedEvent ) . not . toHaveBeenCalled ( )
152+ expect ( conversationsReceivedEvent ) . toHaveBeenCalled ( )
144153
145- // move on past the fetchConversation call
146- await flushPromises ( )
147-
148- expect ( wrapper . vm . initialisedConversations ) . toBeTruthy ( )
149154 expect ( conversationListItems . at ( 0 ) . props ( 'item' ) ) . toStrictEqual ( conversationsList [ 2 ] )
150155 expect ( conversationListItems . at ( 1 ) . props ( 'item' ) ) . toStrictEqual ( conversationsList [ 0 ] )
151156 expect ( conversationListItems . at ( 2 ) . props ( 'item' ) ) . toStrictEqual ( conversationsList [ 1 ] )
@@ -156,7 +161,7 @@ describe('LeftSidebar.vue', () => {
156161 } )
157162
158163 test ( 're-fetches conversations every 30 seconds' , async ( ) => {
159- const wrapper = mountComponent ( )
164+ const wrapper = await mountComponent ( )
160165 expect ( wrapper . exists ( ) ) . toBeTruthy ( )
161166 expect ( fetchConversationsAction ) . toHaveBeenCalled ( )
162167
@@ -174,7 +179,7 @@ describe('LeftSidebar.vue', () => {
174179 } )
175180
176181 test ( 're-fetches conversations when receiving bus event' , async ( ) => {
177- const wrapper = mountComponent ( )
182+ const wrapper = await mountComponent ( )
178183 expect ( wrapper . exists ( ) ) . toBeTruthy ( )
179184 expect ( fetchConversationsAction ) . toHaveBeenCalled ( )
180185
@@ -301,7 +306,7 @@ describe('LeftSidebar.vue', () => {
301306 loadStateSettings = loadStateSettingsOverride
302307 }
303308
304- const wrapper = mountComponent ( )
309+ const wrapper = await mountComponent ( )
305310
306311 expect ( fetchConversationsAction ) . toHaveBeenCalledWith ( expect . anything ( ) , expect . anything ( ) )
307312 expect ( conversationsListMock ) . toHaveBeenCalled ( )
@@ -704,18 +709,18 @@ describe('LeftSidebar.vue', () => {
704709 conversationsListMock . mockReturnValue ( [ ] )
705710 fetchConversationsAction . mockResolvedValueOnce ( )
706711 } )
707- test ( 'shows new conversation button if user can start conversations' , ( ) => {
712+ test ( 'shows new conversation button if user can start conversations' , async ( ) => {
708713 loadStateSettings . start_conversations = true
709714
710- const wrapper = mountComponent ( )
715+ const wrapper = await mountComponent ( )
711716 const newConversationbutton = findNcActionButton ( wrapper , 'Create a new conversation' )
712717 expect ( newConversationbutton . exists ( ) ) . toBeTruthy ( )
713718
714719 } )
715- test ( 'does not show new conversation button if user cannot start conversations' , ( ) => {
720+ test ( 'does not show new conversation button if user cannot start conversations' , async ( ) => {
716721 loadStateSettings . start_conversations = false
717722
718- const wrapper = mountComponent ( )
723+ const wrapper = await mountComponent ( )
719724 const newConversationbutton = findNcActionButton ( wrapper , 'Create a new conversation' )
720725 expect ( newConversationbutton . exists ( ) ) . toBeFalsy ( )
721726 } )
@@ -725,7 +730,7 @@ describe('LeftSidebar.vue', () => {
725730 conversationsListMock . mockImplementation ( ( ) => [ ] )
726731 const eventHandler = jest . fn ( )
727732 subscribe ( 'show-settings' , eventHandler )
728- const wrapper = mountComponent ( )
733+ const wrapper = await mountComponent ( )
729734
730735 const button = wrapper . find ( '.settings-button' )
731736 expect ( button . exists ( ) ) . toBeTruthy ( )
0 commit comments