diff --git a/packages/ui/components/ui/account-switcher/account-switcher.test.tsx b/packages/ui/components/ui/account-switcher/account-switcher.test.tsx index b57c7323..5cd95eb4 100644 --- a/packages/ui/components/ui/account-switcher/account-switcher.test.tsx +++ b/packages/ui/components/ui/account-switcher/account-switcher.test.tsx @@ -6,7 +6,7 @@ describe('', () => { it('renders the current account', () => { const { getByLabelText } = render(); - expect(getByLabelText('Account #123')).toHaveValue(123); + expect(getByLabelText('Sub-Account #123')).toHaveValue(123); }); describe('changing the account via the input field', () => { @@ -15,14 +15,14 @@ describe('', () => { const { getByLabelText } = render(); expect(onChange).not.toHaveBeenCalled(); - fireEvent.change(getByLabelText('Account #123'), { target: { value: 456 } }); + fireEvent.change(getByLabelText('Sub-Account #123'), { target: { value: 456 } }); expect(onChange).toHaveBeenCalledWith(456); }); it('has aria-disabled=false', () => { const { getByLabelText } = render(); - expect(getByLabelText('Account #123')).toHaveAttribute('aria-disabled', 'false'); + expect(getByLabelText('Sub-Account #123')).toHaveAttribute('aria-disabled', 'false'); }); describe('when a filter has been passed', () => { @@ -32,7 +32,7 @@ describe('', () => { , ); - fireEvent.change(getByLabelText('Account #123'), { target: { value: 456 } }); + fireEvent.change(getByLabelText('Sub-Account #123'), { target: { value: 456 } }); expect(onChange).not.toHaveBeenCalled(); }); @@ -41,7 +41,7 @@ describe('', () => { , ); - expect(getByLabelText('Account #123')).toHaveAttribute('aria-disabled', 'true'); + expect(getByLabelText('Sub-Account #123')).toHaveAttribute('aria-disabled', 'true'); }); }); }); @@ -52,14 +52,14 @@ describe('', () => { const { getByLabelText } = render(); expect(onChange).not.toHaveBeenCalled(); - fireEvent.click(getByLabelText('Previous account')); + fireEvent.click(getByLabelText('Previous sub-account')); expect(onChange).toHaveBeenCalledWith(122); }); it("is disabled when we're at account 0", () => { const { queryByLabelText } = render(); - expect(queryByLabelText('Previous account')?.parentElement).toBeDisabled(); + expect(queryByLabelText('Previous sub-account')?.parentElement).toBeDisabled(); }); describe('when a filter has been passed', () => { @@ -70,7 +70,7 @@ describe('', () => { ); expect(onChange).not.toHaveBeenCalled(); - fireEvent.click(getByLabelText('Previous account')); + fireEvent.click(getByLabelText('Previous sub-account')); expect(onChange).toHaveBeenCalledWith(100); }); @@ -79,7 +79,7 @@ describe('', () => { , ); - expect(queryByLabelText('Previous account')?.parentElement).toBeDisabled(); + expect(queryByLabelText('Previous sub-account')?.parentElement).toBeDisabled(); }); }); }); @@ -90,14 +90,14 @@ describe('', () => { const { getByLabelText } = render(); expect(onChange).not.toHaveBeenCalled(); - fireEvent.click(getByLabelText('Next account')); + fireEvent.click(getByLabelText('Next sub-account')); expect(onChange).toHaveBeenCalledWith(124); }); it("is disabled when we're at the maximum account index", () => { const { queryByLabelText } = render(); - expect(queryByLabelText('Next account')?.parentElement).toBeDisabled(); + expect(queryByLabelText('Next sub-account')?.parentElement).toBeDisabled(); }); describe('when a filter has been passed', () => { @@ -108,7 +108,7 @@ describe('', () => { ); expect(onChange).not.toHaveBeenCalled(); - fireEvent.click(getByLabelText('Next account')); + fireEvent.click(getByLabelText('Next sub-account')); expect(onChange).toHaveBeenCalledWith(123); }); @@ -117,7 +117,7 @@ describe('', () => { , ); - expect(queryByLabelText('Next account')?.parentElement).toBeDisabled(); + expect(queryByLabelText('Next sub-account')?.parentElement).toBeDisabled(); }); }); }); diff --git a/packages/ui/components/ui/account-switcher/index.tsx b/packages/ui/components/ui/account-switcher/index.tsx index f7b5f9db..75b23069 100644 --- a/packages/ui/components/ui/account-switcher/index.tsx +++ b/packages/ui/components/ui/account-switcher/index.tsx @@ -68,7 +68,7 @@ export const AccountSwitcher = ({ disabled={!previousButtonEnabled} >
- Account -
-

#

-
- { - /** - * Don't allow manual account number entry when there's a - * filter. - * - * @todo: Change this to only call `handleChange()` when the - * user presses Enter? Then it could validate that the entered - * account index is in the filter. - */ - if (filter) { - return; - } + {account === 0 ? ( + Main Account + ) : ( + <> + Sub-Account - const value = Number(e.target.value); - const valueLength = e.target.value.replace(/^0+/, '').length; +
+

#

+
+ { + /** + * Don't allow manual account number entry when there's a + * filter. + * + * @todo: Change this to only call `handleChange()` when the + * user presses Enter? Then it could validate that the entered + * account index is in the filter. + */ + if (filter) { + return; + } - if (value > MAX_INDEX || valueLength > MAX_INDEX.toString().length) { - return; - } - handleChange(value); - }} - style={{ width: `${inputCharWidth}ch` }} - value={account ? account.toString().replace(/^0+/, '') : '0'} // Removes leading zeros (e.g. 00123 -> 123 - /> -
-
+ const value = Number(e.target.value); + const valueLength = e.target.value.replace(/^0+/, '').length; + + if (value > MAX_INDEX || valueLength > MAX_INDEX.toString().length) { + return; + } + handleChange(value); + }} + style={{ width: `${inputCharWidth}ch` }} + value={account ? account.toString().replace(/^0+/, '') : '0'} // Removes leading zeros (e.g. 00123 -> 123 + /> +
+
+ + )}