11import { createLocalVue , mount } from '@vue/test-utils'
22import flushPromises from 'flush-promises' // TODO fix after migration to @vue /test-utils v2.0.0
33import { cloneDeep } from 'lodash'
4+ import { createPinia , setActivePinia } from 'pinia'
45import VueRouter from 'vue-router'
56import Vuex from 'vuex'
67
@@ -13,6 +14,7 @@ import router from '../../__mocks__/router.js'
1314import { searchPossibleConversations , searchListedConversations } from '../../services/conversationsService.js'
1415import { EventBus } from '../../services/EventBus.js'
1516import storeConfig from '../../store/storeConfig.js'
17+ import { useLeaderTabStore } from '../../stores/leaderTab.js'
1618import { findNcListItems , findNcActionButton } from '../../test-helpers.js'
1719
1820jest . mock ( '@nextcloud/initial-state' , ( ) => ( {
@@ -32,7 +34,6 @@ describe('LeftSidebar.vue', () => {
3234 let testStoreConfig
3335 let loadStateSettings
3436 let conversationsListMock
35- let isLeaderTabMock
3637 let fetchConversationsAction
3738 let addConversationAction
3839 let createOneToOneConversationAction
@@ -54,7 +55,7 @@ describe('LeftSidebar.vue', () => {
5455 } )
5556 }
5657
57- beforeEach ( ( ) => {
58+ beforeEach ( async ( ) => {
5859 jest . useFakeTimers ( )
5960
6061 localVue = createLocalVue ( )
@@ -77,19 +78,23 @@ describe('LeftSidebar.vue', () => {
7778
7879 // note: need a copy because the Vue modifies it when sorting
7980 conversationsListMock = jest . fn ( )
80- isLeaderTabMock = jest . fn ( )
8181 fetchConversationsAction = jest . fn ( ) . mockReturnValue ( { headers : { } } )
8282 addConversationAction = jest . fn ( )
8383 createOneToOneConversationAction = jest . fn ( )
8484 const getUserIdMock = jest . fn ( ) . mockReturnValue ( 'current-user' )
8585 testStoreConfig . modules . actorStore . getters . getUserId = ( ) => getUserIdMock
86- testStoreConfig . modules . talkHashStore . getters . isCurrentTabLeader = isLeaderTabMock
8786 testStoreConfig . modules . conversationsStore . getters . conversationsList = conversationsListMock
8887 testStoreConfig . modules . conversationsStore . actions . fetchConversations = fetchConversationsAction
8988 testStoreConfig . modules . conversationsStore . actions . addConversation = addConversationAction
9089 testStoreConfig . modules . conversationsStore . actions . createOneToOneConversation = createOneToOneConversationAction
9190
9291 store = new Vuex . Store ( testStoreConfig )
92+
93+ setActivePinia ( createPinia ( ) )
94+ const leaderTabStore = useLeaderTabStore ( )
95+ await leaderTabStore . requestTabLeadership ( )
96+
97+ // TODO add a unit test for sub-tabs
9398 } )
9499
95100 afterEach ( ( ) => {
@@ -125,7 +130,6 @@ describe('LeftSidebar.vue', () => {
125130
126131 // note: need a copy because the Vue modifies it when sorting
127132 conversationsListMock . mockImplementation ( ( ) => cloneDeep ( conversationsList ) )
128- isLeaderTabMock . mockReturnValue ( true )
129133 } )
130134
131135 test ( 'fetches and renders conversation list initially' , async ( ) => {
@@ -193,22 +197,6 @@ describe('LeftSidebar.vue', () => {
193197 // note: debounce was short-circuited so no delay needed
194198 expect ( fetchConversationsAction ) . toHaveBeenCalled ( )
195199 } )
196-
197- test ( 'doesn\'t fetch conversations if not a leader tab' , async ( ) => {
198- isLeaderTabMock . mockReturnValue ( false )
199- const wrapper = mountComponent ( )
200- expect ( wrapper . exists ( ) ) . toBeTruthy ( )
201- expect ( fetchConversationsAction ) . not . toHaveBeenCalled ( )
202-
203- fetchConversationsAction . mockClear ( )
204-
205- // move past async call
206- await flushPromises ( )
207- expect ( fetchConversationsAction ) . not . toHaveBeenCalled ( )
208-
209- jest . advanceTimersByTime ( 30000 )
210- expect ( fetchConversationsAction ) . not . toHaveBeenCalled ( )
211- } )
212200 } )
213201
214202 describe ( 'search results' , ( ) => {
@@ -293,7 +281,6 @@ describe('LeftSidebar.vue', () => {
293281 // note: need a copy because the Vue modifies it when sorting
294282 conversationsListMock . mockImplementation ( ( ) => cloneDeep ( conversationsList ) )
295283 fetchConversationsAction . mockResolvedValue ( )
296- isLeaderTabMock . mockReturnValue ( true )
297284 } )
298285
299286 /**
0 commit comments