nixite/testing/style.test.nix

101 lines
2.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" {style = {
2023-12-31 03:08:05 +00:00
some-style = "some value";
};})
(style.styled "div" "div" {class = ["something"]; style = {
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"];
style = {
s = "yes";
};})
(style.styled "foobar" "div" {
class = ["foo" "bar"];
style = {
something = "something";
};
} )
2023-12-31 03:08:05 +00:00
(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";
asString = true;
2023-12-31 03:08:41 +00:00
})
(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";
asString = true;
})
2023-12-31 03:08:41 +00:00
(it "makes a component" {
expected = html.tag "div" {class = ["something"];} "foobar";
actual = my.div {} "foobar";
asString = true;
2023-12-31 03:08:41 +00:00
})
(it "makes special components" {
expected = html.tag "div" {
id = "s";
class = ["something"];
} "foobar";
actual = my.s {} "foobar";
asString = true;
2023-12-31 03:08:41 +00:00
})
(it "works on many classes" {
expected = html.tag "div" {class = ["foo" "bar"];} "foobar";
actual = my.foobar {} "foobar";
asString = true;
2023-12-31 03:08:41 +00:00
})
2023-12-31 03:41:46 +00:00
(it "does custom behavour" {
expected = (html.tag "ul" {
2023-12-31 06:59:23 +00:00
__ = "";
class = ["list"];
} [
(html.tag "li" {} "1")
(html.tag "li" {} "2")
]);
actual = (my.list {} ["1" "2"]);
asString = true;
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";
asString = true;
2023-12-31 03:08:41 +00:00
})
(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;
})
]