test: update tests for new features and fix test expectations
Some checks failed
Deploy static content to Pages / deploy (push) Has been cancelled
Some checks failed
Deploy static content to Pages / deploy (push) Has been cancelled
This commit is contained in:
@@ -50,9 +50,7 @@ describe("Renderer Module", () => {
|
|||||||
|
|
||||||
test("should expand module and show lessons on click", () => {
|
test("should expand module and show lessons on click", () => {
|
||||||
const container = document.getElementById("module-list");
|
const container = document.getElementById("module-list");
|
||||||
const modules = [
|
const modules = [{ id: "mod1", title: "Module 1", lessons: [{ title: "Lesson A" }, { title: "Lesson B" }] }];
|
||||||
{ id: "mod1", title: "Module 1", lessons: [{ title: "Lesson A" }, { title: "Lesson B" }] }
|
|
||||||
];
|
|
||||||
const onSelectLesson = vi.fn();
|
const onSelectLesson = vi.fn();
|
||||||
|
|
||||||
renderModuleList(container, modules, vi.fn(), onSelectLesson);
|
renderModuleList(container, modules, vi.fn(), onSelectLesson);
|
||||||
|
|||||||
@@ -232,9 +232,7 @@ describe("HTML Validator", () => {
|
|||||||
const userHtml = "<p>Hello world</p>";
|
const userHtml = "<p>Hello world</p>";
|
||||||
const lesson = {
|
const lesson = {
|
||||||
mode: "html",
|
mode: "html",
|
||||||
validations: [
|
validations: [{ type: "element_exists", value: "p", message: "Add a paragraph" }]
|
||||||
{ type: "element_exists", value: "p", message: "Add a paragraph" }
|
|
||||||
]
|
|
||||||
};
|
};
|
||||||
|
|
||||||
const result = validateUserCode(userHtml, lesson);
|
const result = validateUserCode(userHtml, lesson);
|
||||||
@@ -242,9 +240,7 @@ describe("HTML Validator", () => {
|
|||||||
|
|
||||||
const failResult = validateUserCode(userHtml, {
|
const failResult = validateUserCode(userHtml, {
|
||||||
mode: "html",
|
mode: "html",
|
||||||
validations: [
|
validations: [{ type: "element_exists", value: "div", message: "Add a div" }]
|
||||||
{ type: "element_exists", value: "div", message: "Add a div" }
|
|
||||||
]
|
|
||||||
});
|
});
|
||||||
expect(failResult.isValid).toBe(false);
|
expect(failResult.isValid).toBe(false);
|
||||||
expect(failResult.message).toBe("Add a div");
|
expect(failResult.message).toBe("Add a div");
|
||||||
@@ -254,9 +250,7 @@ describe("HTML Validator", () => {
|
|||||||
const userHtml = "<ul><li>One</li><li>Two</li><li>Three</li></ul>";
|
const userHtml = "<ul><li>One</li><li>Two</li><li>Three</li></ul>";
|
||||||
const lesson = {
|
const lesson = {
|
||||||
mode: "html",
|
mode: "html",
|
||||||
validations: [
|
validations: [{ type: "element_count", value: { selector: "li", count: 3 }, message: "Need 3 items" }]
|
||||||
{ type: "element_count", value: { selector: "li", count: 3 }, message: "Need 3 items" }
|
|
||||||
]
|
|
||||||
};
|
};
|
||||||
|
|
||||||
const result = validateUserCode(userHtml, lesson);
|
const result = validateUserCode(userHtml, lesson);
|
||||||
@@ -264,9 +258,7 @@ describe("HTML Validator", () => {
|
|||||||
|
|
||||||
const failLesson = {
|
const failLesson = {
|
||||||
mode: "html",
|
mode: "html",
|
||||||
validations: [
|
validations: [{ type: "element_count", value: { selector: "li", count: 5 }, message: "Need 5 items" }]
|
||||||
{ type: "element_count", value: { selector: "li", count: 5 }, message: "Need 5 items" }
|
|
||||||
]
|
|
||||||
};
|
};
|
||||||
const failResult = validateUserCode(userHtml, failLesson);
|
const failResult = validateUserCode(userHtml, failLesson);
|
||||||
expect(failResult.isValid).toBe(false);
|
expect(failResult.isValid).toBe(false);
|
||||||
@@ -276,9 +268,7 @@ describe("HTML Validator", () => {
|
|||||||
const userHtml = "<div><span>A</span><span>B</span></div>";
|
const userHtml = "<div><span>A</span><span>B</span></div>";
|
||||||
const lesson = {
|
const lesson = {
|
||||||
mode: "html",
|
mode: "html",
|
||||||
validations: [
|
validations: [{ type: "element_count", value: { selector: "span", min: 2 }, message: "Need at least 2 spans" }]
|
||||||
{ type: "element_count", value: { selector: "span", min: 2 }, message: "Need at least 2 spans" }
|
|
||||||
]
|
|
||||||
};
|
};
|
||||||
|
|
||||||
const result = validateUserCode(userHtml, lesson);
|
const result = validateUserCode(userHtml, lesson);
|
||||||
@@ -289,9 +279,7 @@ describe("HTML Validator", () => {
|
|||||||
const userHtml = '<input type="email" required>';
|
const userHtml = '<input type="email" required>';
|
||||||
const lesson = {
|
const lesson = {
|
||||||
mode: "html",
|
mode: "html",
|
||||||
validations: [
|
validations: [{ type: "attribute_value", value: { selector: "input", attr: "type", value: "email" } }]
|
||||||
{ type: "attribute_value", value: { selector: "input", attr: "type", value: "email" } }
|
|
||||||
]
|
|
||||||
};
|
};
|
||||||
|
|
||||||
const result = validateUserCode(userHtml, lesson);
|
const result = validateUserCode(userHtml, lesson);
|
||||||
@@ -300,9 +288,7 @@ describe("HTML Validator", () => {
|
|||||||
// Test boolean attribute (required)
|
// Test boolean attribute (required)
|
||||||
const boolLesson = {
|
const boolLesson = {
|
||||||
mode: "html",
|
mode: "html",
|
||||||
validations: [
|
validations: [{ type: "attribute_value", value: { selector: "input", attr: "required", value: true } }]
|
||||||
{ type: "attribute_value", value: { selector: "input", attr: "required", value: true } }
|
|
||||||
]
|
|
||||||
};
|
};
|
||||||
const boolResult = validateUserCode(userHtml, boolLesson);
|
const boolResult = validateUserCode(userHtml, boolLesson);
|
||||||
expect(boolResult.isValid).toBe(true);
|
expect(boolResult.isValid).toBe(true);
|
||||||
@@ -312,9 +298,7 @@ describe("HTML Validator", () => {
|
|||||||
const userHtml = "<form><label>Name</label><input></form>";
|
const userHtml = "<form><label>Name</label><input></form>";
|
||||||
const lesson = {
|
const lesson = {
|
||||||
mode: "html",
|
mode: "html",
|
||||||
validations: [
|
validations: [{ type: "parent_child", value: { parent: "form", child: "input" }, message: "Input should be inside form" }]
|
||||||
{ type: "parent_child", value: { parent: "form", child: "input" }, message: "Input should be inside form" }
|
|
||||||
]
|
|
||||||
};
|
};
|
||||||
|
|
||||||
const result = validateUserCode(userHtml, lesson);
|
const result = validateUserCode(userHtml, lesson);
|
||||||
@@ -329,9 +313,7 @@ describe("HTML Validator", () => {
|
|||||||
const userHtml = "<button>Submit</button>";
|
const userHtml = "<button>Submit</button>";
|
||||||
const lesson = {
|
const lesson = {
|
||||||
mode: "html",
|
mode: "html",
|
||||||
validations: [
|
validations: [{ type: "element_text", value: { selector: "button", text: "Submit" } }]
|
||||||
{ type: "element_text", value: { selector: "button", text: "Submit" } }
|
|
||||||
]
|
|
||||||
};
|
};
|
||||||
|
|
||||||
const result = validateUserCode(userHtml, lesson);
|
const result = validateUserCode(userHtml, lesson);
|
||||||
@@ -339,9 +321,7 @@ describe("HTML Validator", () => {
|
|||||||
|
|
||||||
const failLesson = {
|
const failLesson = {
|
||||||
mode: "html",
|
mode: "html",
|
||||||
validations: [
|
validations: [{ type: "element_text", value: { selector: "button", text: "Cancel" }, message: "Button should say Cancel" }]
|
||||||
{ type: "element_text", value: { selector: "button", text: "Cancel" }, message: "Button should say Cancel" }
|
|
||||||
]
|
|
||||||
};
|
};
|
||||||
const failResult = validateUserCode(userHtml, failLesson);
|
const failResult = validateUserCode(userHtml, failLesson);
|
||||||
expect(failResult.isValid).toBe(false);
|
expect(failResult.isValid).toBe(false);
|
||||||
@@ -351,9 +331,7 @@ describe("HTML Validator", () => {
|
|||||||
const userHtml = '<div class="container">Content</div>';
|
const userHtml = '<div class="container">Content</div>';
|
||||||
const lesson = {
|
const lesson = {
|
||||||
mode: "html",
|
mode: "html",
|
||||||
validations: [
|
validations: [{ type: "contains", value: "container" }]
|
||||||
{ type: "contains", value: "container" }
|
|
||||||
]
|
|
||||||
};
|
};
|
||||||
|
|
||||||
const result = validateUserCode(userHtml, lesson);
|
const result = validateUserCode(userHtml, lesson);
|
||||||
|
|||||||
Reference in New Issue
Block a user