update deps, migrate to pnpm

This commit is contained in:
Jorrin
2024-03-29 21:23:32 +01:00
parent f8a5120064
commit 21f1fd3cee
35 changed files with 15210 additions and 25328 deletions

View File

@@ -1,16 +1,16 @@
import { reorderOnIdList } from "@/utils/list";
import { describe, it, expect } from "vitest";
import { reorderOnIdList } from '@/utils/list';
import { describe, it, expect } from 'vitest';
function list(def: string) {
return def.split(",").map(v=>({
return def.split(',').map((v) => ({
rank: parseInt(v),
id: v,
}))
}));
}
function expectListToEqual(l1: ReturnType<typeof list>, l2: ReturnType<typeof list>) {
function flatten(l: ReturnType<typeof list>) {
return l.map(v=>v.id).join(",");
return l.map((v) => v.id).join(',');
}
expect(flatten(l1)).toEqual(flatten(l2));
}
@@ -18,36 +18,36 @@ function expectListToEqual(l1: ReturnType<typeof list>, l2: ReturnType<typeof li
describe('reorderOnIdList()', () => {
it('should reorder based on rank', () => {
const l = list('2,1,4,3');
const sortedList = list('4,3,2,1')
const sortedList = list('4,3,2,1');
expectListToEqual(reorderOnIdList([], l), sortedList);
});
it('should work with empty input', () => {
expectListToEqual(reorderOnIdList([], []), []);
});
it('should reorder based on id list', () => {
const l = list('4,2,1,3');
const sortedList = list('4,3,2,1')
expectListToEqual(reorderOnIdList(["4","3","2","1"], l), sortedList);
const sortedList = list('4,3,2,1');
expectListToEqual(reorderOnIdList(['4', '3', '2', '1'], l), sortedList);
});
it('should reorder based on id list and rank second', () => {
const l = list('4,2,1,3');
const sortedList = list('4,3,2,1')
expectListToEqual(reorderOnIdList(["4","3"], l), sortedList);
const sortedList = list('4,3,2,1');
expectListToEqual(reorderOnIdList(['4', '3'], l), sortedList);
});
it('should work with only one item', () => {
const l = list('1');
const sortedList = list('1')
expectListToEqual(reorderOnIdList(["1"], l), sortedList);
const sortedList = list('1');
expectListToEqual(reorderOnIdList(['1'], l), sortedList);
expectListToEqual(reorderOnIdList([], l), sortedList);
});
it('should not affect original list', () => {
const l = list('4,3,2,1');
const unsortedList = list('4,3,2,1')
const unsortedList = list('4,3,2,1');
reorderOnIdList([], l);
expectListToEqual(l, unsortedList);
});