Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions src/store/filesSorting.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,13 @@ import { loadState } from '@nextcloud/initial-state'
import axios from '@nextcloud/axios'
import { generateOcsUrl } from '@nextcloud/router'

const DEFAULT_SORTING_DIRECTION = 'asc'
const DEFAULT_SORTING_DIRECTION = 'desc'

export const useFilesSortingStore = defineStore('filesSorting', {
state: () => {
const initialSorting = loadState('libresign', 'sorting', { sorting_mode: 'name', sorting_direction: DEFAULT_SORTING_DIRECTION })
const initialSorting = loadState('libresign', 'sorting', { sorting_mode: 'created_at', sorting_direction: DEFAULT_SORTING_DIRECTION })
return {
sortingMode: initialSorting.sorting_mode || 'name',
sortingMode: initialSorting.sorting_mode || 'created_at',
sortingDirection: initialSorting.sorting_direction || DEFAULT_SORTING_DIRECTION,
}
},
Expand All @@ -36,7 +36,7 @@ export const useFilesSortingStore = defineStore('filesSorting', {
}
// else sort ASC by this new key
this.sortingMode = key
this.sortingDirection = DEFAULT_SORTING_DIRECTION
this.sortingDirection = 'asc'
this.saveSorting()
emit('libresign:sorting:update')
},
Expand Down
29 changes: 13 additions & 16 deletions src/tests/plugins/vuelidate.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* SPDX-License-Identifier: AGPL-3.0-or-later
*/

import { describe, it, expect, vi } from 'vitest'
import { describe, it, expect, vi, beforeEach } from 'vitest'

// Mock @nextcloud packages before any other imports
vi.mock('@nextcloud/logger', () => ({
Expand All @@ -25,30 +25,27 @@ vi.mock('@nextcloud/logger', () => ({
})),
}))

const mockVue = {
use: vi.fn(),
}

vi.mock('vue', async () => {
const actual = await vi.importActual('vue')
const Vue = actual.default ?? actual
return {
...actual,
default: Object.assign(Vue, {
use: mockVue.use,
}),
}
})
const mockUse = vi.fn()

vi.mock('vue', () => ({
default: {
use: mockUse,
},
}))

vi.mock('vuelidate', () => ({
default: {},
}))

describe('vuelidate plugin', () => {
beforeEach(() => {
mockUse.mockClear()
})

it('registers Vuelidate plugin with Vue', async () => {
vi.resetModules()
await import('../../plugins/vuelidate.js')

expect(mockVue.use).toHaveBeenCalled()
expect(mockUse).toHaveBeenCalled()
})
})
12 changes: 6 additions & 6 deletions src/tests/store/filesSorting.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ vi.mock('@nextcloud/event-bus', () => ({
}))

vi.mock('@nextcloud/initial-state', () => ({
loadState: () => ({ sorting_mode: 'name', sorting_direction: 'asc' }),
loadState: () => ({ sorting_mode: 'created_at', sorting_direction: 'desc' }),
}))

vi.mock('@nextcloud/axios', () => ({
Expand All @@ -42,7 +42,7 @@ describe('filesSorting store', () => {

await store.toggleSortingDirection()

expect(store.sortingDirection).toBe('desc')
expect(store.sortingDirection).toBe('asc')
expect(emitMock).toHaveBeenCalledWith('libresign:sorting:update')
})

Expand Down Expand Up @@ -86,11 +86,11 @@ describe('filesSorting store', () => {
expect(putMock).toHaveBeenCalledTimes(2)
expect(putMock).toHaveBeenCalledWith(
'/apps/libresign/api/v1/account/config/sorting_mode',
{ value: 'name' }
{ value: 'created_at' }
)
expect(putMock).toHaveBeenCalledWith(
'/apps/libresign/api/v1/account/config/sorting_direction',
{ value: 'asc' }
{ value: 'desc' }
)
})

Expand All @@ -108,8 +108,8 @@ describe('filesSorting store', () => {
it('maintains initial state from loadState', () => {
const store = useFilesSortingStore()

expect(store.sortingMode).toBe('name')
expect(store.sortingDirection).toBe('asc')
expect(store.sortingMode).toBe('created_at')
expect(store.sortingDirection).toBe('desc')
})

it('emits event after toggling direction', async () => {
Expand Down
Loading