mirror of
https://github.com/bitsocialnet/5chan.git
synced 2026-08-03 07:41:04 +02:00
Review settings upgrades before applying defaults
Adds a review modal for settings upgrades, keeps the settings banner reviewable, and preserves explicit router settings during account import.
This commit is contained in:
@@ -8,6 +8,7 @@ import AccountSettings from '../account-settings';
|
||||
(globalThis as { IS_REACT_ACT_ENVIRONMENT?: boolean }).IS_REACT_ACT_ENVIRONMENT = true;
|
||||
const act = (React as { act?: (cb: () => void | Promise<void>) => void | Promise<void> }).act as (cb: () => void | Promise<void>) => void | Promise<void>;
|
||||
const IMPORTED_ACCOUNT_ADDRESSES_STORAGE_KEY = 'importedAccountAddresses';
|
||||
const LEGACY_DEFAULT_HTTP_ROUTERS = ['https://routing.lol', 'https://peers.pleb.bot', 'https://peers.plebpubsub.xyz', 'https://peers.forumindex.com'];
|
||||
|
||||
const hookMocks = vi.hoisted(() => ({
|
||||
deleteAccount: vi.fn(),
|
||||
@@ -343,6 +344,7 @@ describe('AccountSettings', () => {
|
||||
expect(hookMocks.importAccount).toHaveBeenCalledOnce();
|
||||
const importedPayload = JSON.parse(hookMocks.importAccount.mock.calls[0][0]);
|
||||
expect(importedPayload.account.subscriptions).toEqual(['business.eth', 'music-posting.bso']);
|
||||
expect(importedPayload.account.pkcOptions.httpRoutersOptions).toEqual(LEGACY_DEFAULT_HTTP_ROUTERS);
|
||||
expect(localStorage.getItem(IMPORTED_ACCOUNT_ADDRESSES_STORAGE_KEY)).toBe(JSON.stringify(['0x999']));
|
||||
expect(localStorage.getItem('importedAccountAddress')).toBe('0x999');
|
||||
expect(hookMocks.setActiveAccount).toHaveBeenCalledWith('Imported');
|
||||
@@ -350,6 +352,74 @@ describe('AccountSettings', () => {
|
||||
expect(getLocationText()).toBe('/subs/settings#account-settings');
|
||||
});
|
||||
|
||||
it('preserves explicit HTTP routers when importing an account backup', async () => {
|
||||
fileReaderState.result = JSON.stringify({
|
||||
account: {
|
||||
name: 'Imported',
|
||||
author: { address: '0x999' },
|
||||
pkcOptions: {
|
||||
httpRoutersOptions: ['https://router.custom.example'],
|
||||
ipfsGatewayUrls: ['https://gateway.custom.example'],
|
||||
},
|
||||
},
|
||||
});
|
||||
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();
|
||||
|
||||
const importedPayload = JSON.parse(hookMocks.importAccount.mock.calls[0][0]);
|
||||
expect(importedPayload.account.pkcOptions).toEqual({
|
||||
httpRoutersOptions: ['https://router.custom.example'],
|
||||
ipfsGatewayUrls: ['https://gateway.custom.example'],
|
||||
});
|
||||
});
|
||||
|
||||
it('preserves an explicit empty HTTP routers list when importing an account backup', async () => {
|
||||
fileReaderState.result = JSON.stringify({
|
||||
account: {
|
||||
name: 'Imported',
|
||||
author: { address: '0x999' },
|
||||
pkcOptions: {
|
||||
httpRoutersOptions: [],
|
||||
ipfsGatewayUrls: ['https://gateway.custom.example'],
|
||||
},
|
||||
},
|
||||
});
|
||||
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();
|
||||
|
||||
const importedPayload = JSON.parse(hookMocks.importAccount.mock.calls[0][0]);
|
||||
expect(importedPayload.account.pkcOptions).toEqual({
|
||||
httpRoutersOptions: [],
|
||||
ipfsGatewayUrls: ['https://gateway.custom.example'],
|
||||
});
|
||||
});
|
||||
|
||||
it('activates the resolved account name when an imported account name already exists', async () => {
|
||||
hookMocks.useAccounts.mockReturnValue({
|
||||
accounts: [
|
||||
|
||||
Reference in New Issue
Block a user