Changeset View
Changeset View
Standalone View
Standalone View
cashtab/src/components/__tests__/App.test.js
Show First 20 Lines • Show All 256 Lines • ▼ Show 20 Lines | it('Adding a contact to to a new contactList by clicking on tx history adds it to localforage and wallet context', async () => { | ||||
render(<CashtabTestWrapper chronik={mockedChronik} />); | render(<CashtabTestWrapper chronik={mockedChronik} />); | ||||
// Wait for the page to load | // Wait for the page to load | ||||
await waitFor(() => | await waitFor(() => | ||||
expect(screen.queryByTestId('loading-ctn')).not.toBeInTheDocument(), | expect(screen.queryByTestId('loading-ctn')).not.toBeInTheDocument(), | ||||
); | ); | ||||
// Wait balance to be rendered correctly so we know Cashtab has loaded the wallet | |||||
expect(await screen.findByTestId('balance-xec')).toHaveTextContent( | |||||
'10,000.00 XEC', | |||||
); | |||||
// We see the home container | // We see the home container | ||||
await screen.findByTestId('home-ctn'); | await screen.findByTestId('home-ctn'); | ||||
// Open the collapse of this tx in tx history | // Open the collapse of this tx in tx history | ||||
await user.click( | await user.click( | ||||
await screen.findByRole('button', { | await screen.findByRole('button', { | ||||
name: /Warning: This sender is not in your contact list. Beware of scams./, | name: /Warning: This sender is not in your contact list. Beware of scams./, | ||||
}), | }), | ||||
▲ Show 20 Lines • Show All 47 Lines • ▼ Show 20 Lines | it('Adding a contact to an existing contactList by clicking on tx history adds it to localforage and wallet context', async () => { | ||||
render(<CashtabTestWrapper chronik={mockedChronik} />); | render(<CashtabTestWrapper chronik={mockedChronik} />); | ||||
// Wait for the page to load | // Wait for the page to load | ||||
await waitFor(() => | await waitFor(() => | ||||
expect(screen.queryByTestId('loading-ctn')).not.toBeInTheDocument(), | expect(screen.queryByTestId('loading-ctn')).not.toBeInTheDocument(), | ||||
); | ); | ||||
// Wait balance to be rendered correctly so we know Cashtab has loaded the wallet | |||||
expect(await screen.findByTestId('balance-xec')).toHaveTextContent( | |||||
'10,000.00 XEC', | |||||
); | |||||
// We see the home container | // We see the home container | ||||
await screen.findByTestId('home-ctn'); | await screen.findByTestId('home-ctn'); | ||||
// Open the collapse of this tx in tx history | // Open the collapse of this tx in tx history | ||||
await user.click( | await user.click( | ||||
await screen.findByRole('button', { | await screen.findByRole('button', { | ||||
name: /Warning: This sender is not in your contact list. Beware of scams./, | name: /Warning: This sender is not in your contact list. Beware of scams./, | ||||
}), | }), | ||||
▲ Show 20 Lines • Show All 170 Lines • ▼ Show 20 Lines | it('Setting "Send Confirmations" settings will show send confirmations', async () => { | ||||
// Navigate to Settings screen | // Navigate to Settings screen | ||||
await user.click(screen.queryByTestId('nav-btn-configure')); | await user.click(screen.queryByTestId('nav-btn-configure')); | ||||
// Now we see the Settings screen | // Now we see the Settings screen | ||||
expect(screen.getByTestId('configure-ctn')).toBeInTheDocument(); | expect(screen.getByTestId('configure-ctn')).toBeInTheDocument(); | ||||
// Send confirmations are disabled by default | // Send confirmations are disabled by default | ||||
// Note, another antd issue. We can't get the switch by role bc antd switches are buttons with no name | |||||
// and no label | |||||
// So, use data-testid | |||||
const sendConfirmationsSwitch = screen.getByTestId( | |||||
'send-confirmations-switch', | |||||
); | |||||
// We cannot get switch checked status from the antd switch. So, disabled has a grey background. | |||||
expect(sendConfirmationsSwitch).toHaveStyle( | |||||
'background-color: #bdbdbd;', | |||||
); | |||||
// Enable send confirmations | // Enable send confirmations | ||||
await user.click(sendConfirmationsSwitch); | await user.click(screen.getByTestId('send-confirmations-switch')); | ||||
// Now the switch does not have a grey background | |||||
expect(sendConfirmationsSwitch).not.toHaveStyle( | |||||
'background-color: #bdbdbd;', | |||||
); | |||||
// Navigate to the Send screen | // Navigate to the Send screen | ||||
await user.click(screen.queryByTestId('nav-btn-send')); | await user.click(screen.queryByTestId('nav-btn-send')); | ||||
// Now we see the Send screen | // Now we see the Send screen | ||||
expect(screen.getByTestId('send-xec-ctn')).toBeInTheDocument(); | expect(screen.getByTestId('send-xec-ctn')).toBeInTheDocument(); | ||||
// Fill out to and amount | // Fill out to and amount | ||||
▲ Show 20 Lines • Show All 114 Lines • ▼ Show 20 Lines | it('Setting "ABSOLUTE MINIMUM fees" settings will reduce fees to absolute min', async () => { | ||||
// Navigate to Settings screen | // Navigate to Settings screen | ||||
await user.click(screen.queryByTestId('nav-btn-configure')); | await user.click(screen.queryByTestId('nav-btn-configure')); | ||||
// Now we see the Settings screen | // Now we see the Settings screen | ||||
expect(screen.getByTestId('configure-ctn')).toBeInTheDocument(); | expect(screen.getByTestId('configure-ctn')).toBeInTheDocument(); | ||||
// Send confirmations are disabled by default | // Send confirmations are disabled by default | ||||
// Note, another antd issue. We can't get the switch by role bc antd switches are buttons with no name | |||||
// and no label | |||||
// So, use data-testid | |||||
const minFeeSendsSwitch = screen.getByTestId( | |||||
'settings-minFeeSends-switch', | |||||
); | |||||
// We cannot get switch checked status from the antd switch. So, disabled has a grey background. | |||||
expect(minFeeSendsSwitch).toHaveStyle('background-color: #bdbdbd;'); | |||||
// Enable min fee sends | // Enable min fee sends | ||||
await user.click(minFeeSendsSwitch); | await user.click(screen.getByTestId('settings-minFeeSends-switch')); | ||||
// Now the switch does not have a grey background | |||||
expect(minFeeSendsSwitch).not.toHaveStyle('background-color: #bdbdbd;'); | |||||
// Navigate to the Send screen | // Navigate to the Send screen | ||||
await user.click(screen.queryByTestId('nav-btn-send')); | await user.click(screen.queryByTestId('nav-btn-send')); | ||||
// Now we see the Send screen | // Now we see the Send screen | ||||
expect(screen.getByTestId('send-xec-ctn')).toBeInTheDocument(); | expect(screen.getByTestId('send-xec-ctn')).toBeInTheDocument(); | ||||
// Fill out to and amount | // Fill out to and amount | ||||
▲ Show 20 Lines • Show All 219 Lines • ▼ Show 20 Lines | it('Migrating from wallet/savedWallet keys (version < 1.6.0): A user with an invalid Cashtab wallet as the active wallet is migrated on startup', async () => { | ||||
// Any wallet stored in legacy key structures will have pre_2_1_0 format (or earlier) | // Any wallet stored in legacy key structures will have pre_2_1_0 format (or earlier) | ||||
// i.e.balances key and Path1899, Path145, Path245 hard coded | // i.e.balances key and Path1899, Path145, Path245 hard coded | ||||
walletWithXecAndTokens_pre_2_1_0, | walletWithXecAndTokens_pre_2_1_0, | ||||
localforage, | localforage, | ||||
); | ); | ||||
render(<CashtabTestWrapper chronik={mockedChronik} />); | render(<CashtabTestWrapper chronik={mockedChronik} />); | ||||
// Wait for the app to load | |||||
await waitFor(() => | |||||
expect(screen.queryByTestId('loading-ctn')).not.toBeInTheDocument(), | |||||
); | |||||
// Wait balance to be rendered correctly so we know Cashtab has loaded the wallet | // Wait balance to be rendered correctly so we know Cashtab has loaded the wallet | ||||
expect(await screen.findByTestId('balance-xec')).toHaveTextContent( | expect(await screen.findByTestId('balance-xec')).toHaveTextContent( | ||||
'9,513.12 XEC', | '9,513.12 XEC', | ||||
); | ); | ||||
// Check wallet in localforage | // Check wallet in localforage | ||||
const wallets = await localforage.getItem('wallets'); | const wallets = await localforage.getItem('wallets'); | ||||
const migratedWallet = cashtabWalletFromJSON(wallets[0]); | const migratedWallet = cashtabWalletFromJSON(wallets[0]); | ||||
Show All 15 Lines | it('Migrating from wallet/savedWallet keys (version < 1.6.0): A user with pre-2.1.0 valid wallets in savedWallets has them all migrated to new storage keys and new shape', async () => { | ||||
// Note that, as of 2.1.0, any wallet found in the legacy savedWallets key will be invalid | // Note that, as of 2.1.0, any wallet found in the legacy savedWallets key will be invalid | ||||
await localforage.setItem('savedWallets', [ | await localforage.setItem('savedWallets', [ | ||||
...validSavedWallets_pre_2_1_0, | ...validSavedWallets_pre_2_1_0, | ||||
walletWithXecAndTokens_pre_2_1_0, | walletWithXecAndTokens_pre_2_1_0, | ||||
]); | ]); | ||||
render(<CashtabTestWrapper chronik={mockedChronik} />); | render(<CashtabTestWrapper chronik={mockedChronik} />); | ||||
// Wait for the app to load | |||||
await waitFor(() => | |||||
expect(screen.queryByTestId('loading-ctn')).not.toBeInTheDocument(), | |||||
); | |||||
// Wait balance to be rendered correctly so we know Cashtab has loaded the wallet | // Wait balance to be rendered correctly so we know Cashtab has loaded the wallet | ||||
expect(await screen.findByTestId('balance-xec')).toHaveTextContent( | expect(await screen.findByTestId('balance-xec')).toHaveTextContent( | ||||
'9,513.12 XEC', | '9,513.12 XEC', | ||||
); | ); | ||||
// Check wallets | // Check wallets | ||||
const walletsAfterLoad = cashtabWalletsFromJSON( | const walletsAfterLoad = cashtabWalletsFromJSON( | ||||
await localforage.getItem('wallets'), | await localforage.getItem('wallets'), | ||||
Show All 17 Lines | it('Migrating (version >= 1.6.0 and < 2.1.0): A user with an invalid wallet stored at wallets key has that wallet migrated', async () => { | ||||
const mockedChronik = await initializeCashtabStateForTests( | const mockedChronik = await initializeCashtabStateForTests( | ||||
mixedValidWallets, | mixedValidWallets, | ||||
localforage, | localforage, | ||||
); | ); | ||||
render(<CashtabTestWrapper chronik={mockedChronik} />); | render(<CashtabTestWrapper chronik={mockedChronik} />); | ||||
// Wait for the app to load | |||||
await waitFor(() => | |||||
expect(screen.queryByTestId('loading-ctn')).not.toBeInTheDocument(), | |||||
); | |||||
// Wait balance to be rendered correctly so we know Cashtab has loaded the wallet | // Wait balance to be rendered correctly so we know Cashtab has loaded the wallet | ||||
expect(await screen.findByTestId('balance-xec')).toHaveTextContent( | expect(await screen.findByTestId('balance-xec')).toHaveTextContent( | ||||
'9,513.12 XEC', | '9,513.12 XEC', | ||||
); | ); | ||||
// Check wallets | // Check wallets | ||||
const walletsAfterLoad = cashtabWalletsFromJSON( | const walletsAfterLoad = cashtabWalletsFromJSON( | ||||
await localforage.getItem('wallets'), | await localforage.getItem('wallets'), | ||||
Show All 21 Lines | it('Migrating (version >= 1.6.0 and < 2.1.0): A user with multiple invalid wallets stored at wallets key has them migrated', async () => { | ||||
const mockedChronik = await initializeCashtabStateForTests( | const mockedChronik = await initializeCashtabStateForTests( | ||||
mixedValidWallets, | mixedValidWallets, | ||||
localforage, | localforage, | ||||
); | ); | ||||
render(<CashtabTestWrapper chronik={mockedChronik} />); | render(<CashtabTestWrapper chronik={mockedChronik} />); | ||||
// Wait for the app to load | |||||
await waitFor(() => | |||||
expect(screen.queryByTestId('loading-ctn')).not.toBeInTheDocument(), | |||||
); | |||||
// Wait balance to be rendered correctly so we know Cashtab has loaded the wallet | // Wait balance to be rendered correctly so we know Cashtab has loaded the wallet | ||||
expect(await screen.findByTestId('balance-xec')).toHaveTextContent( | expect(await screen.findByTestId('balance-xec')).toHaveTextContent( | ||||
'9,513.12 XEC', | '9,513.12 XEC', | ||||
); | ); | ||||
// Check wallets | // Check wallets | ||||
const walletsAfterLoad = cashtabWalletsFromJSON( | const walletsAfterLoad = cashtabWalletsFromJSON( | ||||
await localforage.getItem('wallets'), | await localforage.getItem('wallets'), | ||||
Show All 9 Lines | describe('<App />', () => { | ||||
it('Cashtab version >= 1.6.0 and < 2.1.0: A user with an invalid Cashtab wallet as the active wallet is migrated on startup', async () => { | it('Cashtab version >= 1.6.0 and < 2.1.0: A user with an invalid Cashtab wallet as the active wallet is migrated on startup', async () => { | ||||
const mockedChronik = await initializeCashtabStateForTests( | const mockedChronik = await initializeCashtabStateForTests( | ||||
walletWithXecAndTokens_pre_2_1_0, | walletWithXecAndTokens_pre_2_1_0, | ||||
localforage, | localforage, | ||||
); | ); | ||||
render(<CashtabTestWrapper chronik={mockedChronik} />); | render(<CashtabTestWrapper chronik={mockedChronik} />); | ||||
// Wait for the app to load | |||||
await waitFor(() => | |||||
expect(screen.queryByTestId('loading-ctn')).not.toBeInTheDocument(), | |||||
); | |||||
// Wait balance to be rendered correctly so we know Cashtab has loaded the wallet | // Wait balance to be rendered correctly so we know Cashtab has loaded the wallet | ||||
expect(await screen.findByTestId('balance-xec')).toHaveTextContent( | expect(await screen.findByTestId('balance-xec')).toHaveTextContent( | ||||
'9,513.12 XEC', | '9,513.12 XEC', | ||||
); | ); | ||||
// Check wallet in localforage | // Check wallet in localforage | ||||
const wallets = await localforage.getItem('wallets'); | const wallets = await localforage.getItem('wallets'); | ||||
const migratedWallet = cashtabWalletFromJSON(wallets[0]); | const migratedWallet = cashtabWalletFromJSON(wallets[0]); | ||||
// The wallet has been migrated | // The wallet has been migrated | ||||
expect(migratedWallet).toEqual(walletWithXecAndTokens); | expect(migratedWallet).toEqual(walletWithXecAndTokens); | ||||
}); | }); | ||||
it('A user with all valid wallets stored at wallets key does not have any wallets migrated', async () => { | it('A user with all valid wallets stored at wallets key does not have any wallets migrated', async () => { | ||||
const mockedChronik = await initializeCashtabStateForTests( | const mockedChronik = await initializeCashtabStateForTests( | ||||
[walletWithXecAndTokens, ...validSavedWallets], | [walletWithXecAndTokens, ...validSavedWallets], | ||||
localforage, | localforage, | ||||
); | ); | ||||
render(<CashtabTestWrapper chronik={mockedChronik} />); | render(<CashtabTestWrapper chronik={mockedChronik} />); | ||||
// Wait for the app to load | |||||
await waitFor(() => | |||||
expect(screen.queryByTestId('loading-ctn')).not.toBeInTheDocument(), | |||||
); | |||||
// Wait balance to be rendered correctly so we know Cashtab has loaded the wallet | // Wait balance to be rendered correctly so we know Cashtab has loaded the wallet | ||||
expect(await screen.findByTestId('balance-xec')).toHaveTextContent( | expect(await screen.findByTestId('balance-xec')).toHaveTextContent( | ||||
'9,513.12 XEC', | '9,513.12 XEC', | ||||
); | ); | ||||
const walletsAfterLoad = cashtabWalletsFromJSON( | const walletsAfterLoad = cashtabWalletsFromJSON( | ||||
await localforage.getItem('wallets'), | await localforage.getItem('wallets'), | ||||
); | ); | ||||
Show All 19 Lines | it('Migrating (version < 2.9.0): A user with multiple invalid wallets stored at wallets key has them migrated', async () => { | ||||
const mockedChronik = await initializeCashtabStateForTests( | const mockedChronik = await initializeCashtabStateForTests( | ||||
mixedValidWallets, | mixedValidWallets, | ||||
localforage, | localforage, | ||||
); | ); | ||||
render(<CashtabTestWrapper chronik={mockedChronik} />); | render(<CashtabTestWrapper chronik={mockedChronik} />); | ||||
// Wait for the page to load | |||||
await waitFor(() => | |||||
expect(screen.queryByTestId('loading-ctn')).not.toBeInTheDocument(), | |||||
); | |||||
// Wait balance to be rendered correctly so we know Cashtab has loaded the wallet | // Wait balance to be rendered correctly so we know Cashtab has loaded the wallet | ||||
expect(await screen.findByTestId('balance-xec')).toHaveTextContent( | expect(await screen.findByTestId('balance-xec')).toHaveTextContent( | ||||
'9,513.12 XEC', | '9,513.12 XEC', | ||||
); | ); | ||||
// Check wallets | // Check wallets | ||||
const walletsAfterLoad = cashtabWalletsFromJSON( | const walletsAfterLoad = cashtabWalletsFromJSON( | ||||
await localforage.getItem('wallets'), | await localforage.getItem('wallets'), | ||||
Show All 9 Lines | |||||
it('Migrating (version < 2.9.0): A user with an invalid Cashtab wallet as the active wallet is migrated on startup', async () => { | it('Migrating (version < 2.9.0): A user with an invalid Cashtab wallet as the active wallet is migrated on startup', async () => { | ||||
const mockedChronik = await initializeCashtabStateForTests( | const mockedChronik = await initializeCashtabStateForTests( | ||||
walletWithXecAndTokens_pre_2_9_0, | walletWithXecAndTokens_pre_2_9_0, | ||||
localforage, | localforage, | ||||
); | ); | ||||
render(<CashtabTestWrapper chronik={mockedChronik} />); | render(<CashtabTestWrapper chronik={mockedChronik} />); | ||||
// Wait for the page to load | |||||
await waitFor(() => | |||||
expect(screen.queryByTestId('loading-ctn')).not.toBeInTheDocument(), | |||||
); | |||||
// Wait balance to be rendered correctly so we know Cashtab has loaded the wallet | // Wait balance to be rendered correctly so we know Cashtab has loaded the wallet | ||||
expect(await screen.findByTestId('balance-xec')).toHaveTextContent( | expect(await screen.findByTestId('balance-xec')).toHaveTextContent( | ||||
'9,513.12 XEC', | '9,513.12 XEC', | ||||
); | ); | ||||
// Check wallet in localforage | // Check wallet in localforage | ||||
const wallets = await localforage.getItem('wallets'); | const wallets = await localforage.getItem('wallets'); | ||||
const migratedWallet = cashtabWalletFromJSON(wallets[0]); | const migratedWallet = cashtabWalletFromJSON(wallets[0]); | ||||
▲ Show 20 Lines • Show All 77 Lines • Show Last 20 Lines |