44 lines
1.6 KiB
TypeScript
44 lines
1.6 KiB
TypeScript
import { describe, expect, test } from 'vitest'
|
|
import { ref } from 'vue'
|
|
import { useSort } from './sort'
|
|
|
|
describe('useSort', () => {
|
|
const array = ref([{ key1: 'b', key2: 'a' }, { key1: 'a', key2: 'b' }])
|
|
|
|
test('Returns expected properties with default options', () => {
|
|
const { sortedArray, headerProps, showColumn } = useSort(array)
|
|
|
|
expect(sortedArray).toBeDefined()
|
|
expect(headerProps).toBeDefined()
|
|
expect(showColumn).toBeDefined()
|
|
})
|
|
|
|
test('Returns expected properties with custom options', () => {
|
|
const { sortedArray, headerProps, showColumn } = useSort(array, { defaultSortKey: 'key1', defaultSortDirection: 'asc' })
|
|
|
|
expect(sortedArray.value[0].key1).toBe('a')
|
|
expect(headerProps.value.currentSortKey).toBe('key1')
|
|
expect(headerProps.value.sortDirection).toBe('asc')
|
|
expect(showColumn('key1')).toBe(true)
|
|
})
|
|
|
|
test('Sorts array in ascending order', () => {
|
|
const { sortedArray, headerProps } = useSort(array, { defaultSortKey: 'key1', defaultSortDirection: 'asc' })
|
|
|
|
headerProps.value.onSort('key1', 'asc')
|
|
expect(sortedArray.value[0].key1).toBe('a')
|
|
})
|
|
|
|
test('Sorts array in descending order', () => {
|
|
const { sortedArray, headerProps } = useSort(array, { defaultSortKey: 'key1', defaultSortDirection: 'desc' })
|
|
|
|
headerProps.value.onSort('key1', 'desc')
|
|
expect(sortedArray.value[0].key1).toBe('b')
|
|
})
|
|
|
|
test('Hides ignored columns', () => {
|
|
const { showColumn } = useSort(array, { ignoredColumns: ['key1'] })
|
|
|
|
expect(showColumn('key1')).toBe(false)
|
|
})
|
|
}) |