fix(ui): use shared scan launch action errors (#11664)

This commit is contained in:
Alejandro Bailo
2026-06-23 09:52:20 +02:00
committed by GitHub
parent 0610866b73
commit c6c07957a6
12 changed files with 278 additions and 21 deletions
@@ -3,6 +3,11 @@ import userEvent from "@testing-library/user-event";
import type { ComponentProps } from "react";
import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
import {
ACTION_ERROR_API_MESSAGES,
ACTION_ERROR_MESSAGES,
ACTION_ERROR_STATUS,
} from "@/lib/action-errors";
import { useProviderWizardStore } from "@/store/provider-wizard/store";
import { SCAN_JOBS_TAB } from "@/types";
import {
@@ -376,6 +381,47 @@ describe("LaunchStep", () => {
expect(onClose).toHaveBeenCalledTimes(1);
});
it("uses the shared subscription error copy when a manual scan is blocked", async () => {
// Given
const onClose = vi.fn();
const onFooterChange = vi.fn();
const rawError =
ACTION_ERROR_API_MESSAGES[ACTION_ERROR_STATUS.PAYMENT_REQUIRED];
seedConnectedProvider();
scanOnDemandMock.mockResolvedValue({
error: rawError,
status: ACTION_ERROR_STATUS.PAYMENT_REQUIRED,
});
render(
<LaunchStep
onBack={vi.fn()}
onClose={onClose}
onFooterChange={onFooterChange}
capability={SCAN_SCHEDULE_CAPABILITY.MANUAL_ONLY}
/>,
);
await waitFor(() => expect(onFooterChange).toHaveBeenCalled());
// When
await act(async () => {
lastFooterConfig(onFooterChange)?.onAction?.();
});
// Then
await waitFor(() => expect(scanOnDemandMock).toHaveBeenCalledTimes(1));
expect(toastMock).toHaveBeenCalledWith(
expect.objectContaining({
variant: "destructive",
title: "Unable to launch scan",
description:
ACTION_ERROR_MESSAGES[ACTION_ERROR_STATUS.PAYMENT_REQUIRED],
}),
);
expect(toastMock.mock.calls[0]?.[0].description).not.toContain(rawError);
expect(onClose).not.toHaveBeenCalled();
});
it("disables the action and shows the limit copy when over limit", async () => {
// Given
const onFooterChange = vi.fn();