Fix first-login username flow

这个提交包含在:
cryptocommuniums-afk
2026-03-14 22:37:15 +08:00
父节点 8d3faecb15
当前提交 bcdd790d91
修改 3 个文件,包含 40 行新增12 行删除

查看文件

@@ -2,7 +2,10 @@ import { expect, test } from "@playwright/test";
import { installAppMocks } from "./helpers/mockApp";
test("login redirects into dashboard with mocked auth", async ({ page }) => {
await installAppMocks(page, { authenticated: false });
await installAppMocks(page, {
authenticated: false,
authMeNullResponsesAfterLogin: 1,
});
await page.goto("/login");
await expect(page.getByTestId("login-title")).toBeVisible();

查看文件

@@ -61,6 +61,7 @@ type MockAppState = {
analyses: any[];
mediaSession: MockMediaSession | null;
nextVideoId: number;
authMeNullResponsesAfterLogin: number;
};
function trpcResult(json: unknown) {
@@ -154,6 +155,10 @@ async function handleTrpc(route: Route, state: MockAppState) {
const results = operations.map((operation) => {
switch (operation) {
case "auth.me":
if (state.authenticated && state.authMeNullResponsesAfterLogin > 0) {
state.authMeNullResponsesAfterLogin -= 1;
return trpcResult(null);
}
return trpcResult(state.authenticated ? state.user : null);
case "auth.loginWithUsername":
state.authenticated = true;
@@ -282,6 +287,7 @@ export async function installAppMocks(
videos?: any[];
analyses?: any[];
userName?: string;
authMeNullResponsesAfterLogin?: number;
}
) {
const state: MockAppState = {
@@ -312,6 +318,7 @@ export async function installAppMocks(
],
mediaSession: null,
nextVideoId: 100,
authMeNullResponsesAfterLogin: options?.authMeNullResponsesAfterLogin ?? 0,
};
await page.addInitScript(() => {