Changeset View
Changeset View
Standalone View
Standalone View
cashtab/src/components/Configure/__tests__/Configure.test.js
Show All 16 Lines | |||||
import { | import { | ||||
initializeCashtabStateForTests, | initializeCashtabStateForTests, | ||||
prepareMockedChronikCallsForWallet, | prepareMockedChronikCallsForWallet, | ||||
clearLocalForage, | clearLocalForage, | ||||
} from 'components/fixtures/helpers'; | } from 'components/fixtures/helpers'; | ||||
import { validSavedWallets } from 'components/fixtures/mocks'; | import { validSavedWallets } from 'components/fixtures/mocks'; | ||||
import CashtabTestWrapper from 'components/fixtures/CashtabTestWrapper'; | import CashtabTestWrapper from 'components/fixtures/CashtabTestWrapper'; | ||||
import * as bip39 from 'bip39'; | import * as bip39 from 'bip39'; | ||||
import { cashtabWalletsFromJSON } from 'helpers'; | |||||
// https://stackoverflow.com/questions/39830580/jest-test-fails-typeerror-window-matchmedia-is-not-a-function | // https://stackoverflow.com/questions/39830580/jest-test-fails-typeerror-window-matchmedia-is-not-a-function | ||||
Object.defineProperty(window, 'matchMedia', { | Object.defineProperty(window, 'matchMedia', { | ||||
writable: true, | writable: true, | ||||
value: jest.fn().mockImplementation(query => ({ | value: jest.fn().mockImplementation(query => ({ | ||||
matches: false, | matches: false, | ||||
media: query, | media: query, | ||||
onchange: null, | onchange: null, | ||||
▲ Show 20 Lines • Show All 67 Lines • ▼ Show 20 Lines | it('We can add, delete, rename, contacts from the Configure screen, and add a savedWallet as a contact', async () => { | ||||
// Custom contact list | // Custom contact list | ||||
await localforage.setItem('contactList', populatedContactList); | await localforage.setItem('contactList', populatedContactList); | ||||
const savedWallet = validSavedWallets[0]; | const savedWallet = validSavedWallets[0]; | ||||
// Add a new saved wallet that can be rendered | // Add a new saved wallet that can be rendered | ||||
const addedSavedWalletContact = { | const addedSavedWalletContact = { | ||||
address: savedWallet.paths.find(pathInfo => pathInfo.path === 1899) | address: savedWallet.paths.get(1899).address, | ||||
.address, | |||||
name: savedWallet.name, | name: savedWallet.name, | ||||
}; | }; | ||||
await localforage.setItem('wallets', [ | await localforage.setItem('wallets', [ | ||||
walletWithXecAndTokens, | walletWithXecAndTokens, | ||||
savedWallet, | savedWallet, | ||||
]); | ]); | ||||
render( | render( | ||||
▲ Show 20 Lines • Show All 350 Lines • ▼ Show 20 Lines | it('We can rename the active wallet or a saved wallet, we can add a wallet, we can import a wallet, we can delete a wallet', async () => { | ||||
).toBeInTheDocument(); | ).toBeInTheDocument(); | ||||
// wallet ALPHA PRIME is no longer in savedWallets list | // wallet ALPHA PRIME is no longer in savedWallets list | ||||
await waitFor(() => | await waitFor(() => | ||||
expect(screen.queryByText('ALPHA PRIME')).not.toBeInTheDocument(), | expect(screen.queryByText('ALPHA PRIME')).not.toBeInTheDocument(), | ||||
); | ); | ||||
// nor is it in localforage | // nor is it in localforage | ||||
const walletsNow = await localforage.getItem('wallets'); | const walletsNow = cashtabWalletsFromJSON( | ||||
await localforage.getItem('wallets'), | |||||
); | |||||
const expectedWalletsNow = [ | const expectedWalletsNow = [ | ||||
...[walletWithXecAndTokens].concat(validSavedWallets), | ...[walletWithXecAndTokens].concat(validSavedWallets), | ||||
]; | ]; | ||||
// The active wallet has been renamed | // The active wallet has been renamed | ||||
expectedWalletsNow[0].name = 'ACTIVE WALLET'; | expectedWalletsNow[0].name = 'ACTIVE WALLET'; | ||||
// We no longer have wallet alpha -- delete it | // We no longer have wallet alpha -- delete it | ||||
const alphaIndex = expectedWalletsNow.findIndex( | const alphaIndex = expectedWalletsNow.findIndex( | ||||
wallet => wallet.name === 'alpha', | wallet => wallet.name === 'alpha', | ||||
▲ Show 20 Lines • Show All 153 Lines • Show Last 20 Lines |