Skip to content

Commit

Permalink
Merge branch 'master' into users/kingoftac/foundation/update-grid-row…
Browse files Browse the repository at this point in the history
…-style-method
  • Loading branch information
KingOfTac authored Jan 9, 2024
2 parents 485cf6f + 9af1b25 commit bc12e53
Show file tree
Hide file tree
Showing 2 changed files with 87 additions and 9 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"type": "none",
"comment": "Additional design token test cases",
"packageName": "@microsoft/fast-foundation",
"email": "[email protected]",
"dependentChangeType": "none"
}
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ test.describe("A DesignToken", () => {
});
});
test.describe("getting and setting a simple value", () => {
test("should throw if the token value has never been set on the element or it's any ancestors", async () => {
test("should throw if the token value has never been set on the element or its ancestors", async () => {
const result = await page.evaluate((name: string) => {
const target = addElement();
const token = DesignToken.create<number>(name);
Expand Down Expand Up @@ -202,6 +202,28 @@ test.describe("A DesignToken", () => {
).toEqual([12, 14]);
});

test("should persist explicitly set value even if it matches the inherited value", async () => {
expect(
await page.evaluate(async () => {
const results = [];
const ancestor = addElement();
const target = addElement(ancestor);
const token = DesignToken.create<number>(uniqueTokenName());
token.setValueFor(ancestor, 12);
token.setValueFor(target, 12);

results.push(token.getValueFor(target));

token.setValueFor(ancestor, 14);

await Updates.next();

results.push(token.getValueFor(target));
return results;
})
).toEqual([12, 12]);
});

test("should support getting and setting falsey values", async () => {
expect(
await page.evaluate(() => {
Expand Down Expand Up @@ -263,6 +285,59 @@ test.describe("A DesignToken", () => {
})
).toBe("12");
});

test("should inherit CSS custom property from ancestor", async () => {
expect(
await page.evaluate(async () => {
const results = [];
const ancestor = addElement();
const target = addElement(ancestor);
const token = DesignToken.create<number>(uniqueTokenName());
token.setValueFor(ancestor, 12);
await Updates.next();
results.push(
window
.getComputedStyle(target)
.getPropertyValue(token.cssCustomProperty)
);
token.setValueFor(ancestor, 14);
await Updates.next();
results.push(
window
.getComputedStyle(target)
.getPropertyValue(token.cssCustomProperty)
);
return results;
})
).toEqual(["12", "14"]);
});

test("should set CSS custom property for element if value stops matching inherited value", async () => {
expect(
await page.evaluate(async () => {
const results = [];
const ancestor = addElement();
const target = addElement(ancestor);
const token = DesignToken.create<number>(uniqueTokenName());
token.setValueFor(ancestor, 12);
token.setValueFor(target, 12);
await Updates.next();
results.push(
window
.getComputedStyle(target)
.getPropertyValue(token.cssCustomProperty)
);
token.setValueFor(ancestor, 14);
await Updates.next();
results.push(
window
.getComputedStyle(target)
.getPropertyValue(token.cssCustomProperty)
);
return results;
})
).toEqual(["12", "12"]);
});
});
test.describe("that is not a CSSDesignToken", () => {
test("should not set a CSS custom property for the element", async () => {
Expand Down Expand Up @@ -963,11 +1038,9 @@ test.describe("A DesignToken", () => {
target.$fastController.addStyles(styles);

await Updates.next();
return window
.getComputedStyle(target)
.getPropertyValue(token.cssCustomProperty);
return window.getComputedStyle(target).getPropertyValue("width");
})
).toBe("12");
).toBe("12px");
});
test("should set a CSS custom property for the element when the token is set for an ancestor element", async () => {
expect(
Expand All @@ -984,11 +1057,9 @@ test.describe("A DesignToken", () => {
target.$fastController.addStyles(styles);

await Updates.next();
return window
.getComputedStyle(target)
.getPropertyValue(token.cssCustomProperty);
return window.getComputedStyle(target).getPropertyValue("width");
})
).toBe("12");
).toBe("12px");
});
});

Expand Down

0 comments on commit bc12e53

Please sign in to comment.