refactor: simplify errors and focus tests
This commit is contained in:
+31
-15
@@ -292,31 +292,47 @@ describe("TbankConnectionSection", () => {
|
||||
expect(client.getQueryData(operationsQueryKey)).toBeUndefined();
|
||||
});
|
||||
|
||||
it("preserves status and financial cache when a connection update fails", async () => {
|
||||
server.use(
|
||||
http.put("*/api/v1/tbank-connection", () =>
|
||||
HttpResponse.json({ code: "TBANK_UNAVAILABLE" }, { status: 503 }),
|
||||
),
|
||||
);
|
||||
it.each([
|
||||
["INVALID_TBANK_TOKEN", "Проверьте token и его права."],
|
||||
["TBANK_UNAVAILABLE", "T-Bank временно недоступен. Повторите попытку позже."],
|
||||
[undefined, "Не удалось выполнить запрос. Попробуйте ещё раз."],
|
||||
])("preserves the draft and cache after %s, then retries successfully", async (code, message) => {
|
||||
const { promise: response, resolve: finishUpdate }
|
||||
= Promise.withResolvers<Response>();
|
||||
|
||||
const update = vi.fn()
|
||||
.mockImplementationOnce(() =>
|
||||
HttpResponse.json({ code }, { status: 503 }),
|
||||
)
|
||||
.mockImplementationOnce(() => response);
|
||||
|
||||
server.use(http.put("*/api/v1/tbank-connection", update));
|
||||
const client = seededClient();
|
||||
renderSection(client);
|
||||
|
||||
await screen.findByText("Не подключено");
|
||||
fireEvent.change(screen.getByLabelText("Token T-Bank"), {
|
||||
target: { value: "replacement-token" },
|
||||
});
|
||||
const token = screen.getByLabelText("Token T-Bank");
|
||||
fireEvent.change(token, { target: { value: "replacement-token" } });
|
||||
fireEvent.click(screen.getByRole("button", { name: "Подключить" }));
|
||||
|
||||
await screen.findByText(
|
||||
"T-Bank временно недоступен. Повторите попытку позже.",
|
||||
);
|
||||
expect(
|
||||
screen.getByRole("button", { name: "Подключить" }),
|
||||
).toBeInTheDocument();
|
||||
await screen.findByText(message);
|
||||
expect(token).toHaveValue("replacement-token");
|
||||
expect(screen.getByText("Не подключено")).toBeVisible();
|
||||
expect(client.getQueryData(brokerageAccountsQueryKey)).toBeDefined();
|
||||
expect(client.getQueryData(portfolioQueryKey)).toEqual({
|
||||
source: "previous-connection",
|
||||
});
|
||||
fireEvent.click(screen.getByRole("button", { name: "Подключить" }));
|
||||
await waitFor(() => expect(update).toHaveBeenCalledTimes(2));
|
||||
expect(screen.queryByText(message)).not.toBeInTheDocument();
|
||||
expect(token).toBeDisabled();
|
||||
expect(token).toHaveValue("replacement-token");
|
||||
finishUpdate(HttpResponse.json({
|
||||
connected: true, connectedAt: "2026-08-14T00:00:00Z",
|
||||
}));
|
||||
expect(await screen.findByText("Подключено с 14.08.2026")).toBeVisible();
|
||||
expect(token).toHaveValue("");
|
||||
expect(screen.queryByText(message)).not.toBeInTheDocument();
|
||||
});
|
||||
|
||||
it("keeps DELETE recovery inside the dialog and preserves cache until successful retry", async () => {
|
||||
|
||||
Reference in New Issue
Block a user