@@ -96,65 +96,94 @@ it.each([true, false])(
9696 },
9797);
9898
99- it("keeps an unacknowledged transfer visible until a deliberate new attempt", async () => {
100- vi.useFakeTimers();
101- vi.stubGlobal("matchMedia", () => ({
102- matches: false,
103- addEventListener() {},
104- removeEventListener() {},
105- }));
106- const viewer = "a".repeat(64);
107- const snapshot: ClientSnapshot = {
108- status: "ready",
109- relayAvailable: true,
110- viewer,
111- selected: "https://community.example",
112- profile: { name: "", picture: "" },
113- memberships: [],
114- };
115- let status: PairingStatus = { phase: "idle" };
116- const native = {
117- account: vi.fn(async () => viewer),
118- start: vi.fn<PairingNative["start"]>(async () => {
119- status = { phase: "qr", svg: "<svg/>" };
120- }),
121- status: vi.fn(async () => status),
122- cancel: vi.fn(async () => {}),
123- confirm: vi.fn(async () => {}),
124- } satisfies PairingNative;
125- await act(async () => {
126- render(
99+ it.each(["uncertain", "cancelled"] as const)(
100+ "keeps %s terminal until a deliberate new attempt",
101+ async (phase) => {
102+ vi.useFakeTimers();
103+ vi.stubGlobal("matchMedia", () => ({
104+ matches: false,
105+ addEventListener() {},
106+ removeEventListener() {},
107+ }));
108+ const viewer = "a".repeat(64);
109+ let snapshot: ClientSnapshot = {
110+ status: "ready",
111+ relayAvailable: true,
112+ viewer,
113+ selected: "https://community.example",
114+ profile: { name: "", picture: "" },
115+ memberships: [],
116+ };
117+ let status: PairingStatus = { phase: "idle" };
118+ const native = {
119+ account: vi.fn(async () => viewer),
120+ start: vi.fn<PairingNative["start"]>(async () => {
121+ status = { phase: "qr", svg: "<svg/>" };
122+ }),
123+ status: vi.fn(async () => status),
124+ cancel: vi.fn(async () => {}),
125+ confirm: vi.fn(async () => {}),
126+ } satisfies PairingNative;
127+ let mounted!: ReturnType<typeof render>;
128+ const view = () => (
127129 <PairingSettings
128130 communities={{ snapshot: () => snapshot, subscribe: () => () => {} }}
129131 active={() => true}
130132 available
131133 native={native}
132- />,
133- );
134- });
135- expect(native.start).toHaveBeenCalledTimes(1);
136- status = { phase: "transferring" };
137- await act(async () => {
138- await vi.advanceTimersByTimeAsync(400);
139- });
140- status = { phase: "uncertain" };
141- await act(async () => {
142- await vi.advanceTimersByTimeAsync(400);
143- });
144- expect(
145- screen.getByRole("heading", { name: "Check your phone" }),
146- ).toBeTruthy();
147- expect(
148- screen.queryByAltText("Scan this QR code with Buzz on your phone"),
149- ).toBeNull();
150- await act(async () => {
151- await vi.advanceTimersByTimeAsync(240000);
152- });
153- expect(native.start).toHaveBeenCalledTimes(1);
154- await act(async () => {
155- fireEvent.click(
156- screen.getByRole("button", { name: "Start a new pairing" }),
134+ />
157135 );
158- });
159- expect(native.start).toHaveBeenCalledTimes(2);
160- });
136+ await act(async () => {
137+ mounted = render(
138+ <PairingSettings
139+ communities={{ snapshot: () => snapshot, subscribe: () => () => {} }}
140+ active={() => true}
141+ available
142+ native={native}
143+ />,
144+ );
145+ });
146+ expect(native.start).toHaveBeenCalledTimes(1);
147+ status = { phase: "transferring" };
148+ await act(async () => {
149+ await vi.advanceTimersByTimeAsync(400);
150+ });
151+ status = { phase };
152+ await act(async () => {
153+ await vi.advanceTimersByTimeAsync(400);
154+ });
155+ if (phase === "uncertain")
156+ expect(
157+ screen.getByRole("heading", { name: "Check your phone" }),
158+ ).toBeTruthy();
159+ expect(
160+ screen.queryByAltText("Scan this QR code with Buzz on your phone"),
161+ ).toBeNull();
162+ await act(async () => {
163+ await vi.advanceTimersByTimeAsync(240000);
164+ });
165+ expect(native.start).toHaveBeenCalledTimes(1);
166+ await act(async () => {
167+ fireEvent.click(
168+ screen.getByRole("button", {
169+ name: phase === "uncertain" ? "Start a new pairing" : "Try again",
170+ }),
171+ );
172+ });
173+ expect(native.start).toHaveBeenCalledTimes(2);
174+ snapshot = {
175+ ...snapshot,
176+ viewer: "b".repeat(64),
177+ selected: "https://other.example",
178+ };
179+ await act(async () => {
180+ mounted.rerender(view());
181+ });
182+ expect(native.start).toHaveBeenCalledTimes(3);
183+ expect(native.start.mock.calls[2]).toEqual([
184+ expect.any(String),
185+ "b".repeat(64),
186+ "https://other.example",
187+ ]);
188+ },
189+ );
0 commit comments