-
Notifications
You must be signed in to change notification settings - Fork 79
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
203 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
import { describe, expect, it } from "vitest"; | ||
import { | ||
getJsonSchemaValidator, | ||
validatorCssClassname, | ||
validatorCssSize, | ||
} from "./validators"; | ||
|
||
describe("validators", () => { | ||
describe("CSS Classname", () => { | ||
const validator = getJsonSchemaValidator(validatorCssClassname); | ||
|
||
it.each([ | ||
"", | ||
"foo bar", | ||
"foo", | ||
"foo bar baz", | ||
" foo bar ", | ||
"foo123 bar_baz", | ||
"class1 class2", | ||
"foo-bar", | ||
"foo bar-baz", | ||
])("should be valid class names: %s", (value) => { | ||
expect(validator(value)).toBe(true); | ||
}); | ||
|
||
it.each(["123", "-abc"])( | ||
"should be invalid class names: %s", | ||
(value) => { | ||
expect(validator(value)).toBe(false); | ||
}, | ||
); | ||
}); | ||
|
||
describe("CSS size", () => { | ||
const validator = getJsonSchemaValidator(validatorCssSize); | ||
|
||
it.each(["", "12px", "1rem", "2vh"])( | ||
"should be valid size: %s", | ||
(value) => { | ||
expect(validator(value)).toBe(true); | ||
}, | ||
); | ||
|
||
it.each(["px", "vh"])("should be invalid class names: %s", (value) => { | ||
expect(validator(value)).toBe(false); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
import { test, expect } from "@playwright/test"; | ||
|
||
test.describe("Builder field validation", () => { | ||
let url: string; | ||
|
||
test.beforeAll(async ({ request }) => { | ||
const response = await request.post(`/preset/section`); | ||
expect(response.ok()).toBeTruthy(); | ||
({ url } = await response.json()); | ||
}); | ||
|
||
test.afterAll(async ({ request }) => { | ||
await request.delete(url); | ||
}); | ||
|
||
test.beforeEach(async ({ page }) => { | ||
await page.goto(url, { waitUntil: "domcontentloaded" }); | ||
test.setTimeout(5000); | ||
}); | ||
|
||
test("should display error for invalid button fields", async ({ page }) => { | ||
await page | ||
.locator(`.BuilderSidebarToolkit [data-component-type="button"]`) | ||
.dragTo(page.locator(".CoreSection")); | ||
await page.locator(`button.CoreButton.component`).click(); | ||
|
||
// is disabled | ||
|
||
const isDisabledInput = page.locator( | ||
'.BuilderFieldsText[data-automation-key="isDisabled"] input', | ||
); | ||
|
||
await isDisabledInput.fill("maybe"); | ||
expect(await isDisabledInput.getAttribute("aria-invalid")).toBe("true"); | ||
|
||
await isDisabledInput.fill("yes"); | ||
expect(await isDisabledInput.getAttribute("aria-invalid")).toBe("false"); | ||
|
||
// css classes | ||
|
||
const cssClasses = page.locator( | ||
'.BuilderFieldsText[data-automation-key="cssClasses"] input', | ||
); | ||
await cssClasses.fill("1234"); | ||
expect(await cssClasses.getAttribute("aria-invalid")).toBe("true"); | ||
|
||
await cssClasses.fill("class1 class2"); | ||
expect(await cssClasses.getAttribute("aria-invalid")).toBe("false"); | ||
}); | ||
|
||
test("should display error for invalid multiselectinput fields", async ({ | ||
page, | ||
}) => { | ||
await page | ||
.locator( | ||
`.BuilderSidebarToolkit [data-component-type="multiselectinput"]`, | ||
) | ||
.dragTo(page.locator(".CoreSection")); | ||
await page.locator(`.CoreMultiselectInput.component`).click(); | ||
|
||
// maximum count | ||
|
||
const maximunCountInput = page.locator( | ||
'.BuilderFieldsText[data-automation-key="maximumCount"] input', | ||
); | ||
|
||
await maximunCountInput.fill("-1"); | ||
expect(await maximunCountInput.getAttribute("aria-invalid")).toBe("true"); | ||
|
||
await maximunCountInput.fill("2"); | ||
expect(await maximunCountInput.getAttribute("aria-invalid")).toBe("false"); | ||
|
||
// options | ||
|
||
await page.locator(".BuilderFieldsOptions button").nth(1).click(); | ||
|
||
const optionsTextarea = page.locator( | ||
'.BuilderFieldsObject[data-automation-key="options"] textarea', | ||
); | ||
await optionsTextarea.fill(JSON.stringify(true)); | ||
expect(await optionsTextarea.getAttribute("aria-invalid")).toBe("true"); | ||
|
||
await optionsTextarea.fill(JSON.stringify({ a: "A", b: "B" })); | ||
expect(await optionsTextarea.getAttribute("aria-invalid")).toBe("false"); | ||
}); | ||
}); |