diff --git a/web/app/components/header/account-setting/model-provider-page/provider-added-card/model-auth-dropdown/__tests__/usage-priority-section.spec.tsx b/web/app/components/header/account-setting/model-provider-page/provider-added-card/model-auth-dropdown/__tests__/usage-priority-section.spec.tsx index c400d05f22..2df673726a 100644 --- a/web/app/components/header/account-setting/model-provider-page/provider-added-card/model-auth-dropdown/__tests__/usage-priority-section.spec.tsx +++ b/web/app/components/header/account-setting/model-provider-page/provider-added-card/model-auth-dropdown/__tests__/usage-priority-section.spec.tsx @@ -4,6 +4,8 @@ import UsagePrioritySection from '../usage-priority-section' describe('UsagePrioritySection', () => { const onSelect = vi.fn() + const getAiCreditsButton = () => screen.getByRole('button', { name: /aiCreditsOption/ }) + const getApiKeyButton = () => screen.getByRole('button', { name: /apiKeyOption/ }) beforeEach(() => { vi.clearAllMocks() @@ -15,7 +17,8 @@ describe('UsagePrioritySection', () => { render() expect(screen.getByText(/usagePriority/))!.toBeInTheDocument() - expect(screen.getAllByRole('button')).toHaveLength(2) + expect(getAiCreditsButton()).toBeInTheDocument() + expect(getApiKeyButton()).toBeInTheDocument() }) }) @@ -24,24 +27,21 @@ describe('UsagePrioritySection', () => { it('should highlight AI credits option when value is credits', () => { render() - const buttons = screen.getAllByRole('button') - expect(buttons[0]!.className).toContain('border-components-option-card-option-selected-border') - expect(buttons[1]!.className).not.toContain('border-components-option-card-option-selected-border') + expect(getAiCreditsButton()).toHaveAttribute('aria-pressed', 'true') + expect(getApiKeyButton()).toHaveAttribute('aria-pressed', 'false') }) it('should highlight API key option when value is apiKey', () => { render() - const buttons = screen.getAllByRole('button') - expect(buttons[0]!.className).not.toContain('border-components-option-card-option-selected-border') - expect(buttons[1]!.className).toContain('border-components-option-card-option-selected-border') + expect(getAiCreditsButton()).toHaveAttribute('aria-pressed', 'false') + expect(getApiKeyButton()).toHaveAttribute('aria-pressed', 'true') }) it('should highlight API key option when value is apiKeyOnly', () => { render() - const buttons = screen.getAllByRole('button') - expect(buttons[1]!.className).toContain('border-components-option-card-option-selected-border') + expect(getApiKeyButton()).toHaveAttribute('aria-pressed', 'true') }) }) @@ -50,7 +50,7 @@ describe('UsagePrioritySection', () => { it('should call onSelect with system when clicking AI credits option', () => { render() - fireEvent.click(screen.getAllByRole('button')[0]!) + fireEvent.click(getAiCreditsButton()) expect(onSelect).toHaveBeenCalledWith(PreferredProviderTypeEnum.system) }) @@ -58,7 +58,7 @@ describe('UsagePrioritySection', () => { it('should call onSelect with custom when clicking API key option', () => { render() - fireEvent.click(screen.getAllByRole('button')[1]!) + fireEvent.click(getApiKeyButton()) expect(onSelect).toHaveBeenCalledWith(PreferredProviderTypeEnum.custom) }) diff --git a/web/app/components/header/account-setting/model-provider-page/provider-added-card/model-auth-dropdown/usage-priority-section.tsx b/web/app/components/header/account-setting/model-provider-page/provider-added-card/model-auth-dropdown/usage-priority-section.tsx index 19b2ba20a3..b491f07889 100644 --- a/web/app/components/header/account-setting/model-provider-page/provider-added-card/model-auth-dropdown/usage-priority-section.tsx +++ b/web/app/components/header/account-setting/model-provider-page/provider-added-card/model-auth-dropdown/usage-priority-section.tsx @@ -26,7 +26,7 @@ export default function UsagePrioritySection({ value, disabled, onSelect }: Usag
- +
@@ -37,22 +37,27 @@ export default function UsagePrioritySection({ value, disabled, onSelect }: Usag
- {options.map(option => ( - - ))} + {options.map((option) => { + const selected = selectedKey === option.key + + return ( + + ) + })}