Skip to content

Commit

Permalink
updated test suite
Browse files Browse the repository at this point in the history
  • Loading branch information
BabyElias committed Aug 21, 2024
1 parent cb0d3ae commit 109c7d3
Showing 1 changed file with 20 additions and 5 deletions.
25 changes: 20 additions & 5 deletions lib/KTable/useSorting/__tests__/index.spec.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { ref } from '@vue/composition-api';
import _ from 'lodash';
import useSorting, {
SORT_ORDER_ASC,
SORT_ORDER_DESC,
Expand Down Expand Up @@ -41,26 +40,42 @@ describe('useSorting', () => {

handleSort(0); // Sort by 'Name'

expect(sortedRows.value).toEqual(_.orderBy(rows.value, [row => row[0]], [SORT_ORDER_ASC]));
expect(sortedRows.value).toEqual([
['Alice', 28, new Date(1992, 8, 10)],
['Jane', 25, new Date(1995, 10, 20)],
['John', 30, new Date(1990, 5, 15)],
]);
});

it('should sort rows by numeric column in ascending and descending order', () => {
const { handleSort, sortedRows, sortOrder } = useSorting(headers, rows, useLocalSorting);

handleSort(1); // Sort by 'Age'
expect(sortedRows.value).toEqual(_.orderBy(rows.value, [row => row[1]], [SORT_ORDER_ASC]));
expect(sortedRows.value).toEqual([
['Jane', 25, new Date(1995, 10, 20)],
['Alice', 28, new Date(1992, 8, 10)],
['John', 30, new Date(1990, 5, 15)],
]);
expect(sortOrder.value).toBe(SORT_ORDER_ASC);

handleSort(1); // Sort by 'Age' again to toggle order
expect(sortedRows.value).toEqual(_.orderBy(rows.value, [row => row[1]], [SORT_ORDER_DESC]));
expect(sortedRows.value).toEqual([
['John', 30, new Date(1990, 5, 15)],
['Alice', 28, new Date(1992, 8, 10)],
['Jane', 25, new Date(1995, 10, 20)],
]);
expect(sortOrder.value).toBe(SORT_ORDER_DESC);
});

it('should sort rows by date column in ascending order', () => {
const { handleSort, sortedRows } = useSorting(headers, rows, useLocalSorting);

handleSort(2); // Sort by 'Birthdate'
expect(sortedRows.value).toEqual(_.orderBy(rows.value, [row => row[2]], [SORT_ORDER_ASC]));
expect(sortedRows.value).toEqual([
['John', 30, new Date(1990, 5, 15)],
['Alice', 28, new Date(1992, 8, 10)],
['Jane', 25, new Date(1995, 10, 20)],
]);
});

it('should not sort rows when sorting by a column with dataType "others"', () => {
Expand Down

0 comments on commit 109c7d3

Please sign in to comment.