Skip to content

Commit cedcf18

Browse files
committed
fix unit test only for version vue3
1 parent 7e6fa5c commit cedcf18

File tree

2 files changed

+8
-9
lines changed

2 files changed

+8
-9
lines changed

src/utils/helpers.ts

+2-3
Original file line numberDiff line numberDiff line change
@@ -62,10 +62,10 @@ export const getSortsArrayFromOrdering = (ordering: Array<string>|null): Vuetify
6262
return { sortBy, sortDesc };
6363
}
6464

65-
export const getOrderingFromSortArray = (sortBy: Array<string> | Array<{ key: string; order: 'asc' | 'desc'; }>, sortDesc: Array<boolean>): Array<string> => {
65+
export const getOrderingFromSortArray = (sortBy: Array<string | { key: string; order: 'asc' | 'desc'; }>, sortDesc: Array<boolean>): Array<string> => {
6666
let ordering: Array<string> = [];
6767
if(isVue2) {
68-
sortBy.forEach((orderItem, index) => {
68+
(sortBy as string[]).forEach((orderItem: string, index: number) => {
6969
let isDesc = true;
7070
if (sortDesc.length > index) {
7171
isDesc = sortDesc[index];
@@ -82,6 +82,5 @@ export const getOrderingFromSortArray = (sortBy: Array<string> | Array<{ key: st
8282
[]
8383
);
8484
}
85-
console.log(sortBy, ordering)
8685
return ordering;
8786
}

tests/unit/helpers.spec.ts

+6-6
Original file line numberDiff line numberDiff line change
@@ -119,30 +119,30 @@ describe('helpers.ts', () => {
119119
const element = ["ordering_field"];
120120
const returnValue = getSortsArrayFromOrdering(element);
121121

122-
expect(returnValue).toEqual({ sortBy: ["ordering_field"], sortDesc: [false] })
122+
expect(returnValue).toEqual({ sortBy: [{key: "ordering_field", order: "asc"}], sortDesc: [] })
123123
})
124124

125125
it("return correct VuetifySortArraysObject if negative ordering", () => {
126126
const element = ["-ordering_field"];
127127
const returnValue = getSortsArrayFromOrdering(element);
128128

129-
expect(returnValue).toEqual({ sortBy: ["ordering_field"], sortDesc: [true] })
129+
expect(returnValue).toEqual({ sortBy: [{key: "ordering_field", order: "desc"}], sortDesc: [] })
130130
})
131131
})
132132

133133
describe('getOrderingFromSortArray', () => {
134134

135135
it("return correct ordering if positive ordering", () => {
136-
const sortBy = ["ordering_field"];
137-
const sortDesc = [false];
136+
const sortBy: { key: string; order: 'asc' | 'desc'; }[] = [{key: "ordering_field", order: "asc"}];
137+
const sortDesc: boolean[] = [];
138138
const returnValue = getOrderingFromSortArray(sortBy, sortDesc);
139139

140140
expect(returnValue).toEqual(["ordering_field"])
141141
})
142142

143143
it("return correct ordering if negative ordering", () => {
144-
const sortBy = ["ordering_field"];
145-
const sortDesc = [true];
144+
const sortBy: { key: string; order: 'asc' | 'desc'; }[] = [{key: "ordering_field", order: "desc"}];
145+
const sortDesc: boolean[] = [];
146146
const returnValue = getOrderingFromSortArray(sortBy, sortDesc);
147147

148148
expect(returnValue).toEqual(["-ordering_field"])

0 commit comments

Comments
 (0)