Skip to content

Commit

Permalink
wip getLoadingComplete test for dialog
Browse files Browse the repository at this point in the history
  • Loading branch information
KearseTrevor committed Jan 14, 2025
1 parent 20f13b9 commit 16add1e
Showing 1 changed file with 42 additions and 1 deletion.
43 changes: 42 additions & 1 deletion components/dialog/test/dialog.test.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import '../dialog.js';
import { expect, fixture, oneEvent, runConstructor } from '@brightspace-ui/testing';
import { html, LitElement } from 'lit';
import { createMessage } from '../../../mixins/property-required/property-required-mixin.js';
import { getComposedActiveElement } from '../../../helpers/focus.js';
import { html } from 'lit';
import { spy } from 'sinon';

describe('d2l-dialog', () => {

Expand Down Expand Up @@ -80,4 +81,44 @@ describe('d2l-dialog', () => {

});

class DelayedElement extends LitElement {
render() {
return html`<div class="delayed-div"></div>`;
}

async getLoadingComplete() {
const newChild = document.createElement('div');
newChild.className = 'added-child';
newChild.textContent = 'New addition to the family!';
this.shadowRoot.appendChild(newChild);
await new Promise(r => setTimeout(r, 100));
}
}
customElements.define('delayed-elem', DelayedElement);

describe('getLoadingComplete', () => {

it('should wait for child component\'s getLoadingComplete before resizing', async() => {

const el = await fixture(html`
<d2l-dialog>
<delayed-elem></delayed-elem>
</d2l-dialog>
`);

const delayedComponent = el.querySelector('delayed-elem');
const mixinProto = Object.getPrototypeOf(el).__proto__;
const resizeSpy = spy(mixinProto, 'resize');

el.opened = true;
await oneEvent(el, 'd2l-dialog-open');
el.asyncState = 'complete';

expect(resizeSpy.called).to.be.false;
await delayedComponent.getLoadingComplete();
expect(resizeSpy.calledOnce).to.be.true;
});

});

});

0 comments on commit 16add1e

Please sign in to comment.