|
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
|
|
|
|