|
1 | | -import { test, expect } from "@jest/globals"; |
| 1 | +import { test, expect, describe } from "@jest/globals"; |
2 | 2 | import type { Pages, Prop } from "@webstudio-is/sdk"; |
3 | | -import { normalizeProps } from "./props"; |
| 3 | +import { isAttributeNameSafe, normalizeProps } from "./props"; |
4 | 4 |
|
5 | 5 | const pagesBase: Pages = { |
6 | 6 | meta: {}, |
@@ -289,3 +289,30 @@ test("normalize page prop with path and hash into string", () => { |
289 | 289 | idProp, |
290 | 290 | ]); |
291 | 291 | }); |
| 292 | + |
| 293 | +describe("isAttributeNameSafe", () => { |
| 294 | + test("should return true for valid attribute names", () => { |
| 295 | + expect(isAttributeNameSafe("data-test")).toBe(true); |
| 296 | + expect(isAttributeNameSafe("aria-label")).toBe(true); |
| 297 | + expect(isAttributeNameSafe("class")).toBe(true); |
| 298 | + expect(isAttributeNameSafe("ns:class")).toBe(true); |
| 299 | + }); |
| 300 | + |
| 301 | + test("should return false for invalid attribute names", () => { |
| 302 | + expect(isAttributeNameSafe("123class")).toBe(false); |
| 303 | + expect(isAttributeNameSafe("class.name")).toBe(false); |
| 304 | + expect(isAttributeNameSafe(":bad")).toBe(false); |
| 305 | + expect(isAttributeNameSafe(" ")).toBe(false); |
| 306 | + expect(isAttributeNameSafe("hello world")).toBe(false); |
| 307 | + }); |
| 308 | + |
| 309 | + test("should return true for cached valid attribute names", () => { |
| 310 | + isAttributeNameSafe("data-cached"); |
| 311 | + expect(isAttributeNameSafe("data-cached")).toBe(true); |
| 312 | + }); |
| 313 | + |
| 314 | + test("should return false for cached invalid attribute names", () => { |
| 315 | + isAttributeNameSafe("1-invalid-cached"); |
| 316 | + expect(isAttributeNameSafe("1-invalid-cached")).toBe(false); |
| 317 | + }); |
| 318 | +}); |
0 commit comments