nixite/testing/style.test.nix

91 lines
2 KiB
Nix
Raw Normal View History

2023-12-31 03:08:05 +00:00
let
style = import ../nixite/style.nix;
html = import ../nixite/html.nix;
it = import ./it.nix;
my =
(style.styled "p" "p" {} {
some-style = "some value";
})
2023-12-31 03:08:41 +00:00
(style.styled "div" "div" {class = ["something"];} {
2023-12-31 03:08:05 +00:00
this = "that";
})
2023-12-31 03:08:41 +00:00
(style.styled "s" "div" {
id = "s";
class = ["something"];
} {
s = "yes";
})
(style.styled "foobar" "div" {class = ["foo" "bar"];} {
2023-12-31 03:08:05 +00:00
something = "something";
})
(style.style "body" {
foo = "bar";
2023-12-31 03:41:46 +00:00
})
(style.styled "list" "ul" {
__child = child:
assert builtins.isList child; (map (html.tag "li" {}) child);
} {});
2023-12-31 03:08:05 +00:00
in [
2023-12-31 03:08:41 +00:00
(it "makes a p component" {
2023-12-31 06:59:23 +00:00
expected = html.tag "p" {class = ["p"];} "yes";
2023-12-31 03:08:41 +00:00
actual = my.p {} "yes";
})
(it "does not error without attrs" {
2023-12-31 06:59:23 +00:00
expected = html.tag "p" {class = ["p"];} "yes";
actual = my.p "yes";
})
2023-12-31 03:08:41 +00:00
(it "makes a component" {
expected = html.tag "div" {class = ["something"];} "foobar";
actual = my.div {} "foobar";
})
(it "makes special components" {
expected = html.tag "div" {
id = "s";
class = ["something"];
} "foobar";
actual = my.s {} "foobar";
})
(it "works on many classes" {
expected = html.tag "div" {class = ["foo" "bar"];} "foobar";
actual = my.foobar {} "foobar";
})
2023-12-31 03:41:46 +00:00
(it "does custom behavour" {
2023-12-31 06:59:23 +00:00
expected = toString (html.tag "ul" {
__ = "";
class = ["list"];
} [
(html.tag "li" {} "1")
(html.tag "li" {} "2")
]);
actual = toString (my.list {} ["1" "2"]);
2023-12-31 03:41:46 +00:00
})
2023-12-31 03:08:41 +00:00
(it "combines attrs" {
expected = html.tag "div" {
id = "foo";
class = ["something"];
} "foobar";
actual = my.div {id = "foo";} "foobar";
})
(it "makes a style" {
expected = ''
2023-12-31 06:59:23 +00:00
p.p {
2023-12-31 03:08:41 +00:00
some-style: some value;
}
div.something {
this: that;
}
div.something#s {
s: yes;
}
div.foo.bar {
something: something;
}
body {
foo: bar;
}
'';
actual = my.style;
})
]