test/utils/utils.test.js   A
last analyzed

Complexity

Total Complexity 12
Complexity/F 1

Size

Lines of Code 66
Function Count 12

Duplication

Duplicated Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
wmc 12
eloc 42
mnd 0
bc 0
fnc 12
dl 0
loc 66
rs 10
bpm 0
cpm 1
noi 0
c 0
b 0
f 0
1
import L from 'leaflet';
2
import marker2x from 'leaflet/dist/images/marker-icon-2x.png';
3
import marker from 'leaflet/dist/images/marker-icon.png';
4
import markerShadow from 'leaflet/dist/images/marker-shadow.png';
5
import { determineOrderDir, fixLeafletIcons, rangeOf } from '../../src/utils/utils';
6
7
describe('utils', () => {
8
  describe('determineOrderDir', () => {
9
    it('returns ASC when current order field and selected field are different', () => {
10
      expect(determineOrderDir('foo', 'bar')).toEqual('ASC');
11
      expect(determineOrderDir('bar', 'foo')).toEqual('ASC');
12
    });
13
14
    it('returns ASC when no current order dir is provided', () => {
15
      expect(determineOrderDir('foo', 'foo')).toEqual('ASC');
16
      expect(determineOrderDir('bar', 'bar')).toEqual('ASC');
17
    });
18
19
    it('returns DESC when current order field and selected field are equal and current order dir is ASC', () => {
20
      expect(determineOrderDir('foo', 'foo', 'ASC')).toEqual('DESC');
21
      expect(determineOrderDir('bar', 'bar', 'ASC')).toEqual('DESC');
22
    });
23
24
    it('returns undefined when current order field and selected field are equal and current order dir is DESC', () => {
25
      expect(determineOrderDir('foo', 'foo', 'DESC')).toBeUndefined();
26
      expect(determineOrderDir('bar', 'bar', 'DESC')).toBeUndefined();
27
    });
28
  });
29
30
  describe('fixLeafletIcons', () => {
31
    it('updates icons used by leaflet', () => {
32
      fixLeafletIcons();
33
34
      const { iconRetinaUrl, iconUrl, shadowUrl } = L.Icon.Default.prototype.options;
35
36
      expect(iconRetinaUrl).toEqual(marker2x);
37
      expect(iconUrl).toEqual(marker);
38
      expect(shadowUrl).toEqual(markerShadow);
39
    });
40
  });
41
42
  describe('rangeOf', () => {
43
    const func = (i) => `result_${i}`;
44
    const size = 5;
45
46
    it('builds a range of specified size invike provided function', () => {
47
      expect(rangeOf(size, func)).toEqual([
48
        'result_1',
49
        'result_2',
50
        'result_3',
51
        'result_4',
52
        'result_5',
53
      ]);
54
    });
55
56
    it('builds a range starting at provided pos', () => {
57
      const startAt = 3;
58
59
      expect(rangeOf(size, func, startAt)).toEqual([
60
        'result_3',
61
        'result_4',
62
        'result_5',
63
      ]);
64
    });
65
  });
66
});
67