refactor: enforce frontend view model boundaries
This commit is contained in:
@@ -33,6 +33,7 @@ function configureTestAuth() {
|
||||
|
||||
function renderPage(queryClient: QueryClient) {
|
||||
configureTestAuth();
|
||||
|
||||
return render(
|
||||
<QueryClientProvider client={queryClient}>
|
||||
<MantineProvider>
|
||||
@@ -50,6 +51,7 @@ describe("AccountsPage", () => {
|
||||
server.use(
|
||||
http.get("*/api/v1/brokerage-accounts", ({ request }) => {
|
||||
modes.push(new URL(request.url).searchParams.get("sync"));
|
||||
|
||||
return modes.length === 1
|
||||
? HttpResponse.json({ code: "TBANK_UNAVAILABLE" }, { status: 503 })
|
||||
: HttpResponse.json(resource([account]));
|
||||
@@ -102,9 +104,11 @@ describe("AccountsPage", () => {
|
||||
http.get("*/api/v1/brokerage-accounts", () => {
|
||||
requestCount += 1;
|
||||
if (requestCount === 1) return HttpResponse.json(resource([account]));
|
||||
|
||||
{
|
||||
const deferred = Promise.withResolvers<Response>();
|
||||
resolveRefresh = deferred.resolve;
|
||||
|
||||
return deferred.promise;
|
||||
}
|
||||
}),
|
||||
@@ -131,6 +135,7 @@ describe("AccountsPage", () => {
|
||||
server.use(
|
||||
http.post("*/api/v1/tbank-sync", async ({ request }) => {
|
||||
requests.push(await request.json());
|
||||
|
||||
return HttpResponse.json(
|
||||
{ code: "TBANK_UNAVAILABLE" },
|
||||
{ status: 503 },
|
||||
@@ -142,11 +147,9 @@ describe("AccountsPage", () => {
|
||||
http.get("*/api/v1/brokerage-accounts", () => {
|
||||
requestCount += 1;
|
||||
if (requestCount === 1) return HttpResponse.json(resource([account]));
|
||||
|
||||
return requestCount === 2
|
||||
? HttpResponse.json(
|
||||
{ code: "TBANK_UNAVAILABLE" },
|
||||
{ status: 503 },
|
||||
)
|
||||
? HttpResponse.json({ code: "TBANK_UNAVAILABLE" }, { status: 503 })
|
||||
: HttpResponse.json(resource([account]));
|
||||
}),
|
||||
);
|
||||
@@ -161,6 +164,7 @@ describe("AccountsPage", () => {
|
||||
const warning = await screen.findByText(
|
||||
"Не удалось обновить данные. Показаны последние полученные.",
|
||||
);
|
||||
|
||||
expect(warning).toBeInTheDocument();
|
||||
expect(screen.getByText(account.name)).toBeInTheDocument();
|
||||
|
||||
@@ -176,12 +180,10 @@ describe("AccountsPage", () => {
|
||||
server.use(
|
||||
http.get("*/api/v1/brokerage-accounts", () => {
|
||||
requestCount += 1;
|
||||
|
||||
return requestCount === 1
|
||||
? HttpResponse.json(resource([]))
|
||||
: HttpResponse.json(
|
||||
{ code: "TBANK_UNAVAILABLE" },
|
||||
{ status: 503 },
|
||||
);
|
||||
: HttpResponse.json({ code: "TBANK_UNAVAILABLE" }, { status: 503 });
|
||||
}),
|
||||
);
|
||||
const queryClient = createTestQueryClient();
|
||||
@@ -210,11 +212,13 @@ it("keeps unknown membership loading instead of declaring no accounts", async ()
|
||||
const client = createTestQueryClient();
|
||||
renderPage(client);
|
||||
await waitFor(() =>
|
||||
expect(client.getQueryData(brokerageAccountsQueryKey)).toMatchObject((/* eslint-disable unicorn/no-null -- Fixture preserves the production contract’s explicit null values. */
|
||||
/* eslint-disable unicorn/no-null -- Fixture preserves the production contract’s explicit null values. */
|
||||
expect(client.getQueryData(brokerageAccountsQueryKey)).toMatchObject(
|
||||
{
|
||||
data: null,
|
||||
}
|
||||
/* eslint-enable unicorn/no-null */)),
|
||||
},
|
||||
/* eslint-enable unicorn/no-null */
|
||||
),
|
||||
);
|
||||
expect(
|
||||
screen.queryByText("Нет инвестиционных счетов"),
|
||||
|
||||
Reference in New Issue
Block a user