local t = require "tests.testutils"
local _, T, html = t.setup "html"
local a = require "lego.html.attribute"
local h = require "lego.html"
html["simple html"] = function()
local node = h.el("div", {}, { h.text "hello" })
t.eq(h.render(node), "
hello
")
end
html["simple html with attrs"] = function()
local node = h.div({ a.attr("class", "some classes") }, { h.text "string" })
t.eq(h.render(node), [[string
]])
end
html["self-closing tag"] = function()
local node = h.el("img", { a.attr("src", "image.png"), a.attr("alt", "Alt text") }, {})
t.eq(h.render(node), [[
]])
end
html["nested html"] = function()
local node = h.div({ a.class "container" }, {
h.el("h1", {}, { h.text "Title" }),
h.p({}, { h.text "Paragraph" }),
})
t.eq(h.render(node), [[]])
end
html["even more nested html"] = function()
local node = h.div({ a.class "container" }, {
h.el("h1", {}, { h.text "Title" }),
h.div({}, {
h.p({}, {
h.text "text",
h.a({ a.href "google.com" }, { h.text "google" }),
}),
}),
})
t.eq(
h.render(node),
[[]]
)
end
html["simple page"] = function()
local node = h.el("html", { a.attr("lang", "en") }, {
h.el("head", {}, {
h.el("title", {}, { h.text "My Page" }),
}),
h.el("body", {}, {
h.el("h1", {}, { h.text "Welcome" }),
h.p({}, { h.text "This is a basic HTML page." }),
}),
})
t.eq(
h.render_page(node),
[[My PageWelcome
This is a basic HTML page.
]]
)
end
html["row html can be 'embedded'"] = function()
local node = h.el("html", {}, {
h.el("head", {}, { h.el("title", {}, {
h.text "My Page",
}) }),
h.el("body", {}, {
h.raw "",
}),
})
t.eq(
h.render(node),
"My Page"
)
end
return T