Skip to content

Commit f42bbb3

Browse files
committed
Fix AdjustableSidebarWidth.spec.js
1 parent 1975189 commit f42bbb3

File tree

1 file changed

+35
-16
lines changed

1 file changed

+35
-16
lines changed

tests/unit/components/AdjustableSidebarWidth.spec.js

Lines changed: 35 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -112,14 +112,15 @@ describe('AdjustableSidebarWidth', () => {
112112
assertWidth(wrapper, LARGE_DEFAULT_WIDTH);
113113
});
114114

115-
it('changes the `width`, to the next closest max or min, on mount, as soon as the breakpoint gets changed', () => {
115+
it('changes the `width`, to the next closest max or min, on mount, as soon as the breakpoint gets changed', async () => {
116116
const wrapper = createWrapper({
117117
data: () => ({
118118
width: 650,
119119
}),
120120
});
121121
assertWidth(wrapper, 650);
122122
wrapper.findComponent(BreakpointEmitter).vm.$emit('change', 'medium');
123+
await wrapper.vm.$nextTick();
123124
assertWidth(wrapper, 500); // 50% on medium
124125
});
125126

@@ -130,11 +131,13 @@ describe('AdjustableSidebarWidth', () => {
130131
const emitter = wrapper.findComponent(BreakpointEmitter);
131132
expect(emitter.props('scope')).toEqual(BreakpointScopes.nav);
132133
emitter.vm.$emit('change', BreakpointName.small);
134+
await wrapper.vm.$nextTick();
133135
expect(aside.classes()).toContain('no-transition');
134136
await waitFrames(5);
135137
expect(aside.classes()).not.toContain('no-transition');
136138
// try going back to large now
137139
emitter.vm.$emit('change', BreakpointName.large);
140+
await wrapper.vm.$nextTick();
138141
expect(aside.classes()).toContain('no-transition');
139142
await waitFrames(5);
140143
expect(aside.classes()).not.toContain('no-transition');
@@ -253,7 +256,7 @@ describe('AdjustableSidebarWidth', () => {
253256
expect(boundingClientSpy).toHaveBeenCalledTimes(2);
254257
});
255258

256-
it('allows closing the sidebar, with Esc', () => {
259+
it('allows closing the sidebar, with Esc', async () => {
257260
const wrapper = createWrapper({
258261
propsData: {
259262
shownOnMobile: true,
@@ -262,6 +265,7 @@ describe('AdjustableSidebarWidth', () => {
262265
window.dispatchEvent(createEvent('keydown', {
263266
key: 'Escape',
264267
}));
268+
await wrapper.vm.$nextTick();
265269
expect(wrapper.emitted('update:shownOnMobile')).toEqual([[false]]);
266270
});
267271

@@ -354,14 +358,15 @@ describe('AdjustableSidebarWidth', () => {
354358
expect(wrapper.vm.asideStyles).toHaveProperty('--app-height', '700px');
355359
});
356360

357-
it('allows dragging the handle to expand/contract the sidebar, with the mouse', () => {
361+
it('allows dragging the handle to expand/contract the sidebar, with the mouse', async () => {
358362
const wrapper = createWrapper();
359363
const aside = wrapper.findComponent('.aside');
360364
// assert dragging
361-
wrapper.findComponent('.resize-handle').trigger('mousedown', { type: 'mouseevent' });
365+
wrapper.findComponent('.resize-handle').trigger('mousedown');
362366
document.dispatchEvent(createEvent(eventsMap.mouse.move, {
363367
clientX: 500,
364368
}));
369+
await wrapper.vm.$nextTick();
365370
// assert class
366371
expect(aside.classes()).toContain('dragging');
367372
assertWidth(wrapper, 400); // offset is 100, so we remove it from the clientX
@@ -372,6 +377,7 @@ describe('AdjustableSidebarWidth', () => {
372377
assertWidth(wrapper, maxWidth);
373378
// assert drop
374379
document.dispatchEvent(createEvent(eventsMap.mouse.end));
380+
await wrapper.vm.$nextTick();
375381
// assert emit event
376382
expect(wrapper.emitted('width-change')).toHaveLength(2);
377383
expect(wrapper.emitted('width-change')[1]).toEqual([maxWidth]);
@@ -388,16 +394,17 @@ describe('AdjustableSidebarWidth', () => {
388394
assertWidth(wrapper, maxWidth);
389395
});
390396

391-
it('allows dragging the handle to expand/contract the sidebar, with the touch device', () => {
397+
it('allows dragging the handle to expand/contract the sidebar, with the touch device', async () => {
392398
const wrapper = createWrapper();
393399
const aside = wrapper.findComponent('.aside');
394400
// assert dragging
395-
wrapper.findComponent('.resize-handle').trigger('touchstart', { type: 'touchstart' });
401+
wrapper.findComponent('.resize-handle').trigger('touchstart');
396402
document.dispatchEvent(createEvent(eventsMap.touch.move, {
397403
touches: [{
398404
clientX: 500,
399405
}],
400406
}));
407+
await wrapper.vm.$nextTick();
401408
// assert class
402409
expect(aside.classes()).toContain('dragging');
403410
assertWidth(wrapper, 400); // offset is 100, so we remove it from the clientX
@@ -410,6 +417,7 @@ describe('AdjustableSidebarWidth', () => {
410417
assertWidth(wrapper, maxWidth);
411418
// assert drop
412419
document.dispatchEvent(createEvent(eventsMap.touch.end));
420+
await wrapper.vm.$nextTick();
413421
// assert emit event
414422
expect(wrapper.emitted('width-change')).toHaveLength(2);
415423
expect(wrapper.emitted('width-change')[1]).toEqual([maxWidth]);
@@ -428,42 +436,45 @@ describe('AdjustableSidebarWidth', () => {
428436
assertWidth(wrapper, maxWidth);
429437
});
430438

431-
it('prevents dragging outside of the window', () => {
439+
it('prevents dragging outside of the window', async () => {
432440
window.innerWidth = 1000;
433441
const wrapper = createWrapper();
434442
const aside = wrapper.findComponent('.aside');
435443
// assert dragging
436-
wrapper.findComponent('.resize-handle').trigger('mousedown', { type: 'mousedown' });
444+
wrapper.findComponent('.resize-handle').trigger('mousedown');
437445
document.dispatchEvent(createEvent(eventsMap.mouse.move, {
438446
clientX: window.innerWidth + 500,
439447
}));
448+
await wrapper.vm.$nextTick();
440449
// assert class
441450
expect(aside.classes()).toContain('dragging');
442451
assertWidth(wrapper, maxWidth); // wrapper is no wider than the max width
443452
});
444453

445-
it('prevents dragging outside of the max container', () => {
454+
it('prevents dragging outside of the max container', async () => {
446455
window.innerWidth = MAX_WIDTH + 200; // very wide screen
447456
const wrapper = createWrapper();
448457
const aside = wrapper.findComponent('.aside');
449458
// assert dragging
450-
wrapper.findComponent('.resize-handle').trigger('mousedown', { type: 'mousedown' });
459+
wrapper.findComponent('.resize-handle').trigger('mousedown');
451460
document.dispatchEvent(createEvent(eventsMap.mouse.move, {
452461
clientX: window.innerWidth + 500,
453462
}));
463+
await wrapper.vm.$nextTick();
454464
// assert class
455465
expect(aside.classes()).toContain('dragging');
456466
assertWidth(wrapper, 608); // wrapper is no wider than 40% of the widest possible, which is 1920
457467
});
458468

459-
it('prevents dragging below the `minWidth`', () => {
469+
it('prevents dragging below the `minWidth`', async () => {
460470
const wrapper = createWrapper();
461471
const aside = wrapper.findComponent('.aside');
462472
// assert dragging
463-
wrapper.findComponent('.resize-handle').trigger('mousedown', { type: 'mousedown' });
473+
wrapper.findComponent('.resize-handle').trigger('mousedown');
464474
document.dispatchEvent(createEvent(eventsMap.mouse.move, {
465475
clientX: 100,
466476
}));
477+
await wrapper.vm.$nextTick();
467478
// assert class
468479
expect(aside.classes()).toContain('dragging');
469480
assertWidth(wrapper, 300); // wrapper is minimum 20% of the screen (1000px)
@@ -474,11 +485,12 @@ describe('AdjustableSidebarWidth', () => {
474485
const aside = wrapper.findComponent('.aside');
475486
// assert dragging
476487
expect(wrapper.emitted('update:hiddenOnLarge')).toBeFalsy();
477-
wrapper.findComponent('.resize-handle').trigger('mousedown', { type: 'mousedown' });
488+
wrapper.findComponent('.resize-handle').trigger('mousedown');
478489
document.dispatchEvent(createEvent(eventsMap.mouse.move, {
479490
// minimum is 200, so 100px wide is the forceClose cutoff point, so we drag 50px beyond it
480491
clientX: 150,
481492
}));
493+
await wrapper.vm.$nextTick();
482494
// assert class
483495
expect(aside.classes()).toContain('dragging');
484496
assertWidth(wrapper, 300); // wrapper is minimum 30% of the screen (1000px)
@@ -491,6 +503,7 @@ describe('AdjustableSidebarWidth', () => {
491503
document.dispatchEvent(createEvent(eventsMap.mouse.move, {
492504
clientX: 350,
493505
}));
506+
await wrapper.vm.$nextTick();
494507
assertWidth(wrapper, 300);
495508
expect(wrapper.emitted('update:hiddenOnLarge')).toEqual([[true], [false]]);
496509
expect(aside.classes()).toContain('is-opening-on-large');
@@ -512,17 +525,18 @@ describe('AdjustableSidebarWidth', () => {
512525
expect(wrapper.vm.asideStyles).toHaveProperty('--top-offset', '22px');
513526
});
514527

515-
it('accounts for zoomed in devices', () => {
528+
it('accounts for zoomed in devices', async () => {
516529
window.scrollX = 55;
517530
const wrapper = createWrapper();
518531
const aside = wrapper.findComponent('.aside');
519532
// assert dragging
520-
wrapper.findComponent('.resize-handle').trigger('touchstart', { type: 'touchstart' });
533+
wrapper.findComponent('.resize-handle').trigger('touchstart');
521534
document.dispatchEvent(createEvent(eventsMap.touch.move, {
522535
touches: [{
523536
clientX: 300,
524537
}],
525538
}));
539+
await wrapper.vm.$nextTick();
526540
// assert class
527541
expect(aside.classes()).toContain('dragging');
528542
// offset is 100, so we remove it from the clientX, but we add the scrollX.
@@ -533,6 +547,7 @@ describe('AdjustableSidebarWidth', () => {
533547
clientX: window.innerWidth + 150,
534548
}],
535549
}));
550+
await wrapper.vm.$nextTick();
536551
assertWidth(wrapper, maxWidth);
537552
});
538553

@@ -544,11 +559,14 @@ describe('AdjustableSidebarWidth', () => {
544559
const aside = wrapper.findComponent('.aside');
545560
expect(aside.classes()).not.toContain('sidebar-transitioning');
546561
aside.trigger('transitionstart', { propertyName: 'width' });
562+
await wrapper.vm.$nextTick();
547563
expect(aside.classes()).toContain('sidebar-transitioning');
548564
aside.trigger('transitionend', { propertyName: 'width' });
565+
await wrapper.vm.$nextTick();
549566
expect(aside.classes()).not.toContain('sidebar-transitioning');
550567
// assert it stops transitioning after time
551568
aside.trigger('transitionstart', { propertyName: 'width' });
569+
await wrapper.vm.$nextTick();
552570
expect(aside.classes()).toContain('sidebar-transitioning');
553571
await flushPromises();
554572
expect(aside.classes()).not.toContain('sidebar-transitioning');
@@ -596,12 +614,13 @@ describe('AdjustableSidebarWidth', () => {
596614
const wrapper = createWrapper();
597615
setContentWidth(wrapper, 99);
598616
expect(store.state.contentWidth).toBe(0);
599-
wrapper.findComponent('.resize-handle').trigger('touchstart', { type: 'touchstart' });
617+
wrapper.findComponent('.resize-handle').trigger('touchstart');
600618
document.dispatchEvent(createEvent(eventsMap.touch.move, {
601619
touches: [{
602620
clientX: 300,
603621
}],
604622
}));
623+
await wrapper.vm.$nextTick();
605624
await flushPromises();
606625
expect(store.state.contentWidth).toBe(99);
607626
});

0 commit comments

Comments
 (0)