Skip to content

Commit

Permalink
fix test/linting/typescript
Browse files Browse the repository at this point in the history
  • Loading branch information
ckniffen committed Dec 17, 2024
1 parent 10f822d commit 8f4ac3a
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 42 deletions.
4 changes: 1 addition & 3 deletions src/containers/Token/DEXPairs/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -169,9 +169,7 @@ export const DEXPairs = ({ accountId, currency }: DexPairsProps) => {
<table>
<thead>
<tr>
<th className="pair-header" className="left-align">
{t('pair')}
</th>
<th className="pair-header">{t('pair')}</th>
<th>{t('issuer')}</th>
<th className="stats-header">{t('offer_range')}</th>
</tr>
Expand Down
3 changes: 1 addition & 2 deletions src/containers/Token/TokenHeader/index.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { useTranslation } from 'react-i18next'
import { Loader } from '../../shared/components/Loader'
import './styles.scss'
import { localizeNumber, formatLargeNumber } from '../../shared/utils'
import Currency from '../../shared/components/Currency'
Expand Down Expand Up @@ -130,7 +129,7 @@ export const TokenHeader = ({
CURRENCY_OPTIONS,
)
const obligationsBalance = formatLargeNumber(
Number.parseFloat(obligations || 0),
Number.parseFloat(obligations || '0'),
)

return (
Expand Down
14 changes: 8 additions & 6 deletions src/containers/Token/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ const Page: FC<PropsWithChildren<{ accountId: string }>> = ({
</div>
)

export const Token: FC<{ error: string }> = () => {
export const Token = () => {
const rippledSocket = useContext(SocketContext)
const { trackScreenLoaded } = useAnalytics()
const { token = '' } = useRouteParams(TOKEN_ROUTE)
Expand Down Expand Up @@ -88,11 +88,13 @@ export const Token: FC<{ error: string }> = () => {
{isTokenDataLoading ? (
<Loader />
) : (
<TokenHeader
accountId={accountId}
currency={currency}
data={tokenData}
/>
tokenData && (
<TokenHeader
accountId={accountId}
currency={currency}
data={tokenData}
/>
)
)}
{accountId && tokenData && IS_MAINNET && (
<DEXPairs accountId={accountId} currency={currency} />
Expand Down
54 changes: 23 additions & 31 deletions src/containers/Token/test/index.test.tsx
Original file line number Diff line number Diff line change
@@ -1,33 +1,32 @@
import { mount } from 'enzyme'
import configureMockStore from 'redux-mock-store'
import thunk from 'redux-thunk'
import { Provider } from 'react-redux'
import { Route } from 'react-router-dom'
import { initialState } from '../../../rootReducer'
import i18n from '../../../i18n/testConfig'
import Token from '../index'
import TokenHeader from '../TokenHeader'
import { Token } from '../index'
import { TokenHeader } from '../TokenHeader'
import { TokenTransactionTable } from '../TokenTransactionTable'
import mockAccountState from '../../Accounts/test/mockAccountState.json'
import { QuickHarness } from '../../test/utils'
import { flushPromises, QuickHarness } from '../../test/utils'
import { TOKEN_ROUTE } from '../../App/routes'
import mockAccount from '../../Accounts/test/mockAccountState.json'
import Mock = jest.Mock
import { getToken } from '../../../rippled'

jest.mock('../../../rippled', () => ({
__esModule: true,
getToken: jest.fn(),
}))

describe('Token container', () => {
const TEST_ACCOUNT_ID = 'rTEST_ACCOUNT'

const middlewares = [thunk]
const mockStore = configureMockStore(middlewares)
const createWrapper = (state = {}) => {
const store = mockStore({ ...initialState, ...state })
const createWrapper = (getAccountImpl = () => new Promise(() => {})) => {
;(getToken as Mock).mockImplementation(getAccountImpl)
return mount(
<Provider store={store}>
<QuickHarness
i18n={i18n}
initialEntries={[`/token/USD.${TEST_ACCOUNT_ID}`]}
>
<Route path={TOKEN_ROUTE.path} element={<Token />} />
</QuickHarness>
</Provider>,
<QuickHarness
i18n={i18n}
initialEntries={[`/token/USD.${TEST_ACCOUNT_ID}`]}
>
<Route path={TOKEN_ROUTE.path} element={<Token />} />
</QuickHarness>,
)
}

Expand All @@ -36,17 +35,10 @@ describe('Token container', () => {
wrapper.unmount()
})

it('renders static parts', () => {
const state = {
...initialState,
accountHeader: {
loading: false,
error: null,
data: mockAccountState,
},
}

const wrapper = createWrapper(state)
it('renders static parts', async () => {
const wrapper = createWrapper(() => Promise.resolve(mockAccount))
await flushPromises()
wrapper.update()
expect(wrapper.find(TokenHeader).length).toBe(1)
expect(wrapper.find(TokenTransactionTable).length).toBe(1)
wrapper.unmount()
Expand Down

0 comments on commit 8f4ac3a

Please sign in to comment.