Skip to content

Commit

Permalink
chore(test): prevent test env warning
Browse files Browse the repository at this point in the history
  • Loading branch information
theborakompanioni committed Nov 28, 2023
1 parent 918c287 commit 49cdfad
Show file tree
Hide file tree
Showing 6 changed files with 123 additions and 185 deletions.
28 changes: 9 additions & 19 deletions src/components/App.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,7 @@ describe('<App />', () => {
})

it('should display Onboarding screen initially', async () => {
act(() => {
render(<App />)
})
await act(async () => render(<App />))

// Onboarding screen
expect(screen.getByText('onboarding.splashscreen_button_get_started')).toBeInTheDocument()
Expand All @@ -29,20 +27,16 @@ describe('<App />', () => {
// Wallets screen shown after Intro is skipped
expect(screen.queryByText('wallets.title')).not.toBeInTheDocument()

await act(async () => {
const skipIntro = screen.getByText('onboarding.splashscreen_button_skip_intro')
await user.click(skipIntro)
})
const skipIntro = screen.getByText('onboarding.splashscreen_button_skip_intro')
await user.click(skipIntro)

expect(screen.getByText('wallets.title')).toBeInTheDocument()
})

it('should display Wallets screen directly when Onboarding screen has been shown', () => {
it('should display Wallets screen directly when Onboarding screen has been shown', async () => {
global.__DEV__.addToAppSettings({ showOnboarding: false })

act(() => {
render(<App />)
})
await act(async () => render(<App />))

// Wallets screen
expect(screen.getByText('wallets.title')).toBeInTheDocument()
Expand All @@ -52,17 +46,13 @@ describe('<App />', () => {
it('should display a modal with beta warning information', async () => {
global.__DEV__.addToAppSettings({ showOnboarding: false })

act(() => {
render(<App />)
})
await act(async () => render(<App />))

expect(screen.getByText('Read this before using.')).toBeInTheDocument()
expect(screen.queryByText(/While JoinMarket is tried and tested, Jam is not./)).not.toBeInTheDocument()

await act(async () => {
const readThis = screen.getByText('Read this before using.')
await user.click(readThis)
})
const readThis = screen.getByText('Read this before using.')
await user.click(readThis)

expect(screen.getByText('footer.warning_alert_text')).toBeInTheDocument()
expect(screen.getByText('footer.warning_alert_button_ok')).toBeInTheDocument()
Expand All @@ -71,7 +61,7 @@ describe('<App />', () => {
/*it('should display a websocket connection indicator', async () => {
global.__DEV__.addToAppSettings({ showOnboarding: false })
act(() => {
await act(async () => {
render(<App />)
})
Expand Down
26 changes: 7 additions & 19 deletions src/components/Balance.test.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { render, act } from '@testing-library/react'
import { render } from '@testing-library/react'
import user from '@testing-library/user-event'
import { screen } from '../testUtils'
import { BTC, SATS } from '../utils'
Expand Down Expand Up @@ -112,16 +112,12 @@ describe('<Balance />', () => {
expect(screen.queryByTestId(`sats-amount`)).not.toBeInTheDocument()
expect(screen.getByText(`*****`)).toBeInTheDocument()

await act(async () => {
await user.click(screen.getByText(`*****`))
})
await user.click(screen.getByText(`*****`))

expect(screen.getByTestId(`sats-amount`)).toBeInTheDocument()
expect(screen.queryByText(`*****`)).not.toBeInTheDocument()

await act(async () => {
await user.click(screen.getByTestId(`sats-amount`))
})
await user.click(screen.getByTestId(`sats-amount`))

expect(screen.queryByTestId(`sats-amount`)).not.toBeInTheDocument()
expect(screen.getByText(`*****`)).toBeInTheDocument()
Expand All @@ -132,9 +128,7 @@ describe('<Balance />', () => {
expect(screen.queryByTestId(`sats-amount`)).not.toBeInTheDocument()
expect(screen.getByText(`*****`)).toBeInTheDocument()

await act(async () => {
await user.click(screen.getByText(`*****`))
})
await user.click(screen.getByText(`*****`))

expect(screen.queryByTestId(`sats-amount`)).not.toBeInTheDocument()
expect(screen.getByText(`*****`)).toBeInTheDocument()
Expand All @@ -145,9 +139,7 @@ describe('<Balance />', () => {
expect(screen.getByTestId(`sats-amount`)).toBeInTheDocument()
expect(screen.queryByText(`*****`)).not.toBeInTheDocument()

await act(async () => {
await user.click(screen.getByTestId(`sats-amount`))
})
await user.click(screen.getByTestId(`sats-amount`))

expect(screen.getByTestId(`sats-amount`)).toBeInTheDocument()
expect(screen.queryByText(`*****`)).not.toBeInTheDocument()
Expand All @@ -158,16 +150,12 @@ describe('<Balance />', () => {
expect(screen.getByTestId(`sats-amount`)).toBeInTheDocument()
expect(screen.queryByText(`*****`)).not.toBeInTheDocument()

await act(async () => {
await user.click(screen.getByTestId(`sats-amount`))
})
await user.click(screen.getByTestId(`sats-amount`))

expect(screen.queryByTestId(`sats-amount`)).not.toBeInTheDocument()
expect(screen.getByText(`*****`)).toBeInTheDocument()

await act(async () => {
await user.click(screen.getByText(`*****`))
})
await user.click(screen.getByText(`*****`))

expect(screen.getByTestId(`sats-amount`)).toBeInTheDocument()
expect(screen.queryByText(`*****`)).not.toBeInTheDocument()
Expand Down
108 changes: 43 additions & 65 deletions src/components/CreateWallet.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ describe('<CreateWallet />', () => {
})

it('should render without errors', () => {
act(() => setup({}))
setup({})

expect(screen.getByText('create_wallet.title')).toBeVisible()
expect(screen.getByLabelText('create_wallet.label_wallet_name')).toBeVisible()
Expand All @@ -72,58 +72,52 @@ describe('<CreateWallet />', () => {
})

it('should show validation messages to user if form is invalid', async () => {
act(() => setup({}))
setup({})

expect(await screen.queryByText('create_wallet.feedback_invalid_wallet_name')).not.toBeInTheDocument()
expect(await screen.queryByText('create_wallet.feedback_invalid_password')).not.toBeInTheDocument()
expect(await screen.queryByText('create_wallet.feedback_invalid_password_confirm')).not.toBeInTheDocument()
expect(await screen.findByText('create_wallet.button_create')).toBeVisible()

await act(async () => {
// click on the "create" button without filling the form
await user.click(screen.getByText('create_wallet.button_create'))
})
// click on the "create" button without filling the form
await user.click(screen.getByText('create_wallet.button_create'))

expect(await screen.findByText('create_wallet.feedback_invalid_wallet_name')).toBeVisible()
expect(await screen.findByText('create_wallet.feedback_invalid_password')).toBeVisible()
expect(await screen.findByText('create_wallet.feedback_invalid_password_confirm')).toBeVisible()
})

it('should not submit form if wallet name contains invalid characters', async () => {
act(() => setup({}))
setup({})

expect(await screen.queryByText('create_wallet.feedback_invalid_wallet_name')).not.toBeInTheDocument()
expect(await screen.queryByText('create_wallet.feedback_invalid_password_confirm')).not.toBeInTheDocument()

await act(async () => {
await user.type(screen.getByPlaceholderText('create_wallet.placeholder_wallet_name'), invalidTestWalletName)
await user.type(screen.getByPlaceholderText('create_wallet.placeholder_password'), testWalletPassword)
await user.type(screen.getByPlaceholderText('create_wallet.placeholder_password_confirm'), testWalletPassword)
})
await user.type(screen.getByPlaceholderText('create_wallet.placeholder_wallet_name'), invalidTestWalletName)
await user.type(screen.getByPlaceholderText('create_wallet.placeholder_password'), testWalletPassword)
await user.type(screen.getByPlaceholderText('create_wallet.placeholder_password_confirm'), testWalletPassword)

await act(async () => await user.click(screen.getByText('create_wallet.button_create')))
await user.click(screen.getByText('create_wallet.button_create'))

expect(await screen.findByText('create_wallet.button_create')).toBeVisible()
expect(await screen.findByText('create_wallet.feedback_invalid_wallet_name')).toBeVisible()
expect(await screen.queryByText('create_wallet.feedback_invalid_password_confirm')).not.toBeInTheDocument()
})

it('should not submit form if passwords do not match', async () => {
act(() => setup({}))
setup({})

expect(await screen.findByPlaceholderText('create_wallet.placeholder_password')).toBeVisible()
expect(await screen.findByPlaceholderText('create_wallet.placeholder_password_confirm')).toBeVisible()
expect(await screen.queryByText('create_wallet.feedback_invalid_wallet_name')).not.toBeInTheDocument()
expect(await screen.queryByText('create_wallet.feedback_invalid_password_confirm')).not.toBeInTheDocument()
expect(await screen.findByText('create_wallet.button_create')).toBeVisible()

await act(async () => {
await user.type(screen.getByPlaceholderText('create_wallet.placeholder_wallet_name'), testWalletName)
await user.type(screen.getByPlaceholderText('create_wallet.placeholder_password'), '.*')
await user.type(screen.getByPlaceholderText('create_wallet.placeholder_password_confirm'), 'a_mismatching_input')
})
await user.type(screen.getByPlaceholderText('create_wallet.placeholder_wallet_name'), testWalletName)
await user.type(screen.getByPlaceholderText('create_wallet.placeholder_password'), '.*')
await user.type(screen.getByPlaceholderText('create_wallet.placeholder_password_confirm'), 'a_mismatching_input')

await act(async () => await user.click(screen.getByText('create_wallet.button_create')))
await user.click(screen.getByText('create_wallet.button_create'))

expect(await screen.findByText('create_wallet.button_create')).toBeVisible()
expect(await screen.queryByText('create_wallet.feedback_invalid_wallet_name')).not.toBeInTheDocument()
Expand All @@ -143,20 +137,16 @@ describe('<CreateWallet />', () => {
}),
)

act(() => setup({}))
setup({})

expect(await screen.findByText('create_wallet.button_create')).toBeVisible()
expect(await screen.queryByText('create_wallet.title_wallet_created')).not.toBeInTheDocument()

await act(async () => {
await user.type(screen.getByPlaceholderText('create_wallet.placeholder_wallet_name'), testWalletName)
await user.type(screen.getByPlaceholderText('create_wallet.placeholder_password'), testWalletPassword)
await user.type(screen.getByPlaceholderText('create_wallet.placeholder_password_confirm'), testWalletPassword)
})
await user.type(screen.getByPlaceholderText('create_wallet.placeholder_wallet_name'), testWalletName)
await user.type(screen.getByPlaceholderText('create_wallet.placeholder_password'), testWalletPassword)
await user.type(screen.getByPlaceholderText('create_wallet.placeholder_password_confirm'), testWalletPassword)

await act(async () => {
await user.click(screen.getByText('create_wallet.button_create'))
})
await user.click(screen.getByText('create_wallet.button_create'))

expect(screen.getByText('create_wallet.title_wallet_created')).toBeVisible()
expect(screen.queryByText('create_wallet.button_create')).not.toBeInTheDocument()
Expand All @@ -175,29 +165,23 @@ describe('<CreateWallet />', () => {
}),
)

act(() => setup({}))
setup({})

await act(async () => {
await user.type(screen.getByPlaceholderText('create_wallet.placeholder_wallet_name'), testWalletName)
await user.type(screen.getByPlaceholderText('create_wallet.placeholder_password'), testWalletPassword)
await user.type(screen.getByPlaceholderText('create_wallet.placeholder_password_confirm'), testWalletPassword)
})
await user.type(screen.getByPlaceholderText('create_wallet.placeholder_wallet_name'), testWalletName)
await user.type(screen.getByPlaceholderText('create_wallet.placeholder_password'), testWalletPassword)
await user.type(screen.getByPlaceholderText('create_wallet.placeholder_password_confirm'), testWalletPassword)

await act(async () => {
const createWalletButton = screen.getByText('create_wallet.button_create')
await user.click(createWalletButton)
})
const createWalletButton = screen.getByText('create_wallet.button_create')
await user.click(createWalletButton)

await act(async () => {
const revealToggle = await screen.findByText('create_wallet.confirmation_toggle_reveal_info')
await user.click(revealToggle)
const revealToggle = await screen.findByText('create_wallet.confirmation_toggle_reveal_info')
await user.click(revealToggle)

const confirmToggle = screen.getByText('create_wallet.confirmation_toggle_info_written_down')
await user.click(confirmToggle)
const confirmToggle = screen.getByText('create_wallet.confirmation_toggle_info_written_down')
await user.click(confirmToggle)

const nextButton = screen.getByText('create_wallet.next_button')
await user.click(nextButton)
})
const nextButton = screen.getByText('create_wallet.next_button')
await user.click(nextButton)

expect(screen.queryByText('create_wallet.skip_button')).not.toBeInTheDocument()
expect(screen.getByText('create_wallet.back_button')).toBeVisible()
Expand All @@ -216,29 +200,23 @@ describe('<CreateWallet />', () => {
}),
})

act(() => setup({}))
setup({})

await act(async () => {
await user.type(screen.getByPlaceholderText('create_wallet.placeholder_wallet_name'), testWalletName)
await user.type(screen.getByPlaceholderText('create_wallet.placeholder_password'), testWalletPassword)
await user.type(screen.getByPlaceholderText('create_wallet.placeholder_password_confirm'), testWalletPassword)
})
await user.type(screen.getByPlaceholderText('create_wallet.placeholder_wallet_name'), testWalletName)
await user.type(screen.getByPlaceholderText('create_wallet.placeholder_password'), testWalletPassword)
await user.type(screen.getByPlaceholderText('create_wallet.placeholder_password_confirm'), testWalletPassword)

await act(async () => {
const createWalletButton = screen.getByText('create_wallet.button_create')
await user.click(createWalletButton)
})
const createWalletButton = screen.getByText('create_wallet.button_create')
await user.click(createWalletButton)

await act(async () => {
const revealToggle = await screen.findByText('create_wallet.confirmation_toggle_reveal_info')
await user.click(revealToggle)
const revealToggle = await screen.findByText('create_wallet.confirmation_toggle_reveal_info')
await user.click(revealToggle)

const confirmToggle = screen.getByText('create_wallet.confirmation_toggle_info_written_down')
await user.click(confirmToggle)
const confirmToggle = screen.getByText('create_wallet.confirmation_toggle_info_written_down')
await user.click(confirmToggle)

const nextButton = screen.getByText('create_wallet.next_button')
await user.click(nextButton)
})
const nextButton = screen.getByText('create_wallet.next_button')
await user.click(nextButton)

expect(screen.getByText('create_wallet.skip_button')).toBeVisible()
expect(screen.getByText('create_wallet.back_button')).toBeVisible()
Expand Down
46 changes: 22 additions & 24 deletions src/components/Wallet.test.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
import { BrowserRouter } from 'react-router-dom'
import { render, screen, waitFor, act } from '@testing-library/react'
import { render, screen, act } from '@testing-library/react'
import user from '@testing-library/user-event'
import * as apiMock from '../libs/JmWalletApi'
import { I18nextProvider } from 'react-i18next'
import i18n from '../i18n/testConfig'
import { walletDisplayName } from '../utils'
import * as apiMock from '../libs/JmWalletApi'

import Wallet, { WalletProps } from './Wallet'

Expand All @@ -28,16 +30,18 @@ describe('<Wallet />', () => {
coinjoinInProgress = false,
}: WalletProps) => {
render(
<BrowserRouter>
<Wallet
walletFileName={walletFileName}
lockWallet={lockWallet}
unlockWallet={unlockWallet}
isActive={isActive}
coinjoinInProgress={coinjoinInProgress}
makerRunning={makerRunning}
/>
</BrowserRouter>,
<I18nextProvider i18n={i18n}>
<BrowserRouter>
<Wallet
walletFileName={walletFileName}
lockWallet={lockWallet}
unlockWallet={unlockWallet}
isActive={isActive}
coinjoinInProgress={coinjoinInProgress}
makerRunning={makerRunning}
/>
</BrowserRouter>
</I18nextProvider>,
)
}

Expand Down Expand Up @@ -67,15 +71,11 @@ describe('<Wallet />', () => {
expect(screen.queryByText('wallets.wallet_preview.button_open')).not.toBeInTheDocument()
expect(screen.queryByText('wallets.wallet_preview.button_lock')).not.toBeInTheDocument()

await act(async () => {
await user.click(screen.getByPlaceholderText('wallets.wallet_preview.placeholder_password'))
await user.paste(dummyPassword)
})
await user.click(screen.getByPlaceholderText('wallets.wallet_preview.placeholder_password'))
await user.paste(dummyPassword)

await act(async () => {
const unlockWalletButton = screen.getByText('wallets.wallet_preview.button_unlock')
await user.click(unlockWalletButton)
})
const unlockWalletButton = screen.getByText('wallets.wallet_preview.button_unlock')
await user.click(unlockWalletButton)

expect(mockUnlockWallet).toHaveBeenCalledWith(dummyWalletFileName, dummyPassword)
})
Expand Down Expand Up @@ -126,10 +126,8 @@ describe('<Wallet />', () => {
expect(screen.getByText('wallets.wallet_preview.wallet_unlocked')).toBeInTheDocument()
expect(screen.getByText('wallets.wallet_preview.button_lock')).toBeInTheDocument()

await act(async () => {
const lockWalletButton = screen.getByText('wallets.wallet_preview.button_lock')
await user.click(lockWalletButton)
})
const lockWalletButton = screen.getByText('wallets.wallet_preview.button_lock')
await user.click(lockWalletButton)

expect(mockLockWallet).toHaveBeenCalledWith(dummyWalletFileName, { confirmed: false })
})
Expand Down
Loading

0 comments on commit 49cdfad

Please sign in to comment.