nixite/testing/style.test.nix

149 lines
3.5 KiB
Nix
Raw Normal View History

2023-12-31 03:08:05 +00:00
let
style = import ../nixite/style.nix;
2024-01-01 12:42:18 +00:00
elems = import ../nixite/elems.nix;
2023-12-31 03:08:05 +00:00
it = import ./it.nix;
2024-01-01 03:20:59 +00:00
in [
2024-01-01 12:42:18 +00:00
(it "fetches empty style" (let para = (style.component elems.p "para" { });
2024-01-01 03:20:59 +00:00
in {
expected = {
"p" = { };
"p.para" = { };
};
2024-01-01 06:33:57 +00:00
actual = style.getStyle (para "");
2024-01-01 03:20:59 +00:00
}))
2024-01-01 06:33:57 +00:00
(it "fetches style" (let
attrs = { style = { foo = "bar"; }; };
2024-01-01 12:42:18 +00:00
para = (style.component elems.p "para" attrs);
2024-01-01 03:20:59 +00:00
in {
expected = {
"p" = { };
"p.para" = attrs.style;
};
2024-01-01 06:33:57 +00:00
actual = style.getStyle (para "");
2024-01-01 03:20:59 +00:00
}))
2024-01-01 06:33:57 +00:00
(it "appliess class" (let
attrs = { style = { foo = "bar"; }; };
2024-01-01 12:42:18 +00:00
para = (style.component elems.p "para" attrs);
2024-01-01 06:33:57 +00:00
in {
expected = [ "para" ];
actual = (para "").attrs.class;
2024-01-01 04:41:56 +00:00
}))
2024-01-01 06:33:57 +00:00
(it "applies classes from props" (let
attrs = {
style = { foo = "bar"; };
class = [ "other" "class" ];
};
2024-01-01 12:42:18 +00:00
para = (style.component elems.p "para" attrs);
2024-01-01 06:33:57 +00:00
in {
expected = [ "para" "other" "class" ];
actual = (para "").attrs.class;
2024-01-01 04:41:56 +00:00
}))
2024-01-01 06:33:57 +00:00
(it "fetches style for class" (let
s = { foo = "bar"; };
2024-01-01 12:42:18 +00:00
para = (style.component elems.p "para" { style = s; });
2024-01-01 06:33:57 +00:00
in {
expected = {
"p" = { };
"p.para" = s;
};
2024-01-01 06:33:57 +00:00
actual = style.getStyle (para "");
2024-01-01 04:41:56 +00:00
}))
2024-01-01 06:33:57 +00:00
(it "fetches style recursively" (let
s = {
"p" = { };
"div" = { };
2024-01-01 06:33:57 +00:00
"p.para" = { foo = "bar"; };
2024-01-01 12:42:18 +00:00
"div.link" = { this = "that"; };
2024-01-01 06:33:57 +00:00
};
2024-01-01 12:42:18 +00:00
para = (style.component elems.p "para" { style = s."p.para"; });
div = (style.component elems.div "link" { style = s."div.link"; });
2024-01-01 04:41:56 +00:00
in {
2024-01-01 06:33:57 +00:00
expected = s;
2024-01-01 12:42:18 +00:00
actual = style.getStyles (para (div "hello"));
2024-01-01 06:33:57 +00:00
removeDunders = true;
2024-01-01 04:41:56 +00:00
}))
2024-01-01 06:33:57 +00:00
(it "fetches style recursively through lists" (let
s = {
"p" = { };
"div" = { };
2024-01-01 06:33:57 +00:00
"p.para" = { foo = "bar"; };
2024-01-01 12:42:18 +00:00
"div.link" = { this = "that"; };
2024-01-01 06:33:57 +00:00
};
2024-01-01 12:42:18 +00:00
para = (style.component elems.p "para" { style = s."p.para"; });
a = (style.component elems.div "link" { style = s."div.link"; });
2024-01-01 06:33:57 +00:00
in {
expected = s;
actual = style.getStyles (para [ (a "hello") ]);
removeDunders = true;
2024-01-01 04:41:56 +00:00
}))
2024-01-01 03:20:59 +00:00
2024-01-01 06:33:57 +00:00
(it "fetches style recursively with repeats" (let
s = {
"p" = { };
"div" = { };
2024-01-01 06:33:57 +00:00
"p.para" = { foo = "bar"; };
2024-01-01 12:42:18 +00:00
"div.link" = { this = "that"; };
2024-01-01 06:33:57 +00:00
};
2024-01-01 12:42:18 +00:00
para = (style.component elems.p "para" { style = s."p.para"; });
a = (style.component elems.div "link" { style = s."div.link"; });
2024-01-01 03:20:59 +00:00
in {
2024-01-01 06:33:57 +00:00
expected = s;
actual = style.getStyles (para [ (a "hello") (a "hello") ]);
removeDunders = true;
2024-01-01 03:20:59 +00:00
}))
2024-01-01 06:33:57 +00:00
(it "converts styles to string" (let
s = {
"p" = { };
2024-01-01 03:20:59 +00:00
"p.para" = { foo = "bar"; };
2024-01-01 06:33:57 +00:00
"a.link" = { this = "that"; };
2024-01-01 03:20:59 +00:00
};
2024-01-01 06:33:57 +00:00
in {
expected = ''
a.link {
this: that;
}
p.para {
foo: bar;
}
'';
actual = style.stylesToString s;
2024-01-01 03:20:59 +00:00
}))
2024-01-01 06:33:57 +00:00
(it "extends styled tags" (let
s = {
"p.para" = { foo = "bar"; };
2024-01-01 12:42:18 +00:00
"p.oof" = { oof = "yes"; };
2024-01-01 06:33:57 +00:00
};
2024-01-01 12:42:18 +00:00
para = (style.component elems.p "para" { style = s."p.para"; });
para2 = (style.component para "oof" { style = s."p.oof"; });
2024-01-01 06:33:57 +00:00
in {
expected = s;
actual = style.getStyles (para2 "");
removeDunders = true;
}))
2024-01-01 04:41:56 +00:00
2024-01-01 06:33:57 +00:00
(it "extends styled tags classes" (let
s = {
"p" = { };
"div" = { };
2024-01-01 06:33:57 +00:00
"p.para" = { foo = "bar"; };
"p.para.oof" = { oof = "yes"; };
};
2024-01-01 12:42:18 +00:00
para = (style.component elems.p "para" { style = s."p.para"; });
para2 = (style.component para "oof" { style = s."p.para.oof"; });
2024-01-01 06:33:57 +00:00
in {
expected = [ "para" "oof" ];
actual = (para2 "").attrs.class;
}))
2024-01-01 04:41:56 +00:00
2023-12-31 03:08:41 +00:00
]