-
Notifications
You must be signed in to change notification settings - Fork 292
/
Copy pathscene_spec.js
182 lines (135 loc) · 5.12 KB
/
scene_spec.js
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
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
import chai from 'chai';
let assert = chai.assert;
import sampleScene from './fixtures/sample-scene.json';
let nycLatLng = { lng: -73.97229, lat: 40.76456, zoom: 17 };
describe('Scene', function () {
let subject;
subject = makeScene({});
sinon.stub(subject.view, 'findVisibleTileCoordinates').returns([]);
subject.view.setView(nycLatLng);
describe('.constructor()', () => {
it('returns a new instance', () => {
assert.isTrue(subject.constructor.name === 'Scene');
});
});
describe('.load()', () => {
describe('when the scene is not loaded', () => {
beforeEach(() => {
return subject.load();
});
it('correctly sets the value of the data source', () => {
let source = subject.sources['osm'];
assert.propertyVal(source, 'max_zoom', 18);
assert.propertyVal(source, 'url', 'https://tile.mapzen.com/mapzen/vector/v1/all/{z}/{x}/{y}.json?api_key=mapzen-T3tPjn7&');
});
it('sets the initialized property', () => {
assert.isTrue(subject.initialized);
});
it('sets the container property', () => {
assert.instanceOf(subject.container, HTMLDivElement);
});
it('sets the canvas property', () => {
assert.instanceOf(subject.canvas, HTMLCanvasElement);
});
it('sets the gl property', () => {
assert.instanceOf(subject.gl, WebGLRenderingContext);
});
});
describe('loading scene from an existing object', () => {
beforeEach(() => {
subject = makeScene({ config: sampleScene });
return subject.load();
});
it('correctly sets the value of the config object', () => {
assert.equal(subject.config_source, sampleScene);
});
it('sets the initialized property', () => {
assert.isTrue(subject.initialized);
});
});
describe('when the scene is already initialized', () => {
it('handles second load() call', () => {
return subject.load().then(() => {
return subject.load();
});
});
});
});
describe('.resizeMap()', () => {
let height = 100;
let width = 200;
let devicePixelRatio = window.devicePixelRatio;
let computedHeight = Math.round(height * devicePixelRatio);
let computedWidth = Math.round(width * devicePixelRatio);
beforeEach(() => {
return subject.load().then(() => {
sinon.spy(subject.gl, 'bindFramebuffer');
sinon.spy(subject.gl, 'viewport');
// Utils.device_pixel_ratio = devicePixelRatio;
subject.resizeMap(width, height, devicePixelRatio);
});
});
afterEach(() => {
subject.gl.bindFramebuffer.restore();
subject.gl.viewport.restore();
});
it('marks the scene as dirty', () => {
assert.isTrue(subject.dirty);
});
it('sets the device size property', () => {
assert.deepEqual(subject.view.size.device, {
height: computedHeight,
width: computedWidth
});
});
it('calls the gl.bindFrameBuffer method', () => {
assert.ok(subject.gl.bindFramebuffer.called);
});
it('calls the gl.viewport method', () => {
assert.ok(subject.gl.viewport);
});
describe('-canvas.style', () => {
it('sets the height', () => {
assert.equal(subject.canvas.style.height, height + 'px');
});
it('sets the width', () => {
assert.equal(subject.canvas.style.width, width + 'px');
});
});
describe('-canvas', () => {
it('sets the height property', () => {
assert.equal(subject.canvas.height, computedHeight);
});
it('sets the width property', () => {
assert.equal(subject.canvas.width, computedWidth);
});
});
});
describe('.view.setView(lng, lat)', () => {
let {lng, lat, zoom} = nycLatLng;
beforeEach(() => {
subject.view.setView(nycLatLng);
});
it('sets the view center', () => {
assert.equal(subject.view.center.lng, lng);
assert.equal(subject.view.center.lat, lat);
});
it('sets the view zoom', () => {
assert.equal(subject.view.zoom, zoom);
});
it('marks the scene as dirty', () => {
assert.isTrue(subject.dirty);
});
});
describe('.view.setZoom(zoom)', () => {
beforeEach(() => {
subject.view.setZoom(10);
});
it('marks the scene as dirty', () => {
assert.isTrue(subject.dirty);
});
it('updates the zoom level', () => {
assert.equal(subject.view.zoom, 10);
});
});
});