9 changed files with 215 additions and 47 deletions
@ -0,0 +1,21 @@ |
|||||
|
import React from 'react' |
||||
|
import { Provider } from 'react-redux' |
||||
|
import renderer from 'react-test-renderer' |
||||
|
import { ThemeProvider } from 'styled-components' |
||||
|
import createHistory from 'history/createHashHistory' |
||||
|
|
||||
|
import createStore from 'renderer/createStore' |
||||
|
|
||||
|
import theme from 'styles/theme' |
||||
|
|
||||
|
export default function render(component, state) { |
||||
|
const history = createHistory() |
||||
|
const store = createStore(history, state) |
||||
|
return renderer |
||||
|
.create( |
||||
|
<Provider store={store}> |
||||
|
<ThemeProvider theme={theme}>{component}</ThemeProvider> |
||||
|
</Provider>, |
||||
|
) |
||||
|
.toJSON() |
||||
|
} |
@ -0,0 +1,71 @@ |
|||||
|
// @flow
|
||||
|
|
||||
|
import React from 'react' |
||||
|
import { getDefaultUnitByCoinType } from '@ledgerhq/currencies' |
||||
|
|
||||
|
import render from '__mocks__/render' |
||||
|
import CounterValue from '..' |
||||
|
|
||||
|
describe('components', () => { |
||||
|
describe('CounterValue', () => { |
||||
|
it('basic', () => { |
||||
|
const state = { counterValues: { BTC: { USD: { latest: 10e2 } } } } |
||||
|
const unit = getDefaultUnitByCoinType(1) |
||||
|
const component = <CounterValue ticker="BTC" unit={unit} value={1} /> |
||||
|
const tree = render(component, state) |
||||
|
expect(tree).toMatchSnapshot() |
||||
|
}) |
||||
|
|
||||
|
it('specifying ticker different from default', () => { |
||||
|
const state = { counterValues: { LOL: { USD: { latest: 5e2 } } } } |
||||
|
const unit = getDefaultUnitByCoinType(1) |
||||
|
const component = <CounterValue ticker="LOL" unit={unit} value={1} /> |
||||
|
const tree = render(component, state) |
||||
|
expect(tree).toMatchSnapshot() |
||||
|
}) |
||||
|
|
||||
|
it('using countervalue different from default', () => { |
||||
|
const state = { |
||||
|
counterValues: { BTC: { EUR: { latest: 42 } } }, |
||||
|
settings: { |
||||
|
counterValue: 'EUR', |
||||
|
}, |
||||
|
} |
||||
|
const unit = getDefaultUnitByCoinType(1) |
||||
|
const component = <CounterValue ticker="BTC" unit={unit} value={1} /> |
||||
|
const tree = render(component, state) |
||||
|
expect(tree).toMatchSnapshot() |
||||
|
}) |
||||
|
|
||||
|
it('without countervalues populated', () => { |
||||
|
const state = { counterValues: {} } |
||||
|
const unit = getDefaultUnitByCoinType(1) |
||||
|
const component = <CounterValue ticker="BTC" unit={unit} value={1} /> |
||||
|
const tree = render(component, state) |
||||
|
expect(tree).toMatchSnapshot() |
||||
|
}) |
||||
|
|
||||
|
it('with time travel whith date in countervalues', () => { |
||||
|
const state = { counterValues: { BTC: { USD: { '2018-01-01': 20e2 } } } } |
||||
|
const unit = getDefaultUnitByCoinType(1) |
||||
|
|
||||
|
const date = new Date('2018-01-01') |
||||
|
const component = <CounterValue ticker="BTC" unit={unit} value={1} date={date} /> |
||||
|
const tree = render(component, state) |
||||
|
expect(tree).toMatchSnapshot() |
||||
|
}) |
||||
|
|
||||
|
it('with time travel whith date not in countervalues', () => { |
||||
|
const state = { counterValues: { BTC: { USD: { '2018-01-01': 20e2 } } } } |
||||
|
const unit = getDefaultUnitByCoinType(1) |
||||
|
|
||||
|
const date = new Date('2018-01-02') |
||||
|
const component = <CounterValue ticker="BTC" unit={unit} value={1} date={date} /> |
||||
|
const tree = render(component, state) |
||||
|
|
||||
|
// TODO: actually it returns 0 when date is not in countervalues
|
||||
|
// do we want to use closest past value instead?
|
||||
|
expect(tree).toMatchSnapshot() |
||||
|
}) |
||||
|
}) |
||||
|
}) |
@ -0,0 +1,55 @@ |
|||||
|
// Jest Snapshot v1, https://goo.gl/fbAQLP |
||||
|
|
||||
|
exports[`components CounterValue basic 1`] = ` |
||||
|
<span |
||||
|
className="s1c17x4y-0 fJKscS s8vzclq-0 hjqlvj" |
||||
|
color="#66be54" |
||||
|
> |
||||
|
+ USD 10.00 |
||||
|
</span> |
||||
|
`; |
||||
|
|
||||
|
exports[`components CounterValue specifying ticker different from default 1`] = ` |
||||
|
<span |
||||
|
className="s1c17x4y-0 fJKscS s8vzclq-0 hjqlvj" |
||||
|
color="#66be54" |
||||
|
> |
||||
|
+ USD 5.00 |
||||
|
</span> |
||||
|
`; |
||||
|
|
||||
|
exports[`components CounterValue using countervalue different from default 1`] = ` |
||||
|
<span |
||||
|
className="s1c17x4y-0 fJKscS s8vzclq-0 hjqlvj" |
||||
|
color="#66be54" |
||||
|
> |
||||
|
+ EUR 0.42 |
||||
|
</span> |
||||
|
`; |
||||
|
|
||||
|
exports[`components CounterValue with time travel whith date in countervalues 1`] = ` |
||||
|
<span |
||||
|
className="s1c17x4y-0 fJKscS s8vzclq-0 hjqlvj" |
||||
|
color="#66be54" |
||||
|
> |
||||
|
+ USD 20.00 |
||||
|
</span> |
||||
|
`; |
||||
|
|
||||
|
exports[`components CounterValue with time travel whith date not in countervalues 1`] = ` |
||||
|
<span |
||||
|
className="s1c17x4y-0 fJKscS s8vzclq-0 hjqlvj" |
||||
|
color="#66be54" |
||||
|
> |
||||
|
+ USD 0.00 |
||||
|
</span> |
||||
|
`; |
||||
|
|
||||
|
exports[`components CounterValue without countervalues populated 1`] = ` |
||||
|
<span |
||||
|
className="s1c17x4y-0 fJKscS s8vzclq-0 hjqlvj" |
||||
|
color="#66be54" |
||||
|
> |
||||
|
+ USD 0.00 |
||||
|
</span> |
||||
|
`; |
@ -1,9 +0,0 @@ |
|||||
import React from 'react' |
|
||||
import renderer from 'react-test-renderer' |
|
||||
import { ThemeProvider } from 'styled-components' |
|
||||
|
|
||||
import theme from 'styles/theme' |
|
||||
|
|
||||
export function render(component) { |
|
||||
return renderer.create(<ThemeProvider theme={theme}>{component}</ThemeProvider>).toJSON() |
|
||||
} |
|
Loading…
Reference in new issue