diff --git a/src/components/MessagesList/MessagesGroup/Message/MessagePart/FilePreview.spec.js b/src/components/MessagesList/MessagesGroup/Message/MessagePart/FilePreview.spec.js index 098107f0f14..d0d8044f31b 100644 --- a/src/components/MessagesList/MessagesGroup/Message/MessagePart/FilePreview.spec.js +++ b/src/components/MessagesList/MessagesGroup/Message/MessagePart/FilePreview.spec.js @@ -314,7 +314,6 @@ describe('FilePreview.vue', () => { describe('triggering viewer', () => { let oldViewer let oldFiles - let getSidebarStatusMock beforeEach(() => { oldViewer = OCA.Viewer @@ -327,8 +326,6 @@ describe('FilePreview.vue', () => { }, } - getSidebarStatusMock = jest.fn().mockReturnValue(true) - testStoreConfig.modules.sidebarStore.getters.getSidebarStatus = getSidebarStatusMock store = new Vuex.Store(testStoreConfig) }) afterEach(() => { diff --git a/src/store/sidebarStore.spec.js b/src/store/sidebarStore.spec.js deleted file mode 100644 index 500fe1203b3..00000000000 --- a/src/store/sidebarStore.spec.js +++ /dev/null @@ -1,40 +0,0 @@ -/** - * SPDX-FileCopyrightText: 2021 Nextcloud GmbH and Nextcloud contributors - * SPDX-License-Identifier: AGPL-3.0-or-later - */ -import { createLocalVue } from '@vue/test-utils' -import { cloneDeep } from 'lodash' -import Vuex from 'vuex' - -import sidebarStore from './sidebarStore.js' - -describe('sidebarStore', () => { - let localVue = null - let store = null - - beforeEach(() => { - localVue = createLocalVue() - localVue.use(Vuex) - - // eslint-disable-next-line import/no-named-as-default-member - store = new Vuex.Store(cloneDeep(sidebarStore)) - }) - - afterEach(() => { - jest.clearAllMocks() - }) - - test('defaults are off', () => { - expect(store.getters.getSidebarStatus).toBe(true) - }) - - test('toggle sidebar', () => { - store.dispatch('hideSidebar') - - expect(store.getters.getSidebarStatus).toBe(false) - - store.dispatch('showSidebar') - - expect(store.getters.getSidebarStatus).toBe(true) - }) -}) diff --git a/src/stores/__tests__/sidebar.spec.js b/src/stores/__tests__/sidebar.spec.js new file mode 100644 index 00000000000..a47a48f854f --- /dev/null +++ b/src/stores/__tests__/sidebar.spec.js @@ -0,0 +1,70 @@ +/** + * SPDX-FileCopyrightText: 2023 Nextcloud GmbH and Nextcloud contributors + * SPDX-License-Identifier: AGPL-3.0-or-later + */ +import { setActivePinia, createPinia } from 'pinia' + +import { emit } from '@nextcloud/event-bus' + +import BrowserStorage from '../../services/BrowserStorage.js' +import { useSidebarStore } from '../sidebar.js' + +jest.mock('@nextcloud/event-bus', () => ({ + emit: jest.fn(), +})) + +jest.mock('../../services/BrowserStorage.js', () => ({ + getItem: jest.fn(), + setItem: jest.fn(), +})) + +describe('sidebarStore', () => { + let sidebarStore + + beforeEach(() => { + setActivePinia(createPinia()) + sidebarStore = useSidebarStore() + }) + + afterEach(() => { + jest.clearAllMocks() + }) + + it('shows the sidebar on selected tab with caching the value', () => { + sidebarStore.showSidebar({ activeTab: 'test-tab', cache: true }) + + expect(sidebarStore.show).toBe(true) + expect(emit).toHaveBeenCalledWith('spreed:select-active-sidebar-tab', 'test-tab') + expect(BrowserStorage.setItem).toHaveBeenCalledWith('sidebarOpen', 'true') + }) + + it('shows the sidebar with caching the value', () => { + sidebarStore.showSidebar() + + expect(sidebarStore.show).toBe(true) + expect(emit).not.toHaveBeenCalled() + expect(BrowserStorage.setItem).toHaveBeenCalledWith('sidebarOpen', 'true') + }) + + it('shows the sidebar without caching the value', () => { + sidebarStore.showSidebar({ cache: false }) + + expect(sidebarStore.show).toBe(true) + expect(emit).not.toHaveBeenCalled() + expect(BrowserStorage.setItem).not.toHaveBeenCalled() + }) + + it('hides the sidebar with caching the value', () => { + sidebarStore.hideSidebar() + + expect(sidebarStore.show).toBe(false) + expect(BrowserStorage.setItem).toHaveBeenCalledWith('sidebarOpen', 'false') + }) + + it('hides the sidebar without caching the value', () => { + sidebarStore.hideSidebar({ cache: false }) + + expect(sidebarStore.show).toBe(false) + expect(BrowserStorage.setItem).not.toHaveBeenCalled() + }) +})