Add some tests for Et2Box.disabled to make sure it behaves.

This commit is contained in:
nathan 2022-01-12 14:35:01 -07:00
parent 19a2b13974
commit a5f8b6076a

View File

@ -1,7 +1,7 @@
/**
* Test file for Etemplate webComponent base widget Et2Box
*/
import {assert, fixture} from '@open-wc/testing';
import {assert, elementUpdated, fixture} from '@open-wc/testing';
import {Et2Box} from "../Et2Box";
import {html} from "lit-element";
@ -28,5 +28,40 @@ describe("Box widget", () =>
{
element.set_label("Nope");
assert.isEmpty(element.shadowRoot.querySelectorAll('.et2_label'));
})
});
it('disabled', async() =>
{
element.disabled = true;
// wait for asychronous changes to the DOM
// @ts-ignore TypeScript is not recognizing that this widget is a LitElement
await elementUpdated(element);
let style = window.getComputedStyle(<Element><unknown>element);
assert.include(element.getAttributeNames(), "disabled", "Missing disabled attribute");
assert.equal(style.display, "none", "Did not hide when disabled");
element.disabled = false;
// wait for asychronous changes to the DOM
// @ts-ignore TypeScript is not recognizing that this widget is a LitElement
await elementUpdated(element);
// Check attribute goes
assert.notInclude(element.getAttributeNames(), "disabled", "Still had disabled attribute after setting it to false");
style = window.getComputedStyle(<Element><unknown>element);
assert.notEqual(style.display, "none", "Did not show when not disabled");
/** Check via set method instead of property **/
element.set_disabled(true);
// wait for asychronous changes to the DOM
// @ts-ignore TypeScript is not recognizing that this widget is a LitElement
await elementUpdated(element);
style = window.getComputedStyle(<Element><unknown>element);
assert.include(element.getAttributeNames(), "disabled", "Missing disabled attribute");
assert.equal(style.display, "none", "Did not hide when disabled via set_disabled()");
});
});