nixite/testing/style.test.nix

146 lines
3.4 KiB
Nix
Raw Normal View History

2024-01-02 10:53:45 +00:00
{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-01 03:20:59 +00:00
in [
2024-01-02 10:53:45 +00:00
(it "fetches empty style" (let
para = style.component elems.p "para" {};
2024-01-01 03:20:59 +00:00
in {
expected = {
2024-01-02 10:53:45 +00:00
"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
2024-01-02 10:53:45 +00:00
attrs = {style = {foo = "bar";};};
para = style.component elems.p "para" attrs;
2024-01-01 03:20:59 +00:00
in {
expected = {
2024-01-02 10:53:45 +00:00
"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
2024-01-02 10:53:45 +00:00
attrs = {style = {foo = "bar";};};
para = style.component elems.p "para" attrs;
2024-01-01 06:33:57 +00:00
in {
2024-01-02 10:53:45 +00:00
expected = ["para"];
2024-01-01 06:33:57 +00:00
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 = {
2024-01-02 10:53:45 +00:00
style = {foo = "bar";};
class = ["other" "class"];
2024-01-01 06:33:57 +00:00
};
2024-01-02 10:53:45 +00:00
para = style.component elems.p "para" attrs;
2024-01-01 06:33:57 +00:00
in {
2024-01-02 10:53:45 +00:00
expected = ["para" "other" "class"];
2024-01-01 06:33:57 +00:00
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
2024-01-02 10:53:45 +00:00
s = {foo = "bar";};
para = style.component elems.p "para" {style = s;};
2024-01-01 06:33:57 +00:00
in {
expected = {
2024-01-02 10:53:45 +00:00
"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 = {
2024-01-02 10:53:45 +00:00
"p" = {};
"div" = {};
"p.para" = {foo = "bar";};
"div.link" = {this = "that";};
2024-01-01 06:33:57 +00:00
};
2024-01-02 10:53:45 +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 = {
2024-01-02 10:53:45 +00:00
"p" = {};
"div" = {};
"p.para" = {foo = "bar";};
"div.link" = {this = "that";};
2024-01-01 06:33:57 +00:00
};
2024-01-02 10:53:45 +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;
2024-01-02 10:53:45 +00:00
actual = style.getStyles (para [(a "hello")]);
2024-01-01 06:33:57 +00:00
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 = {
2024-01-02 10:53:45 +00:00
"p" = {};
"div" = {};
"p.para" = {foo = "bar";};
"div.link" = {this = "that";};
2024-01-01 06:33:57 +00:00
};
2024-01-02 10:53:45 +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;
2024-01-02 10:53:45 +00:00
actual = style.getStyles (para [(a "hello") (a "hello")]);
2024-01-01 06:33:57 +00:00
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 = {
2024-01-02 10:53:45 +00:00
"p" = {};
"p.para" = {foo = "bar";};
"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 = {
2024-01-02 10:53:45 +00:00
"p.para" = {foo = "bar";};
"p.oof" = {oof = "yes";};
2024-01-01 06:33:57 +00:00
};
2024-01-02 10:53:45 +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 = {
2024-01-02 10:53:45 +00:00
"p" = {};
"div" = {};
"p.para" = {foo = "bar";};
"p.para.oof" = {oof = "yes";};
2024-01-01 06:33:57 +00:00
};
2024-01-02 10:53:45 +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 {
2024-01-02 10:53:45 +00:00
expected = ["para" "oof"];
2024-01-01 06:33:57 +00:00
actual = (para2 "").attrs.class;
}))
2023-12-31 03:08:41 +00:00
]