Skip to content

Commit

Permalink
chore: tests for commissionbounds and delegationlists
Browse files Browse the repository at this point in the history
  • Loading branch information
Esya committed May 21, 2021
1 parent 50b0ee5 commit 3362b14
Show file tree
Hide file tree
Showing 19 changed files with 2,190 additions and 183 deletions.
2 changes: 1 addition & 1 deletion src/app/__tests__/__snapshots__/index.test.tsx.snap
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ exports[`<App /> should render and match the snapshot 1`] = `
<TransitionRoute
component={[Function]}
exact={true}
path="/stake/:address"
path="/account/:address/stake"
/>
<TransitionRoute
component={[Function]}
Expand Down
8 changes: 0 additions & 8 deletions src/app/components/PageWrapper/index.ts

This file was deleted.

3 changes: 1 addition & 2 deletions src/app/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ import { AccountPage } from './pages/AccountPage'
import { CreateWalletPage } from './pages/CreateWalletPage'
import { HomePage } from './pages/HomePage'
import { OpenWalletPage } from './pages/OpenWalletPage'
import { StakingPage } from './pages/StakingPage'

const AppMain = styled(Main)`
position: relative;
Expand All @@ -49,7 +48,7 @@ export function App() {
<TransitionRoute exact path="/" component={HomePage} />
<TransitionRoute exact path="/create-wallet" component={CreateWalletPage} />
<TransitionRoute path="/open-wallet" component={OpenWalletPage} />
<TransitionRoute exact path="/stake/:address" component={StakingPage} />
<TransitionRoute exact path="/account/:address/stake" component={AccountPage} />
<TransitionRoute path="/account/:address" component={AccountPage} />
</Switch>
</TransitionGroup>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,282 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`<CommissionBounds /> should match snapshot when empty 1`] = `
Object {
"asFragment": [Function],
"baseElement": <body>
<div>
No bounds set (0% - 0%)
</div>
</body>,
"container": <div>
No bounds set (0% - 0%)
</div>,
"debug": [Function],
"findAllByAltText": [Function],
"findAllByDisplayValue": [Function],
"findAllByLabelText": [Function],
"findAllByPlaceholderText": [Function],
"findAllByRole": [Function],
"findAllByTestId": [Function],
"findAllByText": [Function],
"findAllByTitle": [Function],
"findByAltText": [Function],
"findByDisplayValue": [Function],
"findByLabelText": [Function],
"findByPlaceholderText": [Function],
"findByRole": [Function],
"findByTestId": [Function],
"findByText": [Function],
"findByTitle": [Function],
"getAllByAltText": [Function],
"getAllByDisplayValue": [Function],
"getAllByLabelText": [Function],
"getAllByPlaceholderText": [Function],
"getAllByRole": [Function],
"getAllByTestId": [Function],
"getAllByText": [Function],
"getAllByTitle": [Function],
"getByAltText": [Function],
"getByDisplayValue": [Function],
"getByLabelText": [Function],
"getByPlaceholderText": [Function],
"getByRole": [Function],
"getByTestId": [Function],
"getByText": [Function],
"getByTitle": [Function],
"queryAllByAltText": [Function],
"queryAllByDisplayValue": [Function],
"queryAllByLabelText": [Function],
"queryAllByPlaceholderText": [Function],
"queryAllByRole": [Function],
"queryAllByTestId": [Function],
"queryAllByText": [Function],
"queryAllByTitle": [Function],
"queryByAltText": [Function],
"queryByDisplayValue": [Function],
"queryByLabelText": [Function],
"queryByPlaceholderText": [Function],
"queryByRole": [Function],
"queryByTestId": [Function],
"queryByText": [Function],
"queryByTitle": [Function],
"rerender": [Function],
"unmount": [Function],
}
`;

exports[`<CommissionBounds /> should match snapshot with active bounds 1`] = `
Object {
"asFragment": [Function],
"baseElement": <body>
.c0 {
display: -webkit-box;
display: -webkit-flex;
display: -ms-flexbox;
display: flex;
box-sizing: border-box;
max-width: 100%;
min-width: 0;
min-height: 0;
-webkit-flex-direction: column;
-ms-flex-direction: column;
flex-direction: column;
}
.c1 {
font-size: 18px;
line-height: 24px;
}
.c2 {
font-size: 18px;
line-height: 24px;
font-weight: bold;
}
<div>
<div
class="c0"
>
<span
class="c1"
>
<span
class="c2"
>
10% - 20%
</span>
at current Epoch 50
</span>
</div>
</div>
</body>,
"container": <div>
<div
class="StyledBox-sc-13pk1d4-0 kUTqHn"
>
<span
class="StyledText-sc-1sadyjn-0 fxbXHC"
>
<span
class="StyledText-sc-1sadyjn-0 onXHw"
>
10% - 20%
</span>
at current Epoch 50
</span>
</div>
</div>,
"debug": [Function],
"findAllByAltText": [Function],
"findAllByDisplayValue": [Function],
"findAllByLabelText": [Function],
"findAllByPlaceholderText": [Function],
"findAllByRole": [Function],
"findAllByTestId": [Function],
"findAllByText": [Function],
"findAllByTitle": [Function],
"findByAltText": [Function],
"findByDisplayValue": [Function],
"findByLabelText": [Function],
"findByPlaceholderText": [Function],
"findByRole": [Function],
"findByTestId": [Function],
"findByText": [Function],
"findByTitle": [Function],
"getAllByAltText": [Function],
"getAllByDisplayValue": [Function],
"getAllByLabelText": [Function],
"getAllByPlaceholderText": [Function],
"getAllByRole": [Function],
"getAllByTestId": [Function],
"getAllByText": [Function],
"getAllByTitle": [Function],
"getByAltText": [Function],
"getByDisplayValue": [Function],
"getByLabelText": [Function],
"getByPlaceholderText": [Function],
"getByRole": [Function],
"getByTestId": [Function],
"getByText": [Function],
"getByTitle": [Function],
"queryAllByAltText": [Function],
"queryAllByDisplayValue": [Function],
"queryAllByLabelText": [Function],
"queryAllByPlaceholderText": [Function],
"queryAllByRole": [Function],
"queryAllByTestId": [Function],
"queryAllByText": [Function],
"queryAllByTitle": [Function],
"queryByAltText": [Function],
"queryByDisplayValue": [Function],
"queryByLabelText": [Function],
"queryByPlaceholderText": [Function],
"queryByRole": [Function],
"queryByTestId": [Function],
"queryByText": [Function],
"queryByTitle": [Function],
"rerender": [Function],
"unmount": [Function],
}
`;

exports[`<CommissionBounds /> should match snapshot with provided bounds 1`] = `
Object {
"asFragment": [Function],
"baseElement": <body>
.c0 {
display: -webkit-box;
display: -webkit-flex;
display: -ms-flexbox;
display: flex;
box-sizing: border-box;
max-width: 100%;
min-width: 0;
min-height: 0;
-webkit-flex-direction: column;
-ms-flex-direction: column;
flex-direction: column;
}
.c1 {
font-size: 18px;
line-height: 24px;
}
<div>
<div
class="c0"
>
<span
class="c1"
>
10% - 20% starting from Epoch 0
</span>
</div>
</div>
</body>,
"container": <div>
<div
class="StyledBox-sc-13pk1d4-0 kUTqHn"
>
<span
class="StyledText-sc-1sadyjn-0 fxbXHC"
>
10% - 20% starting from Epoch 0
</span>
</div>
</div>,
"debug": [Function],
"findAllByAltText": [Function],
"findAllByDisplayValue": [Function],
"findAllByLabelText": [Function],
"findAllByPlaceholderText": [Function],
"findAllByRole": [Function],
"findAllByTestId": [Function],
"findAllByText": [Function],
"findAllByTitle": [Function],
"findByAltText": [Function],
"findByDisplayValue": [Function],
"findByLabelText": [Function],
"findByPlaceholderText": [Function],
"findByRole": [Function],
"findByTestId": [Function],
"findByText": [Function],
"findByTitle": [Function],
"getAllByAltText": [Function],
"getAllByDisplayValue": [Function],
"getAllByLabelText": [Function],
"getAllByPlaceholderText": [Function],
"getAllByRole": [Function],
"getAllByTestId": [Function],
"getAllByText": [Function],
"getAllByTitle": [Function],
"getByAltText": [Function],
"getByDisplayValue": [Function],
"getByLabelText": [Function],
"getByPlaceholderText": [Function],
"getByRole": [Function],
"getByTestId": [Function],
"getByText": [Function],
"getByTitle": [Function],
"queryAllByAltText": [Function],
"queryAllByDisplayValue": [Function],
"queryAllByLabelText": [Function],
"queryAllByPlaceholderText": [Function],
"queryAllByRole": [Function],
"queryAllByTestId": [Function],
"queryAllByText": [Function],
"queryAllByTitle": [Function],
"queryByAltText": [Function],
"queryByDisplayValue": [Function],
"queryByLabelText": [Function],
"queryByPlaceholderText": [Function],
"queryByRole": [Function],
"queryByTestId": [Function],
"queryByText": [Function],
"queryByTitle": [Function],
"rerender": [Function],
"unmount": [Function],
}
`;
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
import { render } from '@testing-library/react'
import { networkActions } from 'app/state/network'
import { NetworkState } from 'app/state/network/types'
import { CommissionBounds as ICommissionBounds } from 'app/state/staking/types'
import * as React from 'react'
import { Provider } from 'react-redux'
import { configureAppStore } from 'store/configureStore'

import { CommissionBounds } from '..'

const renderComponent = (store, bounds?: ICommissionBounds[]) =>
render(
<Provider store={store}>
<CommissionBounds bounds={bounds} />
</Provider>,
)

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

beforeEach(() => {
store = configureAppStore()
})

it('should match snapshot when empty', () => {
const component = renderComponent(store)
expect(component).toMatchSnapshot()
})

it('should match snapshot with provided bounds', () => {
const component = renderComponent(store, [{ epochStart: 0, lower: 0.1, upper: 0.2, epochEnd: 100 }])
expect(component).toMatchSnapshot()
})

it('should match snapshot with active bounds', () => {
store = configureAppStore()
const component = renderComponent(store, [{ epochStart: 0, lower: 0.1, upper: 0.2, epochEnd: 100 }])
store.dispatch(networkActions.networkSelected({ epoch: 50 } as NetworkState))
expect(component).toMatchSnapshot()
})
})
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
* CommisssionBounds
*
*/
import { useNetworkSlice } from 'app/state/network'
import { selectEpoch } from 'app/state/network/selectors'
import { CommissionBounds as ICommissionBounds } from 'app/state/staking/types'
import { Box, Text } from 'grommet'
Expand All @@ -15,6 +16,7 @@ interface CommissionBoundProps {
}

const CommissionBound = memo((props: CommissionBoundProps) => {
useNetworkSlice()
const { t } = useTranslation()
const epoch = useSelector(selectEpoch)

Expand Down Expand Up @@ -53,7 +55,7 @@ export const CommissionBounds = memo((props: Props) => {
const { t } = useTranslation()

if (props.bounds && props.bounds.length > 0) {
const items = props.bounds.map(b => <CommissionBound bound={b} />)
const items = props.bounds.map((b, i) => <CommissionBound bound={b} key={i} />)
return <>{items}</>
} else {
return <>{t('validator.boundsNotSet', 'No bounds set (0% - 0%)')}</>
Expand Down
Loading

0 comments on commit 3362b14

Please sign in to comment.