fix(stats): address review findings on franchise walk and group view

- The relation walk keeps every incoming link to an entry and follows it when
  any link is accepted, so a veto on one seed no longer hides a franchise root
  reached through another (and seed order no longer changes the result).
- A stopped refresher starts no further AniList request; the in-flight result
  is dropped and the walk ends.
- An open franchise that is left with one part closes once the library has
  loaded, so a later refresh cannot reopen it on its own.
This commit is contained in:
sudacode committed 2026-11-22 14:37:03 -08:00
1 parent 55110fd592
commit 4a78b946d9
5 files changed
+122 -18

No files matched your search

@@ -132,3 +132,47 @@ test('a franchise card opens its parts in release order, and a part can stand al
uninstallDom();
}
});
test('a franchise left with one part closes and does not reopen on a later refresh', async () => {
const uninstallDom = installDom();
const original = { ...apiClient };
const [movie, season] = overlord.parts as [AnimeLibraryGroupPart, AnimeLibraryGroupPart];
const split: AnimeLibraryGroup[] = [
{ ...overlord, parts: [movie], coverAnimeId: movie.animeId },
{ ...overlord, groupKey: 1, title: season.canonicalTitle, parts: [season], coverAnimeId: 1 },
];
let library: AnimeLibraryGroup[] = [overlord];
apiClient.getAnimeLibraryGroups = async () => library;
apiClient.getAnimeMergeRecommendations = async () => ({ recommendations: [] });
apiClient.getAnimeDetail = async () => detailData();
apiClient.getAnimeWords = async () => [];
apiClient.getAnimeRollups = async () => [];
apiClient.getAnimeKnownWordsSummary = async () => ({ totalUniqueWords: 0, knownWordCount: 0 });
apiClient.setAnimeGroupOverride = async () => {
library = split;
};
const container = document.createElement('div');
document.body.append(container);
const root = createRoot(container);
try {
await act(async () => root.render(<AnimeTab />));
await act(async () => findButton(container, 'Overlord').click());
await act(async () => findButton(container, 'Overlord II').click());
await act(async () => findButton(container, 'Show On Its Own').click());
await act(async () => findButton(container, 'Back to Overlord').click());
assert.doesNotMatch(container.textContent ?? '', /Seasons and Movies/);
// The franchise gets its second part back; the library must stay where it is.
library = [overlord];
await act(async () => {
window.dispatchEvent(new window.Event('focus'));
});
assert.match(findButton(container, 'Overlord').textContent ?? '', /2 parts/);
assert.doesNotMatch(container.textContent ?? '', /Seasons and Movies/);
} finally {
await act(async () => root.unmount());
Object.assign(apiClient, original);
uninstallDom();
}
});
+7
View File
@@ -161,6 +161,13 @@ export function AnimeTab({
0,
);
const selectedGroup = groups.find((group) => group.groupKey === selectedGroupKey) ?? null;
// A franchise that no longer has several parts closes, so a later refresh
// cannot reopen it on its own. Only loaded results count; while a part is
// open, the franchise stays its back target.
useEffect(() => {
if (loading || selectedGroupKey === null || selectedAnimeId !== null) return;
if (!selectedGroup || selectedGroup.parts.length < 2) setSelectedGroupKey(null);
}, [loading, selectedGroupKey, selectedAnimeId, selectedGroup]);
const checkedEntries = checkedAnimeIds
.map((animeId) => anime.find((entry) => entry.animeId === animeId))
.filter((entry): entry is (typeof anime)[number] => entry !== undefined);