Skip to content

Commit

Permalink
tests and fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
tomivirkki committed Sep 11, 2024
1 parent b813781 commit 5505aa6
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 2 deletions.
9 changes: 7 additions & 2 deletions packages/dashboard/src/widget-resize-controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -106,13 +106,18 @@ export class WidgetResizeController extends EventTarget {
itemWrapper.style.removeProperty('--_vaadin-dashboard-widget-resizer-width');
itemWrapper.style.removeProperty('--_vaadin-dashboard-widget-resizer-height');

this.resizedItem = null;
this.host.$.grid.toggleAttribute('resizing', false);

this.__resizedElementRemoveObserver.disconnect();
this.cleanup();

this.host.dispatchEvent(new CustomEvent('dashboard-item-resize-end'));
this.host.dispatchEvent(
new CustomEvent('dashboard-item-resize-end', {
detail: { item: this.resizedItem },
cancelable: true,
}),
);
this.resizedItem = null;
}

/** @private */
Expand Down
18 changes: 18 additions & 0 deletions packages/dashboard/test/dashboard-widget-resizing.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -272,10 +272,15 @@ describe('dashboard - widget resizing', () => {
dashboard.addEventListener('dashboard-item-resize-end', resizeEndSpy);
fireResizeStart(getElementFromCell(dashboard, 0, 0)!);
await nextFrame();
fireResizeOver(getElementFromCell(dashboard, 0, 1)!, 'end');
await nextFrame();
fireResizeEnd(dashboard);
await nextFrame();

expect(resizeEndSpy).to.have.been.calledOnce;
expect(resizeEndSpy.getCall(0).args[0].detail).to.deep.equal({
item: { id: 0, colspan: 2, rowspan: 1 },
});
});

it('should cancel touchmove events while resizing', async () => {
Expand All @@ -298,6 +303,19 @@ describe('dashboard - widget resizing', () => {
expect(touchmove.defaultPrevented).to.be.false;
});

it('should prevent selection while resizing', async () => {
expect(getComputedStyle(getElementFromCell(dashboard, 0, 0)!).userSelect).not.to.equal('none');
fireResizeStart(getElementFromCell(dashboard, 0, 0)!);
await nextFrame();

expect(getComputedStyle(getElementFromCell(dashboard, 0, 0)!).userSelect).to.equal('none');

fireResizeEnd(dashboard);
await nextFrame();

expect(getComputedStyle(getElementFromCell(dashboard, 0, 0)!).userSelect).not.to.equal('none');
});

// Make sure the original resized element is restored in the host.
// Otherwise, "track" event would stop working.
describe('ensure track event', () => {
Expand Down

0 comments on commit 5505aa6

Please sign in to comment.