Skip to content

Commit

Permalink
Update tests
Browse files Browse the repository at this point in the history
  • Loading branch information
buberdds committed Sep 26, 2024
1 parent 0cd483c commit 76f90de
Show file tree
Hide file tree
Showing 14 changed files with 86 additions and 48 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -316,14 +316,16 @@ exports[`<AddEscrowForm /> should match snapshot 1`] = `
>
<span
class="c5"
/>
>
TEST
</span>
</div>
<input
autocomplete="off"
class="c6"
data-testid="amount"
id="amount-id"
min="0"
min="100"
name="amount"
placeholder="common.amount"
required=""
Expand Down Expand Up @@ -356,7 +358,7 @@ exports[`<AddEscrowForm /> should match snapshot 1`] = `
class="notranslate"
translate="no"
>
TEST
</span>
</span>
</span>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -435,7 +435,9 @@ exports[`<ReclaimEscrowForm /> should match snapshot 1`] = `
>
<span
class="c5"
/>
>
TEST
</span>
</div>
<input
autocomplete="off"
Expand Down Expand Up @@ -476,7 +478,7 @@ exports[`<ReclaimEscrowForm /> should match snapshot 1`] = `
class="notranslate"
translate="no"
>
TEST
</span>
</span>
</span>
Expand Down
32 changes: 7 additions & 25 deletions src/app/components/TimeToEpoch/__tests__/index.test.tsx
Original file line number Diff line number Diff line change
@@ -1,34 +1,16 @@
import * as React from 'react'
import { render } from '@testing-library/react'
import { Provider } from 'react-redux'
import { configureAppStore } from 'store/configureStore'
import { NetworkState } from 'app/state/network/types'

import { TimeToEpoch } from '..'

const renderComponent = (store: any, epoch: number) =>
render(
<Provider store={store}>
<TimeToEpoch epoch={epoch} />
</Provider>,
)
const renderComponent = (currentEpoch: number, epoch: number) =>
render(<TimeToEpoch currentEpoch={currentEpoch} epoch={epoch} />)

describe('<TimeToEpoch />', () => {
let store: ReturnType<typeof configureAppStore>

beforeEach(() => {
store = configureAppStore({
network: {
epoch: 10000,
} as NetworkState,
})
})

it('should estimate debonding times', () => {
expect(renderComponent(store, 10336).container.textContent).toEqual('in 14 days')
expect(renderComponent(store, 10306).container.textContent).toEqual('in 13 days')
expect(renderComponent(store, 10086).container.textContent).toEqual('in 4 days')
expect(renderComponent(store, 10047).container.textContent).toEqual('in 47 hours')
expect(renderComponent(store, 10001).container.textContent).toEqual('in 1 hour')
expect(renderComponent(10000, 10336).container.textContent).toEqual('in 14 days')
expect(renderComponent(10000, 10306).container.textContent).toEqual('in 13 days')
expect(renderComponent(10000, 10086).container.textContent).toEqual('in 4 days')
expect(renderComponent(10000, 10047).container.textContent).toEqual('in 47 hours')
expect(renderComponent(10000, 10001).container.textContent).toEqual('in 1 hour')
})
})
Original file line number Diff line number Diff line change
Expand Up @@ -531,7 +531,7 @@ exports[`<Account /> should match snapshot 1`] = `
class="notranslate"
translate="no"
>
TEST
</span>
</span>
</span>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -750,7 +750,7 @@ exports[`<AccountSelector /> should match snapshot 1`] = `
class="notranslate"
translate="no"
>
TEST
</span>
</span>
</span>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -966,7 +966,7 @@ exports[`<AccountPage /> should match snapshot 1`] = `
class="notranslate"
translate="no"
>
TEST
</span>
</span>
</span>
Expand All @@ -989,7 +989,7 @@ exports[`<AccountPage /> should match snapshot 1`] = `
class="notranslate"
translate="no"
>
TEST
</span>
</span>
</span>
Expand All @@ -1013,7 +1013,7 @@ exports[`<AccountPage /> should match snapshot 1`] = `
class="notranslate"
translate="no"
>
TEST
</span>
</span>
</span>
Expand All @@ -1036,7 +1036,7 @@ exports[`<AccountPage /> should match snapshot 1`] = `
class="notranslate"
translate="no"
>
TEST
</span>
</span>
</span>
Expand Down Expand Up @@ -1123,7 +1123,9 @@ exports[`<AccountPage /> should match snapshot 1`] = `
>
<span
class="c15"
/>
>
TEST
</span>
</div>
<input
autocomplete="off"
Expand Down Expand Up @@ -1185,4 +1187,4 @@ exports[`<AccountPage /> should match snapshot 1`] = `
</div>
`;

exports[`<AccountPage /> with missing delegations 1`] = `"Total-Available100.0 Staked-Debonding-"`;
exports[`<AccountPage /> with missing delegations 1`] = `"Total-Available100.0 TEST Staked-Debonding-"`;
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,11 @@ describe('<CommissionBounds />', () => {
let store: ReturnType<typeof configureAppStore>

beforeEach(() => {
store = configureAppStore()
store = configureAppStore({
network: {
epoch: 0,
} as NetworkState,
})
})

it('should match snapshot when empty', () => {
Expand All @@ -43,7 +47,7 @@ describe('<CommissionBounds />', () => {
store = configureAppStore()
const component = renderComponent(store, [{ epochStart: 0, lower: 0.1, upper: 0.2, epochEnd: 100 }])
act(() => {
store.dispatch(networkActions.networkSelected({ epoch: 50 } as NetworkState))
store.dispatch(networkActions.setEpoch(50))
})
expect(component.baseElement).toMatchSnapshot()
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ interface CommissionBoundProps {
const CommissionBound = memo((props: CommissionBoundProps) => {
const { t } = useTranslation()
const epoch = useSelector(selectEpoch)
if (!epoch) {
if (typeof epoch !== 'number') {
return null
}
const bound = props.bound
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { Provider } from 'react-redux'
import { DebondingDelegationList } from '../DebondingDelegationList'
import { configureAppStore } from 'store/configureStore'
import { stakingActions } from 'app/state/staking'
import { NetworkState } from '../../../../../../app/state/network/types'
import { ThemeProvider } from '../../../../../../styles/theme/ThemeProvider'
import { MemoryRouter } from 'react-router-dom'

Expand All @@ -25,7 +26,12 @@ describe('<DebondingDelegationList />', () => {
let store: ReturnType<typeof configureAppStore>

beforeEach(() => {
store = configureAppStore()
store = configureAppStore({
network: {
ticker: 'TEST',
epoch: 4,
} as NetworkState,
})
})

it('should match snapshot', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -608,7 +608,7 @@ exports[`<ActiveDelegationList /> should match snapshot 1`] = `
class="notranslate"
translate="no"
>
TEST
</span>
</span>
</span>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -594,7 +594,7 @@ exports[`<DebondingDelegationList /> should match snapshot 1`] = `
class="notranslate"
translate="no"
>
TEST
</span>
</span>
</span>
Expand Down
38 changes: 37 additions & 1 deletion src/app/state/network/saga.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { expectSaga, testSaga } from 'redux-saga-test-plan'
import * as matchers from 'redux-saga-test-plan/matchers'
import { getChainContext, getOasisNic, networkSaga, selectNetwork } from './saga'
import { getChainContext, getEpoch, getOasisNic, networkSaga, selectNetwork } from './saga'
import { networkActions } from '.'

describe('Network Sagas', () => {
Expand Down Expand Up @@ -59,4 +59,40 @@ describe('Network Sagas', () => {
.run()
})
})

describe('getEpoch', () => {
const mockEpoch = 35337
const mockSelectedNetwork = 'testnet'
const mockNic = {
beaconGetEpoch: jest.fn().mockResolvedValue(mockEpoch),
}

it('should return existing epoch if available', () => {
return expectSaga(getEpoch)
.withState({
network: {
epoch: mockEpoch,
selectedNetwork: mockSelectedNetwork,
},
})
.returns(mockEpoch)
.run()
})

it('should fetch and return epoch when it is missing in state', () => {
return expectSaga(getEpoch)
.withState({
network: {
selectedNetwork: mockSelectedNetwork,
},
})
.provide([
[matchers.call.fn(getOasisNic), mockNic],
[matchers.call.fn(mockNic.beaconGetEpoch), mockEpoch],
])
.put(networkActions.setEpoch(mockEpoch))
.returns(mockEpoch)
.run()
})
})
})
6 changes: 5 additions & 1 deletion src/app/state/staking/saga.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,11 @@ describe('Staking Sagas', () => {
nic.stakingAccount.mockResolvedValue({})

return expectSaga(stakingSaga)
.withState({})
.withState({
network: {
epoch: 35337,
},
})
.provide(providers)
.dispatch(stakingActions.validatorSelected('oasis1qqzz2le7nua2hvrkjrc9kc6n08ycs9a80chejmr7'))
.put.actionType(stakingActions.updateValidatorDetails.type)
Expand Down
4 changes: 2 additions & 2 deletions src/utils/__fixtures__/test-inputs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ export const privateKeyUnlockedState = {
ticker: 'ROSE',
chainContext: '',
selectedNetwork: 'mainnet',
epoch: 18372,
epoch: 0,
minimumStakingAmount: 100,
},
paraTimes: {
Expand Down Expand Up @@ -274,7 +274,7 @@ export const walletExtensionV0UnlockedState = {
chainContext: '',
ticker: 'ROSE',
selectedNetwork: 'mainnet',
epoch: 27884,
epoch: 0,
minimumStakingAmount: 100,
},
paraTimes: {
Expand Down

0 comments on commit 76f90de

Please sign in to comment.