UNPKG

2.41 kBTypeScriptView Raw
1import * as React from 'react';
2import ZoomControl from '../zoom-control';
3import { mountWithMap, getMapMock } from '../jest/util';
4
5describe('ZoomControl', () => {
6 const zoomIn = '#zoomIn';
7 const zoomOut = '#zoomOut';
8
9 it('should render the component', () => {
10 const wrapper = mountWithMap(<ZoomControl />, getMapMock());
11 expect(wrapper).toBeDefined();
12 });
13
14 describe('hovering over buttons', () => {
15 it('should highlight buttons on mouseover', () => {
16 const wrapper = mountWithMap(<ZoomControl />, getMapMock());
17 const getButtonStyle = (tag: string) => {
18 const style = wrapper.find(tag).props().style;
19 return style!;
20 };
21
22 expect(getButtonStyle(zoomIn).opacity).toBe(0.95);
23 expect(getButtonStyle(zoomOut).opacity).toBe(0.95);
24
25 wrapper.find(zoomIn).simulate('mouseover');
26
27 expect(getButtonStyle(zoomIn).opacity).toBe(1);
28 expect(getButtonStyle(zoomOut).opacity).toBe(0.95);
29
30 wrapper.find(zoomOut).simulate('mouseover');
31 expect(getButtonStyle(zoomIn).opacity).toBe(0.95);
32 expect(getButtonStyle(zoomOut).opacity).toBe(1);
33
34 wrapper.find(zoomIn).simulate('mouseover');
35 expect(getButtonStyle(zoomIn).opacity).toBe(1);
36 expect(getButtonStyle(zoomOut).opacity).toBe(0.95);
37 });
38
39 it('should remove highlight from plus button on mouseout', () => {
40 const wrapper = mountWithMap(<ZoomControl />, getMapMock());
41 const getButtonStyle = (tag: string) => {
42 const style = wrapper.find(tag).props().style;
43 return style!;
44 };
45
46 expect(getButtonStyle(zoomIn).opacity).toBe(0.95);
47
48 wrapper.find(zoomIn).simulate('mouseover');
49 expect(getButtonStyle(zoomIn).opacity).toBe(1);
50
51 wrapper.find(zoomOut).simulate('mouseout');
52 expect(getButtonStyle(zoomIn).opacity).toBe(0.95);
53 });
54
55 it('should remove highlight from minus button on mouseout', () => {
56 const wrapper = mountWithMap(<ZoomControl />, getMapMock());
57 const getButtonStyle = (tag: string) => {
58 const style = wrapper.find(tag).props().style;
59 return style!;
60 };
61
62 expect(getButtonStyle(zoomOut).opacity).toBe(0.95);
63
64 wrapper.find(zoomOut).simulate('mouseover');
65 expect(getButtonStyle(zoomOut).opacity).toBe(1);
66
67 wrapper.find(zoomOut).simulate('mouseout');
68 expect(getButtonStyle(zoomOut).opacity).toBe(0.95);
69 });
70 });
71});