Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add additional design token test cases and test fixes #6883

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading