fix(plex): round-2 deep-review follow-ups on the review fixes

Second review round, scoped to the round-1 fix commit (where round-1's own fixes
introduced new code):

- The collection chip-remove pruned collectionTitles to an empty {} on last removal,
  which still hashes differently from the pristine no-collection state (key absent) in
  the React Query keys → a residual cache split. Collapse an empty map to undefined so
  the key-shape matches the pristine one.
- Replace the tautological "order-independent signature" test (both objects spread from
  EMPTY_PLEX_FILTERS inherited the same key order, so it proved nothing) with full
  literals in genuinely different insertion order that would fail an order-sensitive
  JSON.stringify signature.
- Cover the collectionTitles chip-remove prune (usePlexActiveFilters.dom.test.tsx) and
  the plexSurprise/plexDiscover lang-key split (queryKeys.test.ts) with regression tests.

Gate: tsc/lint/knip/prettier clean, 412 vitest.
This commit is contained in:
2026-08-23 01:53:33 +02:00
parent b7a4eaff8d
commit 8f1309fa18
4 changed files with 61 additions and 7 deletions
+23 -5
View File
@@ -44,11 +44,29 @@ describe("plexFiltersSignature", () => {
collections: ["A"],
});
it("is independent of key order for equivalent filters", () => {
// Same field values, keys assigned in a different literal order — appendPlexFilters emits by field,
// not by object key order, so the signatures must match.
const a: PlexFilters = { ...EMPTY_PLEX_FILTERS, genres: ["Drama"], collections: ["A"] };
const b: PlexFilters = { ...EMPTY_PLEX_FILTERS, collections: ["A"], genres: ["Drama"] };
it("is independent of object key insertion order", () => {
// Full literals with genuinely different key INSERTION order (NOT spread from a shared base, which
// would inherit that base's order and make this tautological). appendPlexFilters reads by field, so
// the signatures must match — this test FAILS against an order-sensitive JSON.stringify signature.
const a: PlexFilters = {
genres: ["Drama"],
contentRatings: [],
directors: [],
actors: [],
studios: [],
keywords: [],
collections: ["A"],
};
const b: PlexFilters = {
collections: ["A"],
keywords: [],
studios: [],
actors: [],
directors: [],
contentRatings: [],
genres: ["Drama"],
};
expect(JSON.stringify(Object.keys(a))).not.toBe(JSON.stringify(Object.keys(b))); // orders truly differ
expect(plexFiltersSignature(a)).toBe(plexFiltersSignature(b));
});