Skip to main content

max / quasi

2.2 KB · 62 lines History Blame Raw
1 //! Names a consumer has to be able to say, proved from outside the crate.
2 //!
3 //! A unit test cannot check this: inside the crate every type is reachable
4 //! through `crate::`, so a missing entry in `lib.rs`'s `pub use` list only
5 //! shows up once something else does the `use`. `Curve` sat unexported that
6 //! way until an audiofiles port tried to call `Field::curve`.
7
8 use quasi_router::{Curve, Field, layout};
9
10 #[test]
11 fn a_slider_can_be_given_a_curve_from_outside_the_crate() {
12 let field = Field::range("gain", "Gain", "0", "1").curve(Curve::Logarithmic {
13 step: Some("0.01".into()),
14 });
15
16 field.with_layout(|drawn| {
17 assert_eq!(
18 drawn.curve,
19 layout::Curve::Logarithmic { step: Some("0.01") }
20 );
21 });
22 }
23
24 /// The save shape and the pick a host answers with are both consumer-facing:
25 /// audiofiles builds the first and hands back the second, so both have to be
26 /// sayable from outside the crate.
27 #[test]
28 fn a_save_ask_and_its_answer_can_be_built_from_outside_the_crate() {
29 use quasi_router::{Accepted, Action, Locating, Picked, Sought};
30
31 let asking = Locating::new(
32 Sought::Save {
33 name: "drums.afcl".into(),
34 accept: vec![Accepted::suffix(".afcl")],
35 },
36 "Export classifier",
37 Action::post("/classifier/export"),
38 "path",
39 );
40 let call = asking
41 .answered([Picked::new("/home/max/drums.afcl", "drums.afcl")])
42 .expect("a route to answer to");
43 assert_eq!(call.payload.get("path"), Some("/home/max/drums.afcl"));
44 }
45
46 /// A screen's document facts are the description's to state, so both the type
47 /// and the gate a renderer asks about a name have to be sayable from outside
48 /// the crate.
49 #[test]
50 fn a_document_can_be_built_and_its_names_checked_from_outside_the_crate() {
51 use quasi_router::{Document, Screen, writable_root_attr};
52
53 let screen = Screen::list_detail("Admin", false).documented(
54 Document::default()
55 .classed("admin-page")
56 .rooted("data-theme", "slate"),
57 );
58
59 assert_eq!(screen.document.body_class.as_deref(), Some("admin-page"));
60 assert!(writable_root_attr(&screen.document.root[0].0));
61 }
62