2023-12-31 00:24:48 +00:00
|
|
|
let
|
|
|
|
html = import ../nixite/html.nix;
|
|
|
|
it = import ./it.nix;
|
2023-12-31 21:33:42 +00:00
|
|
|
in with html; [
|
2024-01-01 03:20:59 +00:00
|
|
|
|
|
|
|
(it "keeps info in the tag" (let p = tag "p";
|
|
|
|
in {
|
|
|
|
actual = p.tag;
|
|
|
|
expected = "p";
|
|
|
|
}))
|
|
|
|
|
|
|
|
(it "keeps attr info in the tag" (let p = tag "p" { class = ""; };
|
|
|
|
in {
|
|
|
|
actual = p.attrs;
|
|
|
|
expected = { class = ""; };
|
|
|
|
}))
|
|
|
|
|
2024-01-01 04:41:56 +00:00
|
|
|
(it "keeps tag after setting attrs" (let p = tag "p" { class = ""; };
|
|
|
|
in {
|
|
|
|
actual = p.tag;
|
|
|
|
expected = "p";
|
|
|
|
}))
|
|
|
|
|
2023-12-31 21:33:42 +00:00
|
|
|
(it "makes a p tag" {
|
|
|
|
actual = tag "p" { } "Hello";
|
|
|
|
expected = {
|
|
|
|
tag = "p";
|
|
|
|
attrs = { };
|
|
|
|
child = "Hello";
|
|
|
|
__toString = toHTML;
|
|
|
|
};
|
|
|
|
})
|
2023-12-31 00:24:48 +00:00
|
|
|
|
2024-01-01 04:41:56 +00:00
|
|
|
(it "makes element"
|
|
|
|
(let para = (tag "p" {});
|
|
|
|
in {
|
|
|
|
expected = "p";
|
|
|
|
actual = para.tag;
|
|
|
|
}))
|
|
|
|
|
|
|
|
(it "keeps attrs on element"
|
|
|
|
(let
|
|
|
|
attrs = { style = { foo = "bar"; }; };
|
|
|
|
para = (tag "p" attrs);
|
|
|
|
in {
|
|
|
|
expected = attrs;
|
|
|
|
actual = para.attrs;
|
|
|
|
}))
|
|
|
|
|
|
|
|
(it "makes renderable element"
|
|
|
|
(let
|
|
|
|
attrs = { style = { foo = "bar"; }; };
|
|
|
|
para = (tag "p" attrs);
|
|
|
|
in {
|
|
|
|
expected = "<p ></p>";
|
|
|
|
actual = toString ( para "" );
|
|
|
|
}))
|
|
|
|
|
|
|
|
(it "keeps tag"
|
|
|
|
(let
|
|
|
|
attrs = { style = { foo = "bar"; }; };
|
|
|
|
para = (tag "p" attrs);
|
|
|
|
in {
|
|
|
|
expected = "p";
|
|
|
|
actual = ( para "" ).tag;
|
|
|
|
}))
|
|
|
|
|
|
|
|
(it "keeps style"
|
|
|
|
(let
|
|
|
|
attrs = { style = { foo = "bar"; }; };
|
|
|
|
para = (tag "p" attrs);
|
|
|
|
in {
|
|
|
|
expected = { foo = "bar"; };
|
|
|
|
actual = ( para "" ).attrs.style;
|
|
|
|
}))
|
|
|
|
|
|
|
|
(it "works recursively"
|
|
|
|
(let
|
|
|
|
attrs = { style = { foo = "bar"; }; };
|
|
|
|
para = (tag "p" attrs);
|
|
|
|
a = (tag "a" {});
|
|
|
|
in {
|
|
|
|
expected = "<p ><a >hello</a></p>";
|
|
|
|
actual = toString ( para (a "hello") );
|
|
|
|
}))
|
|
|
|
|
2023-12-31 21:33:42 +00:00
|
|
|
(it "concatinates classes" {
|
|
|
|
actual = toString (tag "p" { class = [ "class1" "class2" ]; } "Hello");
|
|
|
|
expected = ''<p class="class1 class2">Hello</p>'';
|
|
|
|
})
|
2023-12-31 03:08:05 +00:00
|
|
|
|
2023-12-31 21:33:42 +00:00
|
|
|
(it "applies style" (let page = tag "html" { } [ (tag "head" { } [ "foo" ]) ];
|
|
|
|
in {
|
|
|
|
actual = addToHead page [ "bar" ];
|
|
|
|
expected = {
|
|
|
|
tag = "html";
|
|
|
|
attrs = { };
|
|
|
|
child = [ (tag "head" { } [ "foo" "bar" ]) ];
|
|
|
|
__toString = toHTML;
|
|
|
|
};
|
|
|
|
}))
|
|
|
|
]
|