forked from keplergl/kepler.gl
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexport-image-modal-test.js
More file actions
167 lines (141 loc) · 4.5 KB
/
Copy pathexport-image-modal-test.js
File metadata and controls
167 lines (141 loc) · 4.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
// SPDX-License-Identifier: MIT
// Copyright contributors to the kepler.gl project
import React from 'react';
import test from 'tape-catch';
import sinon from 'sinon';
import {IntlWrapper, mountWithTheme} from 'test/helpers/component-utils';
import {
ExportImageModalFactory,
ImagePreview,
appInjector,
SelectionButton
} from '@kepler.gl/components';
import {INITIAL_UI_STATE} from '@kepler.gl/reducers';
const ExportImageModal = appInjector.get(ExportImageModalFactory);
test('Components -> ExportImageModal.mount', t => {
const onUpdateImageSetting = sinon.spy();
const cleanupExportImage = () => {};
let wrapper;
t.doesNotThrow(() => {
wrapper = mountWithTheme(
<IntlWrapper>
<ExportImageModal
mapW={500}
mapH={500}
exportImage={INITIAL_UI_STATE.exportImage}
onUpdateImageSetting={onUpdateImageSetting}
cleanupExportImage={cleanupExportImage}
/>
</IntlWrapper>
);
}, 'Show not fail with props');
t.ok(onUpdateImageSetting.calledTwice, 'should call onUpdateImageSetting when mount');
t.deepEqual(onUpdateImageSetting.args, [[{exporting: true}], [{mapH: 500, mapW: 500}]]);
t.equal(wrapper.find(ImagePreview).length, 1, 'should render ImagePreview');
const ratioOpts = wrapper
.find('#export-image-modal__option_ratio')
.at(0)
.find(SelectionButton)
.map(c => c.text());
t.deepEqual(ratioOpts, ['Original Screen', '4:3', '16:9'], 'should render correct ratio options');
t.ok(
wrapper
.find('#export-image-modal__option_ratio')
.at(0)
.find(SelectionButton)
.at(0)
.props('selected'),
'first option should be selected'
);
wrapper
.find('#export-image-modal__option_ratio')
.at(0)
.find(SelectionButton)
.at(0)
.simulate('click');
t.ok(onUpdateImageSetting.calledWith({ratio: 'SCREEN'}), 'should call update ratio');
const resolutionOpts = wrapper
.find('#export-image-modal__option_resolution')
.at(0)
.find(SelectionButton)
.map(c => c.text());
t.deepEqual(resolutionOpts, ['1x', '2x', '3x', '4x', '5x'], 'should render correct resolution options');
t.ok(
wrapper
.find('#export-image-modal__option_resolution')
.at(0)
.find(SelectionButton)
.at(0)
.props('selected'),
'first option should be selected'
);
wrapper
.find('#export-image-modal__option_resolution')
.at(0)
.find(SelectionButton)
.at(1)
.simulate('click');
t.ok(onUpdateImageSetting.calledWith({resolution: 'TWO_X'}), 'should call update resolution');
t.end();
});
test('Components -> ExportImageModal.preview image', t => {
const onUpdateImageSetting = sinon.spy();
const cleanupExportImage = () => {};
const imageDataUri = 'data:image/png;base64,2i3u';
const exportImage = {
...INITIAL_UI_STATE.exportImage,
imageDataUri,
imageSize: {
scale: 1,
imageW: 500,
imageH: 500
}
};
let wrapper;
t.doesNotThrow(() => {
wrapper = mountWithTheme(
<IntlWrapper>
<ExportImageModal
mapW={500}
mapH={500}
exportImage={exportImage}
onUpdateImageSetting={onUpdateImageSetting}
cleanupExportImage={cleanupExportImage}
/>
</IntlWrapper>
);
}, 'Show not fail with exportImage.imageDataUri');
t.equal(
wrapper.find('.preview-image-placeholder').html(),
'<img class="preview-image-placeholder" src="data:image/png;base64,2i3u" alt="Map preview">',
'should render image with src'
);
t.equal(
wrapper.find('.preview-image').html(),
'<div class="preview-image"><div class="preview-image-container"><img class="preview-image-placeholder" src="data:image/png;base64,2i3u" alt="Map preview"></div></div>',
'should render preview image with src'
);
t.end();
});
test('Components -> ExportImageModal.unmount', t => {
const onUpdateImageSetting = () => {};
const cleanupExportImage = sinon.spy();
let wrapper;
t.doesNotThrow(() => {
wrapper = mountWithTheme(
<IntlWrapper>
<ExportImageModal
mapW={500}
mapH={500}
exportImage={INITIAL_UI_STATE.exportImage}
onUpdateImageSetting={onUpdateImageSetting}
cleanupExportImage={cleanupExportImage}
/>
</IntlWrapper>
);
}, 'Show not fail with props');
t.ok(cleanupExportImage.notCalled, 'should not call cleanupExportImage when mount');
wrapper.unmount();
t.ok(cleanupExportImage.calledOnce, 'should call cleanupExportImage when unmount');
t.end();
});