Files
factorio-clusterio/test/web_ui/useResourceState.js
Danielv123 2e1710d3a9 Show the same page for missing, deleted and unloadable resources
Every view page handled a resource that can't be shown its own way, and
users without the subscribe permission were left on a spinner forever.

Adds useResourceState and a ResourceState component, used by the host,
instance, mod pack, icon reference, user, role and plugin pages and
exported for plugin pages. The single item hooks now also return the
subscription error.

Resolves #1165
2026-11-01 17:40:22 +01:00

38 lines
1.7 KiB
JavaScript

import assert from "node:assert/strict";
import { getResourceStatus } from "../../packages/web_ui/src/util/useResourceState.ts";
describe("web_ui/util/useResourceState", function() {
describe("getResourceStatus()", function() {
const error = new Error("Permission denied");
it("should be ok when the resource exists", function() {
assert.equal(getResourceStatus(true, true, true, null), "ok");
});
it("should keep showing a resource after the subscription stopped syncing", function() {
assert.equal(getResourceStatus(true, true, false, null), "ok");
assert.equal(getResourceStatus(true, true, false, error), "ok");
});
it("should be loading until the subscription has synced", function() {
assert.equal(getResourceStatus(false, false, false, null), "loading");
});
it("should be loading while resyncing a resource that was seen", function() {
assert.equal(getResourceStatus(false, true, false, null), "loading");
});
it("should be missing when synced without having seen the resource", function() {
assert.equal(getResourceStatus(false, false, true, null), "missing");
});
it("should be deleted when synced after having seen the resource", function() {
assert.equal(getResourceStatus(false, true, true, null), "deleted");
});
it("should be error when the subscription failed", function() {
assert.equal(getResourceStatus(false, false, false, error), "error");
assert.equal(getResourceStatus(false, true, false, error), "error");
});
it("should ignore the error of an earlier attempt once synced", function() {
assert.equal(getResourceStatus(false, false, true, error), "missing");
assert.equal(getResourceStatus(false, true, true, error), "deleted");
});
});
});