nixite/testing/style.test.nix

130 lines
3.1 KiB
Nix

let
style = import ../nixite/style.nix;
it = import ./it.nix;
in [
(it "fetches empty style" (let para = (style.tag "p" "para" { });
in {
expected = { "p.para" = { }; };
actual = style.getStyle (para "");
}))
(it "fetches style" (let
attrs = { style = { foo = "bar"; }; };
para = (style.tag "p" "para" attrs);
in {
expected = { "p.para" = attrs.style; };
actual = style.getStyle (para "");
}))
(it "appliess class" (let
attrs = { style = { foo = "bar"; }; };
para = (style.tag "p" "para" attrs);
in {
expected = [ "para" ];
actual = (para "").attrs.class;
}))
(it "applies classes from props" (let
attrs = {
style = { foo = "bar"; };
class = [ "other" "class" ];
};
para = (style.tag "p" "para" attrs);
in {
expected = [ "para" "other" "class" ];
actual = (para "").attrs.class;
}))
(it "fetches style for class" (let
s = { foo = "bar"; };
para = (style.tag "p" "para" { style = s; });
in {
expected = { "p.para" = s; };
actual = style.getStyle (para "");
}))
(it "fetches style recursively" (let
s = {
"p.para" = { foo = "bar"; };
"a.link" = { this = "that"; };
};
para = (style.tag "p" "para" { style = s."p.para"; });
a = (style.tag "a" "link" { style = s."a.link"; });
in {
expected = s;
actual = style.getStyles (para (a "hello"));
removeDunders = true;
}))
(it "fetches style recursively through lists" (let
s = {
"p.para" = { foo = "bar"; };
"a.link" = { this = "that"; };
};
para = (style.tag "p" "para" { style = s."p.para"; });
a = (style.tag "a" "link" { style = s."a.link"; });
in {
expected = s;
actual = style.getStyles (para [ (a "hello") ]);
removeDunders = true;
}))
(it "fetches style recursively with repeats" (let
s = {
"p.para" = { foo = "bar"; };
"a.link" = { this = "that"; };
};
para = (style.tag "p" "para" { style = s."p.para"; });
a = (style.tag "a" "link" { style = s."a.link"; });
in {
expected = s;
actual = style.getStyles (para [ (a "hello") (a "hello") ]);
removeDunders = true;
}))
(it "converts styles to string" (let
s = {
"p.para" = { foo = "bar"; };
"a.link" = { this = "that"; };
};
in {
expected = ''
a.link {
this: that;
}
p.para {
foo: bar;
}
'';
actual = style.stylesToString s;
}))
(it "extends styled tags" (let
s = {
"p.para" = { foo = "bar"; };
"p.para.oof" = { oof = "yes"; };
};
para = (style.tag "p" "para" { style = s."p.para"; });
para2 = (style.extend para "oof" { style = s."p.para.oof"; });
in {
expected = s;
actual = style.getStyles (para2 "");
removeDunders = true;
}))
(it "extends styled tags classes" (let
s = {
"p.para" = { foo = "bar"; };
"p.para.oof" = { oof = "yes"; };
};
para = (style.tag "p" "para" { style = s."p.para"; });
para2 = (style.extend para "oof" { style = s."p.para.oof"; });
in {
expected = [ "para" "oof" ];
actual = (para2 "").attrs.class;
}))
]