59 lines
1.8 KiB
TypeScript
59 lines
1.8 KiB
TypeScript
import { describe, expect, it } from "vitest";
|
|
import { createActor, waitFor } from "xstate";
|
|
|
|
import {
|
|
createTestPrivateZoomMachine,
|
|
loadPrivateZoom,
|
|
makeAlbum,
|
|
makeAlbumsResponse,
|
|
TEST_PRIVATE_ZOOM_INPUT,
|
|
} from "./private-zoom-machine.test-utils";
|
|
|
|
describe("private zoom album flow", () => {
|
|
it("loads albums for the supplied character", async () => {
|
|
let loadedCharacterId: string | null = null;
|
|
const actor = createActor(
|
|
createTestPrivateZoomMachine({
|
|
onLoad: ({ characterId }) => {
|
|
loadedCharacterId = characterId;
|
|
},
|
|
}),
|
|
{ input: { characterId: "character_aria" } },
|
|
).start();
|
|
|
|
actor.send({ type: "PrivateZoomInit" });
|
|
await waitFor(actor, (snapshot) => snapshot.matches("ready"));
|
|
|
|
expect(actor.getSnapshot().context.characterId).toBe("character_aria");
|
|
expect(loadedCharacterId).toBe("character_aria");
|
|
actor.stop();
|
|
});
|
|
|
|
it("loads only the first non-paginated album page", async () => {
|
|
const actor = await loadPrivateZoom({
|
|
loadResponse: makeAlbumsResponse({
|
|
items: Array.from({ length: 20 }, (_, index) => makeAlbum(index)),
|
|
}),
|
|
});
|
|
expect(actor.getSnapshot().context.items).toHaveLength(20);
|
|
expect(actor.getSnapshot().context).not.toHaveProperty("hasMore");
|
|
expect(actor.getSnapshot().context).not.toHaveProperty("nextCursor");
|
|
actor.stop();
|
|
});
|
|
|
|
it("moves to failed when the album actor rejects", async () => {
|
|
const actor = createActor(
|
|
createTestPrivateZoomMachine({
|
|
loadError: new Error("albums unavailable"),
|
|
}),
|
|
{ input: TEST_PRIVATE_ZOOM_INPUT },
|
|
).start();
|
|
actor.send({ type: "PrivateZoomInit" });
|
|
await waitFor(actor, (snapshot) => snapshot.matches("failed"));
|
|
expect(actor.getSnapshot().context.errorMessage).toBe(
|
|
"albums unavailable",
|
|
);
|
|
actor.stop();
|
|
});
|
|
});
|