195 lines
4.5 KiB
Nix
195 lines
4.5 KiB
Nix
{
|
|
describe,
|
|
it,
|
|
...
|
|
}: let
|
|
html = import ../nixite/html.nix;
|
|
in
|
|
with html; [
|
|
(
|
|
describe "tag" [
|
|
(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 = "";};
|
|
}))
|
|
|
|
(it "keeps tag after setting attrs" (let
|
|
p = tag "p" {class = "";};
|
|
in {
|
|
actual = p.tag;
|
|
expected = "p";
|
|
}))
|
|
|
|
(it "makes a p tag" {
|
|
actual = tag "p" {} "Hello";
|
|
expected = {
|
|
tag = "p";
|
|
attrs = {};
|
|
child = "Hello";
|
|
};
|
|
removeDunders = true;
|
|
})
|
|
|
|
(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 "needs no args to make string" (let
|
|
p = tag "p";
|
|
in {
|
|
actual = toString p;
|
|
expected = "<p ></p>";
|
|
}))
|
|
|
|
(it "needs no content to make string" (let
|
|
p = tag "p";
|
|
in {
|
|
actual = toString (p {class = "foobar";});
|
|
expected = ''<p class="foobar"></p>'';
|
|
}))
|
|
|
|
(it "can take many sets of props" (let
|
|
p = tag "p";
|
|
in {
|
|
actual = toString (p {class = "foobar";} {style = "a style";});
|
|
expected = ''<p class="foobar" style="a style"></p>'';
|
|
}))
|
|
|
|
(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"));
|
|
}))
|
|
|
|
(it "throws with function child" {
|
|
actual = toString (tag "p" (i: ""));
|
|
throws = true;
|
|
})
|
|
|
|
(it "throws with a number" {
|
|
actual = toString (tag "p" 5);
|
|
throws = true;
|
|
})
|
|
|
|
(it "throws with a bool" {
|
|
actual = toString (tag "p" true);
|
|
throws = true;
|
|
})
|
|
|
|
(it "throws with a null" {
|
|
actual = toString (tag "p" null);
|
|
throws = true;
|
|
})
|
|
|
|
(it "concatinates classes" {
|
|
actual = toString (tag "p" {class = ["class1" "class2"];} "Hello");
|
|
expected = ''<p class="class1 class2">Hello</p>'';
|
|
})
|
|
|
|
(it "renders on / off attrs" {
|
|
actual = toString (tag "p" {
|
|
on = true;
|
|
off = false;
|
|
});
|
|
expected = "<p on></p>";
|
|
})
|
|
]
|
|
)
|
|
(
|
|
describe "addToHead" [
|
|
(it "adds a string to the head" (let
|
|
page = html.document {
|
|
head = ["foo"];
|
|
};
|
|
in {
|
|
actual = addToHead page ["bar"];
|
|
expected = html.document {
|
|
head = ["foo" "bar"];
|
|
};
|
|
asJSON = true;
|
|
}))
|
|
]
|
|
)
|
|
(
|
|
describe "document" [
|
|
(it "has a head and body" {
|
|
actual =
|
|
(document {
|
|
head = [];
|
|
})
|
|
.head;
|
|
expected = [];
|
|
})
|
|
(it "has a head and body" {
|
|
actual =
|
|
(document {
|
|
body = [];
|
|
})
|
|
.body;
|
|
expected = [];
|
|
})
|
|
(it "produces a valid html document" {
|
|
actual = document {
|
|
head = [];
|
|
body = [];
|
|
};
|
|
expected = ''
|
|
<!DOCTYPE html>
|
|
${(tag "html" [
|
|
(tag "head" [])
|
|
(tag "body" [])
|
|
])}
|
|
'';
|
|
asString = true;
|
|
})
|
|
]
|
|
)
|
|
]
|