refactor(stores): standardize state machine structure

This commit is contained in:
2026-07-15 11:19:08 +08:00
parent ed3e800245
commit 20d07023e4
68 changed files with 3492 additions and 3193 deletions
@@ -0,0 +1,36 @@
import { describe, expect, it } from "vitest";
import { createActor, waitFor } from "xstate";
import { createTestAuthMachine } from "./auth-machine.test-utils";
describe("auth credentials flow", () => {
it("email login updates login status", async () => {
const actor = createActor(createTestAuthMachine()).start();
actor.send({
type: "AuthEmailLoginSubmitted",
email: "user@example.com",
password: "12345678",
});
await waitFor(actor, (snapshot) => snapshot.matches("idle"));
expect(actor.getSnapshot().context).toMatchObject({
loginStatus: "email",
hasInitialized: true,
});
actor.stop();
});
it("registration completes through the email session", async () => {
const actor = createActor(createTestAuthMachine()).start();
actor.send({
type: "AuthEmailRegisterSubmitted",
email: "user@example.com",
password: "12345678",
username: "User",
confirmPassword: "12345678",
});
await waitFor(actor, (snapshot) => snapshot.matches("idle"));
expect(actor.getSnapshot().context.loginStatus).toBe("email");
actor.stop();
});
});