Skip to content

Commit 80dfe06

Browse files
authored
chore: add test showing property reflection on boolean attribute (#7353)
# Pull Request ## πŸ“– Description Added a test showing reflection of a property on a boolean attribute. Closes #7351 ## βœ… Checklist ### General - [x] I have included a change request file using `$ npm run change` - [x] I have added tests for my changes. - [x] I have tested my changes. - [ ] I have updated the project documentation to reflect my changes. - [x] I have read the [CONTRIBUTING](https://github.com/microsoft/fast/blob/main/CONTRIBUTING.md) documentation and followed the [standards](https://github.com/microsoft/fast/blob/main/CODE_OF_CONDUCT.md#our-standards) for this project.
1 parent 3c3d3da commit 80dfe06

4 files changed

Lines changed: 42 additions & 2 deletions

File tree

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"type": "none",
3+
"comment": "chore: add test showing property reflection on boolean attribute",
4+
"packageName": "@microsoft/fast-html",
5+
"email": "7559015+janechu@users.noreply.github.com",
6+
"dependentChangeType": "none"
7+
}

β€Žpackages/fast-html/test/fixtures/attribute/attribute.spec.tsβ€Ž

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,20 @@ test.describe("f-template", async () => {
2424
await expect(customElement).toHaveAttribute("type", "radio");
2525
await expect(customElement.locator("input[type='radio']")).toHaveCount(1);
2626
});
27+
test("create a property to attribute binding", async ({ page }) => {
28+
await page.goto("/fixtures/attribute/");
29+
30+
const customElement = page.locator("test-element-property");
31+
32+
await expect(customElement.locator("input[disabled]")).toHaveCount(1);
33+
34+
await page.evaluate(() => {
35+
const customElement = document.getElementsByTagName("test-element-property");
36+
(customElement.item(0) as any)!.isEnabled = true;
37+
});
38+
39+
await expect(customElement.locator("input[disabled]")).toHaveCount(0);
40+
});
2741
test("create an attribute binding with an expression", async ({ page }) => {
2842
await page.goto("/fixtures/attribute/");
2943

@@ -33,7 +47,9 @@ test.describe("f-template", async () => {
3347
await expect(customElementInput).toHaveAttribute("disabled");
3448

3549
await page.evaluate(() => {
36-
const customElement = document.getElementsByTagName("test-element-expression");
50+
const customElement = document.getElementsByTagName(
51+
"test-element-expression",
52+
);
3753
customElement.item(0)?.setAttribute("active-group", "home");
3854
});
3955

β€Žpackages/fast-html/test/fixtures/attribute/index.htmlβ€Ž

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,11 @@
1010
<input disabled data-fe-b-0 type="checkbox">
1111
</template>
1212
</test-element>
13+
<test-element-property>
14+
<template shadowrootmode="open">
15+
<input type="checkbox" data-fe-b-0 disabled>
16+
</template>
17+
</test-element-property>
1318
<test-element-expression active-group="work" current-group="work">
1419
<template shadowrootmode="open">
1520
<input disabled data-fe-b-0 type="button">
@@ -18,6 +23,9 @@
1823
<f-template name="test-element">
1924
<template><input type="{{type}}" disabled></template>
2025
</f-template>
26+
<f-template name="test-element-property">
27+
<template><input type="checkbox" ?disabled="{{!isEnabled}}"></template>
28+
</f-template>
2129
<f-template name="test-element-expression">
2230
<template>
2331
<input ?disabled="{{activeGroup == currentGroup}}" type="button">

β€Žpackages/fast-html/test/fixtures/attribute/main.tsβ€Ž

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1+
import { attr, FASTElement, observable } from "@microsoft/fast-element";
12
import { RenderableFASTElement, TemplateElement } from "@microsoft/fast-html";
2-
import { attr, FASTElement } from "@microsoft/fast-element";
33

44
class TestElement extends FASTElement {
55
@attr
@@ -10,6 +10,15 @@ RenderableFASTElement(TestElement).defineAsync({
1010
templateOptions: "defer-and-hydrate",
1111
});
1212

13+
class TestElementProperty extends FASTElement {
14+
@observable
15+
isEnabled: boolean = false;
16+
}
17+
RenderableFASTElement(TestElementProperty).defineAsync({
18+
name: "test-element-property",
19+
templateOptions: "defer-and-hydrate",
20+
});
21+
1322
class TestElementExpression extends FASTElement {
1423
@attr({ attribute: "active-group" })
1524
activeGroup: string = "";

0 commit comments

Comments
Β (0)