aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--frontend/__tests__/elements/account/result-filters.spec.ts80
-rw-r--r--frontend/src/ts/constants/default-result-filters.ts2
2 files changed, 65 insertions, 17 deletions
diff --git a/frontend/__tests__/elements/account/result-filters.spec.ts b/frontend/__tests__/elements/account/result-filters.spec.ts
index 80c450511..f5d1bd15d 100644
--- a/frontend/__tests__/elements/account/result-filters.spec.ts
+++ b/frontend/__tests__/elements/account/result-filters.spec.ts
@@ -1,25 +1,73 @@
-import {
- defaultResultFilters,
- mergeWithDefaultFilters,
-} from "../../../src/ts/elements/account/result-filters";
+import defaultResultFilters from "../../../src/ts/constants/default-result-filters";
+import { mergeWithDefaultFilters } from "../../../src/ts/elements/account/result-filters";
describe("result-filters.ts", () => {
describe("mergeWithDefaultFilters", () => {
it("should merge with default filters correctly", () => {
- const merged = mergeWithDefaultFilters({
- pb: {
- no: false,
- yes: false,
+ const tests = [
+ {
+ input: {
+ pb: {
+ no: false,
+ yes: false,
+ },
+ },
+ expected: () => {
+ const expected = defaultResultFilters;
+ expected.pb.no = false;
+ expected.pb.yes = false;
+ return expected;
+ },
},
+ {
+ input: {
+ words: {
+ "10": false,
+ },
+ },
+ expected: () => {
+ const expected = defaultResultFilters;
+ expected.words["10"] = false;
+ return expected;
+ },
+ },
+ {
+ input: {
+ blah: true,
+ },
+ expected: () => {
+ return defaultResultFilters;
+ },
+ },
+ {
+ input: 1,
+ expected: () => {
+ return defaultResultFilters;
+ },
+ },
+ {
+ input: null,
+ expected: () => {
+ return defaultResultFilters;
+ },
+ },
+ {
+ input: undefined,
+ expected: () => {
+ return defaultResultFilters;
+ },
+ },
+ {
+ input: {},
+ expected: () => {
+ return defaultResultFilters;
+ },
+ },
+ ];
+ tests.forEach((test) => {
+ const merged = mergeWithDefaultFilters(test.input as any);
+ expect(merged).toEqual(test.expected());
});
-
- const expected = JSON.parse(JSON.stringify(defaultResultFilters));
- expected.pb.no = false;
- expected.pb.yes = false;
-
- expect(merged).toEqual(expected);
-
- console.log(defaultResultFilters);
});
});
});
diff --git a/frontend/src/ts/constants/default-result-filters.ts b/frontend/src/ts/constants/default-result-filters.ts
index b831def9a..71ff08662 100644
--- a/frontend/src/ts/constants/default-result-filters.ts
+++ b/frontend/src/ts/constants/default-result-filters.ts
@@ -1,4 +1,4 @@
-import { ResultFilters } from "@monkeytype/shared-types";
+import { ResultFilters } from "@monkeytype/contracts/schemas/users";
const object: ResultFilters = {
_id: "default-result-filters-id",