forked from firefox-devtools/debugger
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgrip-array.js
More file actions
621 lines (489 loc) · 23.1 KB
/
Copy pathgrip-array.js
File metadata and controls
621 lines (489 loc) · 23.1 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
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at <http://mozilla.org/MPL/2.0/>. */
/* global jest */
const { shallow } = require("enzyme");
const { getRep } = require("../rep");
const GripArray = require("../grip-array");
const { MODE } = require("../constants");
const stubs = require("../stubs/grip-array");
const {
expectActorAttribute,
getSelectableInInspectorGrips,
getGripLengthBubbleText
} = require("./test-helpers");
const { maxLengthMap } = GripArray;
function shallowRenderRep(object, props = {}) {
return shallow(
GripArray.rep({
object,
...props
})
);
}
describe("GripArray - basic", () => {
const object = stubs.get("testBasic");
it("correctly selects GripArray Rep", () => {
expect(getRep(object)).toBe(GripArray.rep);
});
it("renders as expected", () => {
const renderRep = props => shallowRenderRep(object, props);
const length = getGripLengthBubbleText(object);
const defaultOutput = `Array${length} []`;
let component = renderRep({ mode: undefined });
expect(component.text()).toBe(defaultOutput);
expectActorAttribute(component, object.actor);
component = renderRep({ mode: MODE.TINY });
expect(component.text()).toBe("[]");
expectActorAttribute(component, object.actor);
component = renderRep({ mode: MODE.SHORT });
expect(component.text()).toBe(defaultOutput);
expectActorAttribute(component, object.actor);
component = renderRep({ mode: MODE.LONG });
expect(component.text()).toBe(defaultOutput);
expectActorAttribute(component, object.actor);
});
});
describe("GripArray - max props", () => {
const object = stubs.get("testMaxProps");
it("renders as expected", () => {
const renderRep = props => shallowRenderRep(object, props);
let length = getGripLengthBubbleText(object);
const defaultOutput = `Array${length} [ 1, "foo", {} ]`;
expect(renderRep({ mode: undefined }).text()).toBe(defaultOutput);
length = getGripLengthBubbleText(object, { mode: MODE.TINY });
expect(renderRep({ mode: MODE.TINY }).text()).toBe(`${length} […]`);
expect(renderRep({ mode: MODE.SHORT }).text()).toBe(defaultOutput);
expect(renderRep({ mode: MODE.LONG }).text()).toBe(defaultOutput);
length = getGripLengthBubbleText(object, { mode: MODE.LONG });
// Check the custom title with nested objects to make sure nested objects
// are not displayed with their parent's title.
expect(
renderRep({
mode: MODE.LONG,
title: "CustomTitle"
}).text()
).toBe(`CustomTitle${length} [ 1, "foo", {} ]`);
});
});
describe("GripArray - more than short mode max props", () => {
const object = stubs.get("testMoreThanShortMaxProps");
it("renders as expected", () => {
const renderRep = props => shallowRenderRep(object, props);
let length = getGripLengthBubbleText(object);
const shortLength = maxLengthMap.get(MODE.SHORT);
const shortContent = Array(shortLength)
.fill('"test string"')
.join(", ");
const longContent = Array(shortLength + 1)
.fill('"test string"')
.join(", ");
const defaultOutput = `Array${length} [ ${shortContent}, … ]`;
expect(renderRep({ mode: undefined }).text()).toBe(defaultOutput);
length = getGripLengthBubbleText(object, { mode: MODE.TINY });
expect(renderRep({ mode: MODE.TINY }).text()).toBe(`${length} […]`);
expect(renderRep({ mode: MODE.SHORT }).text()).toBe(defaultOutput);
length = getGripLengthBubbleText(object, { mode: MODE.LONG });
expect(renderRep({ mode: MODE.LONG }).text()).toBe(
`Array${length} [ ${longContent} ]`
);
});
});
describe("GripArray - more than long mode max props", () => {
const object = stubs.get("testMoreThanLongMaxProps");
it("renders as expected", () => {
const renderRep = props => shallowRenderRep(object, props);
const length = getGripLengthBubbleText(object);
const shortLength = maxLengthMap.get(MODE.SHORT);
const longLength = maxLengthMap.get(MODE.LONG);
const shortContent = Array(shortLength)
.fill('"test string"')
.join(", ");
const defaultOutput = `Array${length} [ ${shortContent}, … ]`;
const longContent = Array(longLength)
.fill('"test string"')
.join(", ");
expect(renderRep({ mode: undefined }).text()).toBe(defaultOutput);
expect(renderRep({ mode: MODE.TINY }).text()).toBe(`${length} […]`);
expect(renderRep({ mode: MODE.SHORT }).text()).toBe(defaultOutput);
expect(renderRep({ mode: MODE.LONG }).text()).toBe(
`Array${length} [ ${longContent}, … ]`
);
});
});
describe("GripArray - recursive array", () => {
const object = stubs.get("testRecursiveArray");
it("renders as expected", () => {
const renderRep = props => shallowRenderRep(object, props);
let length = getGripLengthBubbleText(object);
const childArrayLength = getGripLengthBubbleText(object.preview.items[0], {
mode: MODE.TINY
});
const defaultOutput = `Array${length} [ ${childArrayLength} […] ]`;
expect(renderRep({ mode: undefined }).text()).toBe(defaultOutput);
length = getGripLengthBubbleText(object, { mode: MODE.TINY });
expect(renderRep({ mode: MODE.TINY }).text()).toBe(`${length} […]`);
expect(renderRep({ mode: MODE.SHORT }).text()).toBe(defaultOutput);
expect(renderRep({ mode: MODE.LONG }).text()).toBe(defaultOutput);
});
});
describe("GripArray - preview limit", () => {
const object = stubs.get("testPreviewLimit");
it("renders as expected", () => {
const renderRep = props => shallowRenderRep(object, props);
const length = getGripLengthBubbleText(object);
const shortOutput = `Array${length} [ 0, 1, 2, … ]`;
const longOutput = `Array${length} [ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, … ]`;
expect(renderRep({ mode: undefined }).text()).toBe(shortOutput);
expect(renderRep({ mode: MODE.TINY }).text()).toBe(`${length} […]`);
expect(renderRep({ mode: MODE.SHORT }).text()).toBe(shortOutput);
expect(renderRep({ mode: MODE.LONG }).text()).toBe(longOutput);
});
});
describe("GripArray - empty slots", () => {
it("renders an array with empty slots only as expected", () => {
const object = stubs.get("Array(5)");
const renderRep = props => shallowRenderRep(object, props);
let length = getGripLengthBubbleText(object);
const defaultOutput = `Array${length} [ <5 empty slots> ]`;
expect(renderRep({ mode: undefined }).text()).toBe(defaultOutput);
length = getGripLengthBubbleText(object, { mode: MODE.TINY });
expect(renderRep({ mode: MODE.TINY }).text()).toBe(`${length} […]`);
expect(renderRep({ mode: MODE.SHORT }).text()).toBe(defaultOutput);
length = getGripLengthBubbleText(object, { mode: MODE.LONG });
const longOutput = `Array${length} [ <5 empty slots> ]`;
expect(renderRep({ mode: MODE.LONG }).text()).toBe(longOutput);
});
it("one empty slot at the beginning as expected", () => {
const object = stubs.get("[,1,2,3]");
const renderRep = props => shallowRenderRep(object, props);
let length = getGripLengthBubbleText(object);
const defaultOutput = `Array${length} [ <1 empty slot>, 1, 2, … ]`;
expect(renderRep({ mode: undefined }).text()).toBe(defaultOutput);
length = getGripLengthBubbleText(object, { mode: MODE.TINY });
expect(renderRep({ mode: MODE.TINY }).text()).toBe(`${length} […]`);
expect(renderRep({ mode: MODE.SHORT }).text()).toBe(defaultOutput);
length = getGripLengthBubbleText(object, { mode: MODE.LONG });
const longOutput = `Array${length} [ <1 empty slot>, 1, 2, 3 ]`;
expect(renderRep({ mode: MODE.LONG }).text()).toBe(longOutput);
});
it("multiple consecutive empty slots at the beginning as expected", () => {
const object = stubs.get("[,,,3,4,5]");
const renderRep = props => shallowRenderRep(object, props);
const length = getGripLengthBubbleText(object);
const defaultOutput = `Array${length} [ <3 empty slots>, 3, 4, … ]`;
const longOutput = `Array${length} [ <3 empty slots>, 3, 4, 5 ]`;
expect(renderRep({ mode: undefined }).text()).toBe(defaultOutput);
expect(renderRep({ mode: MODE.TINY }).text()).toBe(`${length} […]`);
expect(renderRep({ mode: MODE.SHORT }).text()).toBe(defaultOutput);
expect(renderRep({ mode: MODE.LONG }).text()).toBe(longOutput);
});
it("one empty slot in the middle as expected", () => {
const object = stubs.get("[0,1,,3,4,5]");
const renderRep = props => shallowRenderRep(object, props);
const length = getGripLengthBubbleText(object);
const defaultOutput = `Array${length} [ 0, 1, <1 empty slot>, … ]`;
const longOutput = `Array${length} [ 0, 1, <1 empty slot>, 3, 4, 5 ]`;
expect(renderRep({ mode: undefined }).text()).toBe(defaultOutput);
expect(renderRep({ mode: MODE.TINY }).text()).toBe(`${length} […]`);
expect(renderRep({ mode: MODE.SHORT }).text()).toBe(defaultOutput);
expect(renderRep({ mode: MODE.LONG }).text()).toBe(longOutput);
});
it("successive empty slots in the middle as expected", () => {
const object = stubs.get("[0,1,,,,5]");
const renderRep = props => shallowRenderRep(object, props);
const length = getGripLengthBubbleText(object);
const defaultOutput = `Array${length} [ 0, 1, <3 empty slots>, … ]`;
const longOutput = `Array${length} [ 0, 1, <3 empty slots>, 5 ]`;
expect(renderRep({ mode: undefined }).text()).toBe(defaultOutput);
expect(renderRep({ mode: MODE.TINY }).text()).toBe(`${length} […]`);
expect(renderRep({ mode: MODE.SHORT }).text()).toBe(defaultOutput);
expect(renderRep({ mode: MODE.LONG }).text()).toBe(longOutput);
});
it("non successive single empty slots as expected", () => {
const object = stubs.get("[0,,2,,4,5]");
const renderRep = props => shallowRenderRep(object, props);
const length = getGripLengthBubbleText(object);
const defaultOutput = `Array${length} [ 0, <1 empty slot>, 2, … ]`;
expect(renderRep({ mode: undefined }).text()).toBe(defaultOutput);
expect(renderRep({ mode: MODE.TINY }).text()).toBe(`${length} […]`);
expect(renderRep({ mode: MODE.SHORT }).text()).toBe(defaultOutput);
expect(renderRep({ mode: MODE.LONG }).text()).toBe(
`Array${length} [ 0, <1 empty slot>, 2, <1 empty slot>, 4, 5 ]`
);
});
it("multiple multi-slot holes as expected", () => {
const object = stubs.get("[0,,,3,,,,7,8]");
const renderRep = props => shallowRenderRep(object, props);
const length = getGripLengthBubbleText(object);
const defaultOutput = `Array${length} [ 0, <2 empty slots>, 3, … ]`;
expect(renderRep({ mode: undefined }).text()).toBe(defaultOutput);
expect(renderRep({ mode: MODE.TINY }).text()).toBe(`${length} […]`);
expect(renderRep({ mode: MODE.SHORT }).text()).toBe(defaultOutput);
expect(renderRep({ mode: MODE.LONG }).text()).toBe(
`Array${length} [ 0, <2 empty slots>, 3, <3 empty slots>, 7, 8 ]`
);
});
it("a single slot hole at the end as expected", () => {
const object = stubs.get("[0,1,2,3,4,,]");
const renderRep = props => shallowRenderRep(object, props);
const length = getGripLengthBubbleText(object);
const defaultOutput = `Array${length} [ 0, 1, 2, … ]`;
const longOutput = `Array${length} [ 0, 1, 2, 3, 4, <1 empty slot> ]`;
expect(renderRep({ mode: undefined }).text()).toBe(defaultOutput);
expect(renderRep({ mode: MODE.TINY }).text()).toBe(`${length} […]`);
expect(renderRep({ mode: MODE.SHORT }).text()).toBe(defaultOutput);
expect(renderRep({ mode: MODE.LONG }).text()).toBe(longOutput);
});
it("multiple consecutive empty slots at the end as expected", () => {
const object = stubs.get("[0,1,2,,,,]");
const renderRep = props => shallowRenderRep(object, props);
const length = getGripLengthBubbleText(object);
const defaultOutput = `Array${length} [ 0, 1, 2, … ]`;
const longOutput = `Array${length} [ 0, 1, 2, <3 empty slots> ]`;
expect(renderRep({ mode: undefined }).text()).toBe(defaultOutput);
expect(renderRep({ mode: MODE.TINY }).text()).toBe(`${length} […]`);
expect(renderRep({ mode: MODE.SHORT }).text()).toBe(defaultOutput);
expect(renderRep({ mode: MODE.LONG }).text()).toBe(longOutput);
});
});
describe("GripArray - NamedNodeMap", () => {
const object = stubs.get("testNamedNodeMap");
it("renders as expected", () => {
const renderRep = props => shallowRenderRep(object, props);
let length = getGripLengthBubbleText(object);
const defaultOutput =
`NamedNodeMap${length} ` +
'[ class="myclass", cellpadding="7", border="3" ]';
expect(renderRep({ mode: undefined }).text()).toBe(defaultOutput);
length = getGripLengthBubbleText(object, { mode: MODE.TINY });
expect(renderRep({ mode: MODE.TINY }).text()).toBe(`NamedNodeMap${length}`);
expect(renderRep({ mode: MODE.SHORT }).text()).toBe(defaultOutput);
expect(renderRep({ mode: MODE.LONG }).text()).toBe(defaultOutput);
});
});
describe("GripArray - NodeList", () => {
const object = stubs.get("testNodeList");
const grips = getSelectableInInspectorGrips(object);
const renderRep = props => shallowRenderRep(object, props);
let length = getGripLengthBubbleText(object);
it("renders as expected", () => {
const defaultOutput =
`NodeList${length} [ button#btn-1.btn.btn-log, ` +
"button#btn-2.btn.btn-err, button#btn-3.btn.btn-count ]";
expect(renderRep({ mode: undefined }).text()).toBe(defaultOutput);
length = getGripLengthBubbleText(object, { mode: MODE.TINY });
expect(renderRep({ mode: MODE.TINY }).text()).toBe(`NodeList${length}`);
expect(renderRep({ mode: MODE.SHORT }).text()).toBe(defaultOutput);
expect(renderRep({ mode: MODE.LONG }).text()).toBe(defaultOutput);
});
it("has 3 node grip", () => {
expect(grips).toHaveLength(3);
});
it("calls the expected function on mouseover", () => {
const onDOMNodeMouseOver = jest.fn();
const wrapper = renderRep({ onDOMNodeMouseOver });
const node = wrapper.find(".objectBox-node");
node.at(0).simulate("mouseover");
node.at(1).simulate("mouseover");
node.at(2).simulate("mouseover");
expect(onDOMNodeMouseOver.mock.calls).toHaveLength(3);
expect(onDOMNodeMouseOver.mock.calls[0][0]).toBe(grips[0]);
expect(onDOMNodeMouseOver.mock.calls[1][0]).toBe(grips[1]);
expect(onDOMNodeMouseOver.mock.calls[2][0]).toBe(grips[2]);
});
it("calls the expected function on mouseout", () => {
const onDOMNodeMouseOut = jest.fn();
const wrapper = renderRep({ onDOMNodeMouseOut });
const node = wrapper.find(".objectBox-node");
node.at(0).simulate("mouseout");
node.at(1).simulate("mouseout");
node.at(2).simulate("mouseout");
expect(onDOMNodeMouseOut.mock.calls).toHaveLength(3);
});
it("calls the expected function on click", () => {
const onInspectIconClick = jest.fn();
const wrapper = renderRep({ onInspectIconClick });
const node = wrapper.find(".open-inspector");
node.at(0).simulate("click");
node.at(1).simulate("click");
node.at(2).simulate("click");
expect(onInspectIconClick.mock.calls).toHaveLength(3);
expect(onInspectIconClick.mock.calls[0][0]).toBe(grips[0]);
expect(onInspectIconClick.mock.calls[1][0]).toBe(grips[1]);
expect(onInspectIconClick.mock.calls[2][0]).toBe(grips[2]);
});
it("no inspect icon when nodes are not connected to the DOM tree", () => {
const renderedComponentWithoutInspectIcon = shallowRenderRep(
stubs.get("testDisconnectedNodeList")
);
const node = renderedComponentWithoutInspectIcon.find(".open-inspector");
expect(node.exists()).toBe(false);
});
});
describe("GripArray - DocumentFragment", () => {
const object = stubs.get("testDocumentFragment");
it("renders as expected", () => {
const renderRep = props => shallowRenderRep(object, props);
let length = getGripLengthBubbleText(object);
const defaultOutput =
`DocumentFragment${length} [ li#li-0.list-element, ` +
"li#li-1.list-element, li#li-2.list-element, … ]";
expect(renderRep({ mode: undefined }).text()).toBe(defaultOutput);
length = getGripLengthBubbleText(object, { mode: MODE.TINY });
expect(renderRep({ mode: MODE.TINY }).text()).toBe(
`DocumentFragment${length}`
);
expect(renderRep({ mode: MODE.SHORT }).text()).toBe(defaultOutput);
length = getGripLengthBubbleText(object, { mode: MODE.LONG });
const longOutput =
`DocumentFragment${length} [ ` +
"li#li-0.list-element, li#li-1.list-element, li#li-2.list-element, " +
"li#li-3.list-element, li#li-4.list-element ]";
expect(renderRep({ mode: MODE.LONG }).text()).toBe(longOutput);
});
});
describe("GripArray - Items not in preview", () => {
const object = stubs.get("testItemsNotInPreview");
it("correctly selects GripArray Rep", () => {
expect(getRep(object)).toBe(GripArray.rep);
});
it("renders as expected", () => {
const renderRep = props => shallowRenderRep(object, props);
let length = getGripLengthBubbleText(object);
const defaultOutput = `Array${length} [ … ]`;
let component = renderRep({ mode: undefined });
expect(component.text()).toBe(defaultOutput);
expectActorAttribute(component, object.actor);
length = getGripLengthBubbleText(object, { mode: MODE.TINY });
component = renderRep({ mode: MODE.TINY });
expect(component.text()).toBe(`${length} […]`);
expectActorAttribute(component, object.actor);
component = renderRep({ mode: MODE.SHORT });
expect(component.text()).toBe(defaultOutput);
expectActorAttribute(component, object.actor);
component = renderRep({ mode: MODE.LONG });
expect(component.text()).toBe(defaultOutput);
expectActorAttribute(component, object.actor);
});
});
describe("GripArray - Set", () => {
it("correctly selects GripArray Rep", () => {
const object = stubs.get("new Set([1,2,3,4])");
expect(getRep(object)).toBe(GripArray.rep);
});
it("renders short sets as expected", () => {
const object = stubs.get("new Set([1,2,3,4])");
const renderRep = props => shallowRenderRep(object, props);
let length = getGripLengthBubbleText(object);
const defaultOutput = `Set${length} [ 1, 2, 3, … ]`;
let component = renderRep({ mode: undefined });
expect(component.text()).toBe(defaultOutput);
expectActorAttribute(component, object.actor);
component = renderRep({ mode: MODE.TINY });
expect(component.text()).toBe(`Set${length}`);
expectActorAttribute(component, object.actor);
component = renderRep({ mode: MODE.SHORT });
expect(component.text()).toBe(defaultOutput);
expectActorAttribute(component, object.actor);
length = getGripLengthBubbleText(object, { mode: MODE.LONG });
component = renderRep({ mode: MODE.LONG });
expect(component.text()).toBe(`Set${length} [ 1, 2, 3, 4 ]`);
expectActorAttribute(component, object.actor);
});
it("renders larger sets as expected", () => {
const object = stubs.get("new Set([0,1,2,…,19])");
const renderRep = props => shallowRenderRep(object, props);
let length = getGripLengthBubbleText(object);
const defaultOutput = `Set${length} [ 0, 1, 2, … ]`;
let component = renderRep({ mode: undefined });
expect(component.text()).toBe(defaultOutput);
expectActorAttribute(component, object.actor);
component = renderRep({ mode: MODE.TINY });
expect(component.text()).toBe(`Set${length}`);
expectActorAttribute(component, object.actor);
component = renderRep({ mode: MODE.SHORT });
expect(component.text()).toBe(defaultOutput);
expectActorAttribute(component, object.actor);
length = getGripLengthBubbleText(object, { mode: MODE.LONG });
component = renderRep({ mode: MODE.LONG });
expect(component.text()).toBe(
`Set${length} [ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, … ]`
);
expectActorAttribute(component, object.actor);
});
});
describe("GripArray - WeakSet", () => {
it("correctly selects GripArray Rep", () => {
const object = stubs.get(
"new WeakSet(document.querySelectorAll('button:nth-child(3n)'))"
);
expect(getRep(object)).toBe(GripArray.rep);
});
it("renders short WeakSets as expected", () => {
const object = stubs.get(
"new WeakSet(document.querySelectorAll('button:nth-child(3n)'))"
);
const renderRep = props => shallowRenderRep(object, props);
let length = getGripLengthBubbleText(object);
const defaultOutput = `WeakSet${length} [ button, button, button, … ]`;
let component = renderRep({ mode: undefined });
expect(component.text()).toBe(defaultOutput);
expectActorAttribute(component, object.actor);
component = renderRep({ mode: MODE.TINY });
expect(component.text()).toBe(`WeakSet${length}`);
expectActorAttribute(component, object.actor);
component = renderRep({ mode: MODE.SHORT });
expect(component.text()).toBe(defaultOutput);
expectActorAttribute(component, object.actor);
length = getGripLengthBubbleText(object, { mode: MODE.LONG });
component = renderRep({ mode: MODE.LONG });
expect(component.text()).toBe(
`WeakSet${length} [ button, button, button, button ]`
);
expectActorAttribute(component, object.actor);
});
it("renders larger WeakSets as expected", () => {
const object = stubs.get(
"new WeakSet(document.querySelectorAll('div, button'))"
);
const renderRep = props => shallowRenderRep(object, props);
const length = getGripLengthBubbleText(object);
const defaultOutput = `WeakSet${length} [ button, button, button, … ]`;
let component = renderRep({ mode: undefined });
expect(component.text()).toBe(defaultOutput);
expectActorAttribute(component, object.actor);
component = renderRep({ mode: MODE.TINY });
expect(component.text()).toBe(`WeakSet${length}`);
expectActorAttribute(component, object.actor);
component = renderRep({ mode: MODE.SHORT });
expect(component.text()).toBe(defaultOutput);
expectActorAttribute(component, object.actor);
component = renderRep({ mode: MODE.LONG });
expect(component.text()).toBe(`WeakSet(12) [ ${"button, ".repeat(10)}… ]`);
expectActorAttribute(component, object.actor);
});
});
describe("GripArray - DOMTokenList", () => {
const object = stubs.get("DOMTokenList");
it("correctly selects GripArray Rep", () => {
expect(getRep(object)).toBe(GripArray.rep);
});
it("renders as expected", () => {
const renderRep = props => shallowRenderRep(object, props);
const length = getGripLengthBubbleText(object);
const defaultOutput = `DOMTokenList${length} []`;
let component = renderRep({ mode: undefined });
expect(component.text()).toBe(defaultOutput);
expectActorAttribute(component, object.actor);
component = renderRep({ mode: MODE.TINY });
expect(component.text()).toBe(defaultOutput);
expectActorAttribute(component, object.actor);
component = renderRep({ mode: MODE.SHORT });
expect(component.text()).toBe(defaultOutput);
expectActorAttribute(component, object.actor);
component = renderRep({ mode: MODE.LONG });
expect(component.text()).toBe(defaultOutput);
expectActorAttribute(component, object.actor);
});
});