fix(account settings): activate imported account

This commit is contained in:
Tommaso Casaburi
2026-05-08 16:51:59 +07:00
parent 0c0fd0b018
commit 4f1b4d9677
2 changed files with 44 additions and 2 deletions
@@ -350,6 +350,40 @@ describe('AccountSettings', () => {
expect(getLocationText()).toBe('/subs/settings#account-settings');
});
it('activates the resolved account name when an imported account name already exists', async () => {
hookMocks.useAccounts.mockReturnValue({
accounts: [
{ id: 'test-id', name: 'Account 1', author: { shortAddress: '0x1...3' } },
{ id: 'existing-imported-id', name: 'Imported', author: { shortAddress: '0x9...9' } },
],
});
fileReaderState.result = JSON.stringify({
account: {
id: 'imported-id',
name: 'Imported',
author: { address: '0xabc' },
},
});
hookMocks.importAccount.mockResolvedValue(undefined);
hookMocks.setActiveAccount.mockResolvedValue(undefined);
render();
await act(async () => {
getButtonByText('import_account_backup').click();
});
const file = new File(['{}'], 'account.json', { type: 'application/json' });
await act(async () => {
createdInput?.onchange?.({ target: { files: [file] } } as unknown as Event);
await Promise.resolve();
});
await flushMicrotasks();
expect(hookMocks.importAccount).toHaveBeenCalledOnce();
expect(hookMocks.setActiveAccount).toHaveBeenCalledWith('Imported 2');
});
it('surfaces import errors without navigating or reloading', async () => {
fileReaderState.result = JSON.stringify({
account: {