gradio/js/app/test/custom_css.spec.ts
Hannah 46b45683e1
Allow applying @media, @keyframes and @import in custom CSS (#7395)
* allow @media and @keyframes in custom CSS

* add changeset

* demo tweak

* formatting

* fix

* tweak

* add .dark test

* formatting

* add font-face test

* support @import statements

* add changeset

* tweak

* fix test

---------

Co-authored-by: gradio-pr-bot <gradio-pr-bot@users.noreply.github.com>
2024-02-13 00:39:30 +01:00

72 lines
1.9 KiB
TypeScript

import { test, expect } from "@gradio/tootils";
test("renders the correct elements", async ({ page }) => {
await expect(page.getByTestId("markdown")).toHaveCount(2);
});
test("applies the custom CSS styles", async ({ page }) => {
// Test for CSSKeyframesRule
const animationName = await page
.locator(".cool-col")
.evaluate((node) => getComputedStyle(node).animationName);
expect(animationName).toBe("animation");
// Test for CSSMediaRule and CSSStyleRule
await page.setViewportSize({ width: 500, height: 720 });
await expect(page.locator(".markdown").nth(1)).toHaveCSS(
"background-color",
"rgb(0, 0, 255)"
);
await expect(page.locator(".markdown p")).toHaveCSS(
"color",
"rgb(173, 216, 230)"
);
await page.setViewportSize({ width: 1280, height: 720 });
await expect(page.locator(".markdown").nth(1)).toHaveCSS(
"background-color",
"rgb(173, 216, 230)"
);
await expect(page.locator(".markdown p")).toHaveCSS(
"color",
"rgb(65, 105, 225)"
);
});
test("applies the custom font family", async ({ page }) => {
await expect(
page.getByRole("heading", { name: "Gradio Demo with Custom CSS" })
).toHaveCSS("font-family", "test-font");
});
test("applies resources from the @import rule", async ({ page }) => {
await expect(page.getByText("Resize the browser window to")).toHaveCSS(
"font-family",
'"Protest Riot", sans-serif'
);
});
test(".dark styles are applied corrently", async ({ page }) => {
await page.emulateMedia({ colorScheme: "dark" });
await expect(page.locator(".markdown").nth(1)).toHaveCSS(
"background-color",
"rgb(255, 192, 203)"
);
await expect(page.locator(".darktest h3")).toHaveCSS(
"color",
"rgb(255, 255, 0)"
);
await page.emulateMedia({ colorScheme: "light" });
await expect(page.locator(".markdown").nth(1)).toHaveCSS(
"background-color",
"rgb(173, 216, 230)"
);
await expect(page.locator(".darktest h3")).toHaveCSS(
"color",
"rgb(31, 41, 55)"
);
});