nixite/testing/style.test.nix

227 lines
5.4 KiB
Nix
Raw Normal View History

2024-01-03 07:52:35 +00:00
{
describe,
it,
...
}: let
2023-12-31 03:08:05 +00:00
style = import ../nixite/style.nix;
2024-01-01 12:42:18 +00:00
elems = import ../nixite/elems.nix;
2024-01-03 13:19:41 +00:00
in [
(
describe "getStyle" [
(it "fetches empty style" (let
para = style.component elems.p "para" {};
in {
expected = {
"p" = {};
"p.para" = {};
};
actual = style.getStyle (para "");
}))
2024-01-03 13:19:41 +00:00
(it "fetches style" (let
attrs = {style = {foo = "bar";};};
para = style.component elems.p "para" attrs;
in {
expected = {
"p" = {};
"p.para" = attrs.style;
};
actual = style.getStyle (para "");
}))
2024-01-01 03:20:59 +00:00
2024-01-03 13:19:41 +00:00
(it "fetches style for class" (let
s = {foo = "bar";};
para = style.component elems.p "para" {style = s;};
in {
expected = {
"p" = {};
"p.para" = s;
};
actual = style.getStyle (para "");
}))
2024-01-04 22:37:43 +00:00
(it "separates media queries" (let
s = {
foo = "bar";
__mediaQueries = {
"(max-width: 500px)" = {
foo = "nar";
};
"(prefers-color-scheme: dark)" = {
foo = "blar";
};
};
};
para = style.component elems.p "para" {
style = s;
};
in {
expected = {
"p" = {};
"p.para" = {
foo = "bar";
};
"@media (max-width: 500px)" = {
"p.para" = {
foo = "nar";
};
};
"@media (prefers-color-scheme: dark)" = {
"p.para" = {
foo = "blar";
};
};
};
actual = style.getStyle (para "");
}))
2024-01-03 13:19:41 +00:00
]
)
(
describe "component" [
(it "applies class" (let
attrs = {style = {foo = "bar";};};
para = style.component elems.p "para" attrs;
in {
expected = ["para"];
actual = (para "").attrs.class;
}))
2024-01-01 04:41:56 +00:00
2024-01-03 13:19:41 +00:00
(it "applies classes from props" (let
attrs = {
style = {foo = "bar";};
class = ["other" "class"];
};
para = style.component elems.p "para" attrs;
in {
expected = ["para" "other" "class"];
actual = (para "").attrs.class;
}))
2024-01-01 04:41:56 +00:00
2024-01-03 13:19:41 +00:00
(it "extends styled tags classes" (let
s = {
"p" = {};
"div" = {};
"p.para" = {foo = "bar";};
"p.para.oof" = {oof = "yes";};
};
para = style.component elems.p "para" {style = s."p.para";};
para2 = style.component para "oof" {style = s."p.para.oof";};
in {
expected = ["para" "oof"];
actual = (para2 "").attrs.class;
}))
]
)
(
describe "getStyles" [
(it "fetches style recursively" (let
s = {
"p" = {};
"div" = {};
"p.para" = {foo = "bar";};
"div.link" = {this = "that";};
};
para = style.component elems.p "para" {style = s."p.para";};
div = style.component elems.div "link" {style = s."div.link";};
in {
expected = s;
actual = style.getStyles (para (div "hello"));
removeDunders = true;
}))
2024-01-01 04:41:56 +00:00
2024-01-03 13:19:41 +00:00
(it "fetches style recursively through lists" (let
s = {
"p" = {};
"div" = {};
"p.para" = {foo = "bar";};
"div.link" = {this = "that";};
};
para = style.component elems.p "para" {style = s."p.para";};
a = style.component elems.div "link" {style = s."div.link";};
in {
expected = s;
actual = style.getStyles (para [(a "hello")]);
removeDunders = true;
}))
2024-01-01 04:41:56 +00:00
2024-01-03 13:19:41 +00:00
(it "fetches style recursively with repeats" (let
s = {
"p" = {};
"div" = {};
"p.para" = {foo = "bar";};
"div.link" = {this = "that";};
};
para = style.component elems.p "para" {style = s."p.para";};
a = style.component elems.div "link" {style = s."div.link";};
in {
expected = s;
actual = style.getStyles (para [(a "hello") (a "hello")]);
removeDunders = true;
}))
2024-01-01 03:20:59 +00:00
2024-01-03 13:19:41 +00:00
(it "extends styled tags" (let
s = {
"p.para" = {foo = "bar";};
"p.oof" = {oof = "yes";};
};
para = style.component elems.p "para" {style = s."p.para";};
para2 = style.component para "oof" {style = s."p.oof";};
in {
expected = s;
actual = style.getStyles (para2 "");
removeDunders = true;
}))
]
)
(
describe "stylesToString" [
(it "converts styles to string" (let
s = {
"p" = {};
"p.para" = {foo = "bar";};
"a.link" = {this = "that";};
};
in {
expected = ''
a.link {
this: that;
}
p.para {
foo: bar;
}
'';
actual = style.stylesToString s;
}))
2024-01-04 22:37:43 +00:00
(it "converts nested styles to string" (let
s = {
"p" = {};
"p.para" = {foo = "bar";};
"a.link" = {this = "that";};
"@media blah" = {
"a.link" = {
this = "not that";
};
};
};
in {
expected = ''
a.link {
this: that;
}
p.para {
foo: bar;
}
@media blah {
a.link {
this: not that;
}
}
'';
actual = style.stylesToString s;
}))
2024-01-03 13:19:41 +00:00
]
)
]