Add some tests
This commit is contained in:
44
src/components/table/sort.spec.ts
Normal file
44
src/components/table/sort.spec.ts
Normal file
@@ -0,0 +1,44 @@
|
||||
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, { ignoredColums: ['key1'] })
|
||||
|
||||
expect(showColumn('key1')).toBe(false)
|
||||
})
|
||||
})
|
||||
@@ -10,9 +10,9 @@ export type ScanResult = {
|
||||
orderCount: number,
|
||||
}
|
||||
|
||||
interface MarketScan {
|
||||
owner: string;
|
||||
types: number[];
|
||||
type MarketScan = {
|
||||
owner: string,
|
||||
types: number[]
|
||||
};
|
||||
|
||||
const marketScans = 'marketScans';
|
||||
@@ -21,7 +21,7 @@ export const useMarketScanStore = defineStore(marketScans, () => {
|
||||
const marketScan = ref<MarketScan>();
|
||||
|
||||
const types = computed(() => marketScan.value?.types ?? []);
|
||||
const setTypes = async (_types: number[]) => {
|
||||
const setTypes = async (types: number[]) => {
|
||||
|
||||
}
|
||||
const addType = async (type: number) => {
|
||||
|
||||
Reference in New Issue
Block a user