fix(web): resolve feature install status sync and mutual exclusivity (#214)

This commit is contained in:
SnapOtter
2026-06-13 13:44:37 +08:00
parent 4e14e00a4c
commit 492da820f8
4 changed files with 40 additions and 13 deletions
+6 -3
View File
@@ -123,12 +123,15 @@ describe("useFeaturesStore", () => {
expect(useFeaturesStore.getState().loadError).toBe(true);
});
it("skips fetch if already loaded without error", async () => {
useFeaturesStore.setState({ loaded: true, loadError: false });
it("does a background refresh if already loaded without error", async () => {
const bundles = [makeBundleState({ id: "bundle-a" })];
useFeaturesStore.setState({ loaded: true, loadError: false, bundles });
apiGetMock.mockResolvedValueOnce({ bundles });
await useFeaturesStore.getState().fetch();
expect(apiGetMock).not.toHaveBeenCalled();
// Should call apiGet for a background refresh (not short-circuit)
expect(apiGetMock).toHaveBeenCalledWith("/v1/features");
});
it("retries fetch if previously loaded with error", async () => {
+4 -2
View File
@@ -2010,10 +2010,12 @@ describe("useFeaturesStore", () => {
expect(s.loaded).toBe(true);
});
it("fetch skips when already loaded without error", async () => {
it("fetch triggers background refresh when already loaded without error", async () => {
const bundles = [{ id: "ocr", name: "OCR", status: "installed" }];
mockApiGet.mockResolvedValueOnce({ bundles });
useFeaturesStore.setState({ loaded: true, loadError: false });
await useFeaturesStore.getState().fetch();
expect(mockApiGet).not.toHaveBeenCalled();
expect(mockApiGet).toHaveBeenCalledWith("/v1/features");
});
it("fetch sets loaded=true and loadError=true on error", async () => {