Compare commits
2
Commits
c6f2f2eedc
...
19fe99695c
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
19fe99695c | ||
|
|
a56edf2b37 |
@@ -3,8 +3,9 @@ import type { FC, PropsWithChildren } from "react";
|
|||||||
import { QueryClientProvider, useQueryClient } from "@tanstack/react-query";
|
import { QueryClientProvider, useQueryClient } from "@tanstack/react-query";
|
||||||
import { act, renderHook, waitFor } from "@testing-library/react";
|
import { act, renderHook, waitFor } from "@testing-library/react";
|
||||||
import { http, HttpResponse } from "msw";
|
import { http, HttpResponse } from "msw";
|
||||||
import { describe, expect, it } from "vitest";
|
import { describe, expect, it, onTestFinished, vi } from "vitest";
|
||||||
|
|
||||||
|
import * as sharedApi from "@/shared/api";
|
||||||
import { apiClient, apiQueryClient, useAuthenticatedQuery } from "@/shared/api";
|
import { apiClient, apiQueryClient, useAuthenticatedQuery } from "@/shared/api";
|
||||||
import { createTestQueryClient } from "@/test/query";
|
import { createTestQueryClient } from "@/test/query";
|
||||||
import { resource } from "@/test/resource";
|
import { resource } from "@/test/resource";
|
||||||
@@ -398,4 +399,23 @@ describe("AuthProvider", () => {
|
|||||||
expect(result.current.cards.data?.[0]?.id).toBe("b-card"),
|
expect(result.current.cards.data?.[0]?.id).toBe("b-card"),
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it("registers auth handlers once until unmount", async () => {
|
||||||
|
const configure = vi.spyOn(sharedApi, "configureAuthClient");
|
||||||
|
onTestFinished(() => configure.mockRestore());
|
||||||
|
|
||||||
|
const { rerender, result, unmount } = renderHook(useAuth, {
|
||||||
|
wrapper: createAuthWrapper(createTestQueryClient()),
|
||||||
|
});
|
||||||
|
|
||||||
|
await waitFor(() => expect(result.current.ready).toBe(true));
|
||||||
|
const registrations = configure.mock.calls.length;
|
||||||
|
|
||||||
|
rerender();
|
||||||
|
expect(configure).toHaveBeenCalledTimes(registrations);
|
||||||
|
|
||||||
|
unmount();
|
||||||
|
expect(configure).toHaveBeenCalledTimes(registrations + 1);
|
||||||
|
expect(configure).toHaveBeenLastCalledWith();
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -161,7 +161,8 @@ function useAuthProviderVm() {
|
|||||||
refresh,
|
refresh,
|
||||||
unavailable: () => unavailableRef.current,
|
unavailable: () => unavailableRef.current,
|
||||||
});
|
});
|
||||||
});
|
// `user` tracks access-token changes, which configureAuthClient publishes as session state.
|
||||||
|
}, [clearSession, refresh, user]);
|
||||||
useEffect(() => () => configureAuthClient(), []);
|
useEffect(() => () => configureAuthClient(), []);
|
||||||
|
|
||||||
const authContextValue = {
|
const authContextValue = {
|
||||||
|
|||||||
@@ -151,6 +151,20 @@ function loadedProps(nextPortfolio: Portfolio = portfolio) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
describe("AccountPage states", () => {
|
describe("AccountPage states", () => {
|
||||||
|
it("shows the loaded portfolio source sync status", async () => {
|
||||||
|
server.use(
|
||||||
|
http.get("*/api/v1/brokerage-accounts/:accountId/portfolio", () =>
|
||||||
|
HttpResponse.json(resource(portfolio, { freshness: "stale" })),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
renderAccountRoute(createTestQueryClient());
|
||||||
|
|
||||||
|
expect(
|
||||||
|
await screen.findByText("Данные требуют обновления"),
|
||||||
|
).toBeInTheDocument();
|
||||||
|
expect(screen.getByText(/Данные на 14\.08\.2026/)).toBeInTheDocument();
|
||||||
|
});
|
||||||
|
|
||||||
it.each(
|
it.each(
|
||||||
["account-1", "all"].flatMap(accountId =>
|
["account-1", "all"].flatMap(accountId =>
|
||||||
["STOCK", "BOND"].flatMap(type =>
|
["STOCK", "BOND"].flatMap(type =>
|
||||||
|
|||||||
@@ -31,6 +31,7 @@ const AccountPage: FC = () => {
|
|||||||
positionSections={viewModel.positionSections}
|
positionSections={viewModel.positionSections}
|
||||||
recentEvents={viewModel.recentEvents}
|
recentEvents={viewModel.recentEvents}
|
||||||
recentOperations={viewModel.recentOperations}
|
recentOperations={viewModel.recentOperations}
|
||||||
|
source={viewModel.source}
|
||||||
unrealizedReturns={viewModel.unrealizedReturns}
|
unrealizedReturns={viewModel.unrealizedReturns}
|
||||||
/>
|
/>
|
||||||
);
|
);
|
||||||
|
|||||||
Reference in New Issue
Block a user