Skip to content

Commit

Permalink
fix: adjust tests
Browse files Browse the repository at this point in the history
Signed-off-by: Maksim Sukharev <[email protected]>
  • Loading branch information
Antreesy committed Sep 15, 2024
1 parent eddb2b8 commit 706287b
Show file tree
Hide file tree
Showing 3 changed files with 70 additions and 43 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -314,7 +314,6 @@ describe('FilePreview.vue', () => {
describe('triggering viewer', () => {
let oldViewer
let oldFiles
let getSidebarStatusMock

beforeEach(() => {
oldViewer = OCA.Viewer
Expand All @@ -327,8 +326,6 @@ describe('FilePreview.vue', () => {
},
}

getSidebarStatusMock = jest.fn().mockReturnValue(true)
testStoreConfig.modules.sidebarStore.getters.getSidebarStatus = getSidebarStatusMock
store = new Vuex.Store(testStoreConfig)
})
afterEach(() => {
Expand Down
40 changes: 0 additions & 40 deletions src/store/sidebarStore.spec.js

This file was deleted.

70 changes: 70 additions & 0 deletions src/stores/__tests__/sidebar.spec.js
Original file line number Diff line number Diff line change
@@ -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()
})
})

0 comments on commit 706287b

Please sign in to comment.