|
| 1 | +import { describe, expect, it } from "vitest"; |
| 2 | + |
| 3 | +import { applyDefaultMutedFilter, MUTED_FILTER } from "./findings-filters"; |
| 4 | + |
| 5 | +describe("applyDefaultMutedFilter", () => { |
| 6 | + it("injects filter[muted]=false when the caller has not set it", () => { |
| 7 | + const input: Record<string, string> = { "filter[status__in]": "FAIL" }; |
| 8 | + const result = applyDefaultMutedFilter(input); |
| 9 | + |
| 10 | + expect(result["filter[muted]"]).toBe(MUTED_FILTER.EXCLUDE); |
| 11 | + expect(result["filter[status__in]"]).toBe("FAIL"); |
| 12 | + }); |
| 13 | + |
| 14 | + it("preserves an explicit filter[muted]=include opt-in from the checkbox", () => { |
| 15 | + const result = applyDefaultMutedFilter({ |
| 16 | + "filter[muted]": MUTED_FILTER.INCLUDE, |
| 17 | + }); |
| 18 | + |
| 19 | + expect(result["filter[muted]"]).toBe(MUTED_FILTER.INCLUDE); |
| 20 | + }); |
| 21 | + |
| 22 | + it("preserves an explicit filter[muted]=false (no silent overwrite)", () => { |
| 23 | + const result = applyDefaultMutedFilter({ |
| 24 | + "filter[muted]": MUTED_FILTER.EXCLUDE, |
| 25 | + }); |
| 26 | + |
| 27 | + expect(result["filter[muted]"]).toBe(MUTED_FILTER.EXCLUDE); |
| 28 | + }); |
| 29 | + |
| 30 | + it("does not mutate the input object", () => { |
| 31 | + const input = { "filter[status__in]": "FAIL" }; |
| 32 | + applyDefaultMutedFilter(input); |
| 33 | + |
| 34 | + expect(input).not.toHaveProperty("filter[muted]"); |
| 35 | + }); |
| 36 | + |
| 37 | + it("returns a default-filled object when called with no caller filters", () => { |
| 38 | + const result = applyDefaultMutedFilter({} as Record<string, string>); |
| 39 | + |
| 40 | + expect(result["filter[muted]"]).toBe(MUTED_FILTER.EXCLUDE); |
| 41 | + }); |
| 42 | +}); |
0 commit comments