src/globalStateLens.test.js   A
last analyzed

Complexity

Total Complexity 4
Complexity/F 1

Size

Lines of Code 51
Function Count 4

Duplication

Duplicated Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
wmc 4
eloc 29
mnd 0
bc 0
fnc 4
dl 0
loc 51
bpm 0
cpm 1
noi 0
c 0
b 0
f 0
rs 10
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