Skip to content

Commit 53cd7ea

Browse files
committed
fix(site/src/pages/AISettingsPage/SpendPage): name the denied-state organization picker by its prompt
Drop the aria-label that hid the visible "Select an organization" prompt from the trigger's accessible name, render the budget-period placeholder as status text instead of a disabled button, and cover organization selection in both flows with a view test asserting onOrganizationChange.
1 parent 32d5008 commit 53cd7ea

3 files changed

Lines changed: 72 additions & 5 deletions

File tree

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
import { screen } from "@testing-library/react";
2+
import userEvent from "@testing-library/user-event";
3+
import { expect, it, vi } from "vitest";
4+
import { mockInitialRenderResult } from "#/components/PaginationWidget/PaginationContainer.mocks";
5+
import { MockOrganization, MockOrganization2 } from "#/testHelpers/entities";
6+
import { render } from "#/testHelpers/renderHelpers";
7+
import type { SpendReportQuery } from "./components/SpendUsersTable";
8+
import { SpendPageView } from "./SpendPageView";
9+
10+
const pendingReportQuery = {
11+
...mockInitialRenderResult,
12+
data: undefined,
13+
isLoading: true,
14+
isFetching: true,
15+
error: null,
16+
refetch: vi.fn(),
17+
} satisfies SpendReportQuery;
18+
19+
const renderView = (organization: typeof MockOrganization | undefined) => {
20+
const onOrganizationChange = vi.fn();
21+
render(
22+
<SpendPageView
23+
isEntitled
24+
isEnabled
25+
now={new Date("2026-03-12T12:00:00Z")}
26+
organizations={[MockOrganization, MockOrganization2]}
27+
organization={organization}
28+
onOrganizationChange={onOrganizationChange}
29+
isOrganizationsLoading={false}
30+
organizationsError={null}
31+
dateRange={undefined}
32+
minDate={undefined}
33+
onDateRangeChange={vi.fn()}
34+
filterMenus={undefined}
35+
reportQuery={pendingReportQuery}
36+
/>,
37+
);
38+
return { onOrganizationChange };
39+
};
40+
41+
it("reports the organization picked from the switcher", async () => {
42+
const user = userEvent.setup();
43+
const { onOrganizationChange } = renderView(MockOrganization);
44+
45+
await user.click(
46+
screen.getByRole("button", {
47+
name: `Organization ${MockOrganization.display_name}`,
48+
}),
49+
);
50+
await user.click(
51+
await screen.findByRole("option", { name: /My Organization 2/ }),
52+
);
53+
54+
expect(onOrganizationChange).toHaveBeenCalledWith(MockOrganization2);
55+
});
56+
57+
it("reports the organization picked to recover from a denied one", async () => {
58+
const user = userEvent.setup();
59+
const { onOrganizationChange } = renderView(undefined);
60+
61+
await user.click(
62+
screen.getByRole("button", { name: /Select an organization/ }),
63+
);
64+
await user.click(
65+
await screen.findByRole("option", { name: /My Organization 2/ }),
66+
);
67+
68+
expect(onOrganizationChange).toHaveBeenCalledWith(MockOrganization2);
69+
});

‎site/src/pages/AISettingsPage/SpendPage/SpendPageView.tsx‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,6 @@ const SpendPageContent: FC<SpendPageContentProps> = ({
107107
{refetchErrorAlert}
108108
<OrganizationAutocomplete
109109
value={null}
110-
ariaLabel="Organization"
111110
options={organizations}
112111
required
113112
triggerClassName="w-60"

‎site/src/pages/AISettingsPage/SpendPage/components/SpendFilters.tsx‎

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import { CalendarIcon } from "lucide-react";
22
import type { FC } from "react";
33
import { MaxAISpendPeriodDays, type Organization } from "#/api/typesGenerated";
4-
import { Button } from "#/components/Button/Button";
54
import {
65
DateRangePicker,
76
type DateRangeValue,
@@ -91,10 +90,10 @@ export const SpendFilters: FC<SpendFiltersProps> = ({
9190
size="lg"
9291
/>
9392
) : (
94-
<Button variant="outline" size="lg" disabled>
95-
<CalendarIcon className="size-4 text-content-secondary" />
93+
<div className="flex h-10 items-center gap-2 rounded-md border border-solid border-border px-3 py-2 text-sm text-content-secondary">
94+
<CalendarIcon className="size-4" />
9695
Current budget period
97-
</Button>
96+
</div>
9897
)}
9998
</div>
10099
);

0 commit comments

Comments
 (0)