Changeset View
Changeset View
Standalone View
Standalone View
cashtab/src/components/OnBoarding/__tests__/index.test.tsx
| Show All 11 Lines | |||||
| import appConfig from 'config/app'; | import appConfig from 'config/app'; | ||||
| import { | import { | ||||
| initializeCashtabStateForTests, | initializeCashtabStateForTests, | ||||
| clearLocalForage, | clearLocalForage, | ||||
| } from 'components/App/fixtures/helpers'; | } from 'components/App/fixtures/helpers'; | ||||
| import CashtabTestWrapper from 'components/App/fixtures/CashtabTestWrapper'; | import CashtabTestWrapper from 'components/App/fixtures/CashtabTestWrapper'; | ||||
| import { Ecc } from 'ecash-lib'; | import { Ecc } from 'ecash-lib'; | ||||
| /** Public test fixture only — do not use for real funds (see wallet/fixtures/vectors). */ | |||||
| const BURNED_ONBOARDING_MNEMONIC = | |||||
| 'beauty shoe decline spend still weird slot snack coach flee between paper'; | |||||
| const BURNED_ONBOARDING_WALLET_ADDRESS = | |||||
| 'ecash:qqa9lv3kjd8vq7952p7rq0f6lkpqvlu0cydvxtd70g'; | |||||
| describe('<OnBoarding />', () => { | describe('<OnBoarding />', () => { | ||||
| const ecc = new Ecc(); | const ecc = new Ecc(); | ||||
| beforeEach(() => { | beforeEach(() => { | ||||
| // Mock the fetch call for Cashtab's price API | // Mock the fetch call for Cashtab's price API | ||||
| global.fetch = jest.fn(); | global.fetch = jest.fn(); | ||||
| const fiatCode = 'usd'; // Use usd until you mock getting settings from localforage | const fiatCode = 'usd'; // Use usd until you mock getting settings from localforage | ||||
| const cryptoId = appConfig.coingeckoId; | const cryptoId = appConfig.coingeckoId; | ||||
| // Keep this in the code, because different URLs will have different outputs requiring different parsing | // Keep this in the code, because different URLs will have different outputs requiring different parsing | ||||
| Show All 11 Lines | beforeEach(() => { | ||||
| json: () => Promise.resolve(priceResponse), | json: () => Promise.resolve(priceResponse), | ||||
| }); | }); | ||||
| }); | }); | ||||
| afterEach(async () => { | afterEach(async () => { | ||||
| jest.clearAllMocks(); | jest.clearAllMocks(); | ||||
| await clearLocalForage(localforage); | await clearLocalForage(localforage); | ||||
| }); | }); | ||||
| it('With no wallet, first load shows New and Import; Import accepts burned test seed', async () => { | |||||
| const mockedChronik = await initializeCashtabStateForTests( | |||||
| false, | |||||
| localforage, | |||||
| ); | |||||
| mockedChronik.setBlockchainInfo({ tipHeight: 800000 }); | |||||
| mockedChronik.setTxHistoryByAddress( | |||||
| BURNED_ONBOARDING_WALLET_ADDRESS, | |||||
| [], | |||||
| ); | |||||
| render(<CashtabTestWrapper ecc={ecc} chronik={mockedChronik} />); | |||||
| await waitFor(() => | |||||
| expect( | |||||
| screen.queryByTitle('Cashtab Loading'), | |||||
| ).not.toBeInTheDocument(), | |||||
| ); | |||||
| const newWalletBtn = screen.getByRole('button', { name: /New Wallet/ }); | |||||
| const importWalletBtn = screen.getByRole('button', { | |||||
| name: /Import Wallet/, | |||||
| }); | |||||
| expect(newWalletBtn).toBeVisible(); | |||||
| expect(importWalletBtn).toBeVisible(); | |||||
| await userEvent.click(importWalletBtn); | |||||
| const mnemonicField = screen.getByPlaceholderText( | |||||
| 'mnemonic (seed phrase)', | |||||
| ); | |||||
| expect(mnemonicField).toBeInTheDocument(); | |||||
| await userEvent.type(mnemonicField, BURNED_ONBOARDING_MNEMONIC); | |||||
| const okBtn = screen.getByRole('button', { name: 'OK' }); | |||||
| expect(okBtn).toHaveProperty('disabled', false); | |||||
| await userEvent.click(okBtn); | |||||
| const walletsAfterImport = await localforage.getItem('wallets'); | |||||
| expect(walletsAfterImport).toHaveLength(1); | |||||
| expect( | |||||
| (walletsAfterImport as Array<{ name: string; address: string }>)[0] | |||||
| .name, | |||||
| ).toBe('qqa...70g'); | |||||
| expect( | |||||
| (walletsAfterImport as Array<{ name: string; address: string }>)[0] | |||||
| .address, | |||||
| ).toBe(BURNED_ONBOARDING_WALLET_ADDRESS); | |||||
| await waitFor(() => | |||||
| expect( | |||||
| screen.queryByPlaceholderText('mnemonic (seed phrase)'), | |||||
| ).not.toBeInTheDocument(), | |||||
| ); | |||||
| expect( | |||||
| await screen.findByText('Backup your wallet'), | |||||
| ).toBeInTheDocument(); | |||||
| }); | |||||
| it('We can create a new wallet', async () => { | it('We can create a new wallet', async () => { | ||||
| // localforage defaults | // localforage defaults | ||||
| const mockedChronik = await initializeCashtabStateForTests( | const mockedChronik = await initializeCashtabStateForTests( | ||||
| false, | false, | ||||
| localforage, | localforage, | ||||
| ); | ); | ||||
| // Set up blockchainInfo (required for Wallet.sync()) | // Set up blockchainInfo (required for Wallet.sync()) | ||||
| Show All 27 Lines | it('We can create a new wallet', async () => { | ||||
| }), | }), | ||||
| ); | ); | ||||
| // We see the backup wallet alert | // We see the backup wallet alert | ||||
| expect( | expect( | ||||
| await screen.findByText('Backup your wallet'), | await screen.findByText('Backup your wallet'), | ||||
| ).toBeInTheDocument(); | ).toBeInTheDocument(); | ||||
| // We see a QR code | // We see a QR code on the Receive page | ||||
| await userEvent.click(screen.getByRole('link', { name: /Receive/ })); | |||||
| expect(screen.getByTitle('Raw QR Code')).toBeInTheDocument(); | expect(screen.getByTitle('Raw QR Code')).toBeInTheDocument(); | ||||
| // New wallet is added in localforage | // New wallet is added in localforage | ||||
| const walletsAfterAdd = await localforage.getItem('wallets'); | const walletsAfterAdd = await localforage.getItem('wallets'); | ||||
| expect(walletsAfterAdd).toHaveLength(1); | expect(walletsAfterAdd).toHaveLength(1); | ||||
| }); | }); | ||||
| it('We can import a wallet', async () => { | it('We can import a wallet', async () => { | ||||
| // localforage defaults | // localforage defaults | ||||
| ▲ Show 20 Lines • Show All 85 Lines • ▼ Show 20 Lines | it('We can import a wallet', async () => { | ||||
| ).not.toBeInTheDocument(), | ).not.toBeInTheDocument(), | ||||
| ); | ); | ||||
| // We see the backup wallet alert | // We see the backup wallet alert | ||||
| expect( | expect( | ||||
| await screen.findByText('Backup your wallet'), | await screen.findByText('Backup your wallet'), | ||||
| ).toBeInTheDocument(); | ).toBeInTheDocument(); | ||||
| // We see a QR code | // We see a QR code on the Receive page | ||||
| await userEvent.click(screen.getByRole('link', { name: /Receive/ })); | |||||
| expect(screen.getByTitle('Raw QR Code')).toBeInTheDocument(); | expect(screen.getByTitle('Raw QR Code')).toBeInTheDocument(); | ||||
| }); | }); | ||||
| }); | }); | ||||