Total Complexity | 4 |
Complexity/F | 1 |
Lines of Code | 51 |
Function Count | 4 |
Duplicated Lines | 0 |
Ratio | 0 % |
Changes | 0 |
1 | /* eslint-env jest */ |
||
2 | import { view, set, over, lensProp } from 'ramda' |
||
3 | import { inGlobalStateLens } from './globalStateLens' |
||
4 | |||
5 | it('Gets the global state', () => { |
||
6 | const tokenLens = lensProp('token') |
||
7 | const globalState = { |
||
8 | store: { |
||
9 | state: { token: 'HET_TOKEN' } |
||
10 | } |
||
11 | } |
||
12 | |||
13 | const tokenLensInGlobal = inGlobalStateLens(tokenLens) |
||
14 | |||
15 | expect(view(tokenLensInGlobal, globalState)).toBe('HET_TOKEN') |
||
16 | }) |
||
17 | |||
18 | it('Sets in the global state', () => { |
||
19 | const tokenLens = lensProp('token') |
||
20 | const globalState = { |
||
21 | store: { |
||
22 | state: { token: 'HET_TOKEN' } |
||
23 | } |
||
24 | } |
||
25 | |||
26 | const tokenLensInGlobal = inGlobalStateLens(tokenLens) |
||
27 | |||
28 | expect(set(tokenLensInGlobal, 'NEW_TOKEN', globalState)).toStrictEqual({ |
||
29 | store: { |
||
30 | state: { token: 'NEW_TOKEN' } |
||
31 | } |
||
32 | }) |
||
33 | }) |
||
34 | |||
35 | it('Runs a function over the lens value in the global state', () => { |
||
36 | const tokenLens = lensProp('token') |
||
37 | const globalState = { |
||
38 | store: { |
||
39 | state: { token: 'HET_TOKEN' } |
||
40 | } |
||
41 | } |
||
42 | |||
43 | const tokenLensInGlobal = inGlobalStateLens(tokenLens) |
||
44 | |||
45 | expect( |
||
46 | over(tokenLensInGlobal, token => token + token, globalState) |
||
47 | ).toStrictEqual({ |
||
48 | store: { |
||
49 | state: { token: 'HET_TOKENHET_TOKEN' } |
||
50 | } |
||
51 | }) |
||
52 | }) |
||
53 |