|
1 |
+ |
//! The same screen, declared.
|
|
2 |
+ |
//!
|
|
3 |
+ |
//! [`crate::staging`] writes MNW's `library_contacts` pane by hand, against a
|
|
4 |
+ |
//! `Data` seam invented for the spike. This is the screen as the server
|
|
5 |
+ |
//! actually holds it: a verbatim port of the three `declare!` blocks in
|
|
6 |
+ |
//! `MNW/server/src/quasi/library_contacts.rs`, against the bench's own rows.
|
|
7 |
+ |
//!
|
|
8 |
+ |
//! Two things it has that the hand-written copy does not, and both are the
|
|
9 |
+ |
//! point. Every table is placed behind a guard, so the branch case the spike's
|
|
10 |
+ |
//! module doc calls its real constraint is exercised here rather than assumed
|
|
11 |
+ |
//! away. And a shape reaches another shape by `include`, so the residual has to
|
|
12 |
+ |
//! compose rather than being one flat program.
|
|
13 |
+ |
//!
|
|
14 |
+ |
//! Kept verbatim rather than tidied. A bench measuring a shape written for the
|
|
15 |
+ |
//! bench measures the bench.
|
|
16 |
+ |
|
|
17 |
+ |
use quasi_declare::declare;
|
|
18 |
+ |
use quasi_router::Node;
|
|
19 |
+ |
|
|
20 |
+ |
use crate::fixture::{Buyer, Rows, Shared};
|
|
21 |
+ |
|
|
22 |
+ |
/// The region the tab nav targets, as the server names it.
|
|
23 |
+ |
const REGION: &str = "tab-content";
|
|
24 |
+ |
|
|
25 |
+ |
/// This screen's own nest, which the revoke control addresses under.
|
|
26 |
+ |
const PATH: &str = "/library/tabs/contacts";
|
|
27 |
+ |
|
|
28 |
+ |
declare! {
|
|
29 |
+ |
/// Everything inside the tab pane.
|
|
30 |
+ |
shape pane(buyers: &[Buyer], shared: &[Shared]) -> Node;
|
|
31 |
+ |
|
|
32 |
+ |
region REGION as Pane {
|
|
33 |
+ |
empty "No contacts yet." when buyers.is_empty() and shared.is_empty();
|
|
34 |
+ |
|
|
35 |
+ |
section "Your Buyers ({buyers.len()})" unless buyers.is_empty();
|
|
36 |
+ |
text "Buyers who opted to share their email with you at purchase time."
|
|
37 |
+ |
unless buyers.is_empty();
|
|
38 |
+ |
include buyers_table(buyers) unless buyers.is_empty();
|
|
39 |
+ |
|
|
40 |
+ |
section "Shared With" unless shared.is_empty();
|
|
41 |
+ |
text "You've shared your email with these creators. You can revoke sharing at any time."
|
|
42 |
+ |
unless shared.is_empty();
|
|
43 |
+ |
include shared_table(shared) unless shared.is_empty();
|
|
44 |
+ |
}
|
|
45 |
+ |
}
|
|
46 |
+ |
|
|
47 |
+ |
declare! {
|
|
48 |
+ |
/// The buyers who shared an email.
|
|
49 |
+ |
shape buyers_table(buyers: &[Buyer]) -> Node;
|
|
50 |
+ |
|
|
51 |
+ |
table {
|
|
52 |
+ |
column "Username" {
|
|
53 |
+ |
width Content;
|
|
54 |
+ |
priority Essential;
|
|
55 |
+ |
}
|
|
56 |
+ |
column "Email" {
|
|
57 |
+ |
width Fill;
|
|
58 |
+ |
priority Essential;
|
|
59 |
+ |
}
|
|
60 |
+ |
column "Purchases" {
|
|
61 |
+ |
width Content;
|
|
62 |
+ |
}
|
|
63 |
+ |
column "Total Spent" {
|
|
64 |
+ |
width Content;
|
|
65 |
+ |
}
|
|
66 |
+ |
column "Last Purchase" {
|
|
67 |
+ |
width Content;
|
|
68 |
+ |
priority Optional;
|
|
69 |
+ |
}
|
|
70 |
+ |
|
|
71 |
+ |
for buyer in buyers.iter() {
|
|
72 |
+ |
cells {
|
|
73 |
+ |
cell buyer.username.clone() {
|
|
74 |
+ |
activate to get "/u/{buyer.username}" navigating;
|
|
75 |
+ |
}
|
|
76 |
+ |
cell buyer.email.clone() {
|
|
77 |
+ |
activate to external "mailto:{buyer.email}";
|
|
78 |
+ |
}
|
|
79 |
+ |
cell buyer.purchases.clone();
|
|
80 |
+ |
cell buyer.spent.clone();
|
|
81 |
+ |
cell buyer.last_purchase.clone();
|
|
82 |
+ |
}
|
|
83 |
+ |
}
|
|
84 |
+ |
}
|
|
85 |
+ |
}
|
|
86 |
+ |
|
|
87 |
+ |
declare! {
|
|
88 |
+ |
/// The creators this reader has shared an email with.
|
|
89 |
+ |
shape shared_table(shared: &[Shared]) -> Node;
|
|
90 |
+ |
|
|
91 |
+ |
table {
|
|
92 |
+ |
column "Creator" {
|
|
93 |
+ |
width Fill;
|
|
94 |
+ |
priority Essential;
|
|
95 |
+ |
}
|
|
96 |
+ |
column "" {
|
|
97 |
+ |
width Content;
|
|
98 |
+ |
priority Essential;
|
|
99 |
+ |
}
|
|
100 |
+ |
|
|
101 |
+ |
for creator in shared.iter() {
|
|
102 |
+ |
cells {
|
|
103 |
+ |
cell creator.name.clone() {
|
|
104 |
+ |
activate to get "/u/{creator.username}" navigating;
|
|
105 |
+ |
}
|
|
106 |
+ |
cell "" {
|
|
107 |
+ |
act "Revoke" to delete "{PATH}/revoke/{creator.seller_id}" awaiting {
|
|
108 |
+ |
confirm "Revoke contact sharing with {creator.username}?";
|
|
109 |
+ |
tone Danger;
|
|
110 |
+ |
}
|
|
111 |
+ |
}
|
|
112 |
+ |
}
|
|
113 |
+ |
}
|
|
114 |
+ |
}
|
|
115 |
+ |
}
|
|
116 |
+ |
|
|
117 |
+ |
/// The pane, built from real rows the way a request builds it.
|
|
118 |
+ |
#[must_use]
|
|
119 |
+ |
pub fn describe(rows: &Rows) -> Node {
|
|
120 |
+ |
pane(&rows.buyers, &rows.shared)
|
|
121 |
+ |
}
|
|
122 |
+ |
|
|
123 |
+ |
#[cfg(test)]
|
|
124 |
+ |
mod tests {
|
|
125 |
+ |
use quasi_http::Serves as _;
|
|
126 |
+ |
use quasi_webview::Webview;
|
|
127 |
+ |
|
|
128 |
+ |
use super::*;
|
|
129 |
+ |
use crate::fixture::SIZES;
|
|
130 |
+ |
|
|
131 |
+ |
/// The port is faithful to the server's screen, which is not the same
|
|
132 |
+ |
/// thing as agreeing with [`crate::staging`].
|
|
133 |
+ |
///
|
|
134 |
+ |
/// The hand-written copy is the impoverished one. It was written for the
|
|
135 |
+ |
/// spike against a `Data` seam and dropped four things the declaration
|
|
136 |
+ |
/// carries, each asserted below so that the difference is a record rather
|
|
137 |
+ |
/// than a surprise the next reader has to rediscover:
|
|
138 |
+ |
///
|
|
139 |
+ |
/// - `navigating` on a profile link, which drops the htmx swap because a
|
|
140 |
+ |
/// profile is a whole document rather than a region.
|
|
141 |
+ |
/// - `confirm`, `tone Danger` and `awaiting` on the Revoke control.
|
|
142 |
+ |
///
|
|
143 |
+ |
/// Everything the acceptance rule protects does agree: every address, the
|
|
144 |
+ |
/// actions and their methods, and the heading structure. That is checked
|
|
145 |
+ |
/// here, and the bytes deliberately are not.
|
|
146 |
+ |
#[test]
|
|
147 |
+ |
fn the_declared_pane_carries_what_the_hand_written_one_dropped() {
|
|
148 |
+ |
let webview = Webview::new();
|
|
149 |
+ |
let rows = Rows::new(5);
|
|
150 |
+ |
let hand = webview.fragment(&crate::fixture::pane(&rows));
|
|
151 |
+ |
let real = webview.fragment(&describe(&rows));
|
|
152 |
+ |
|
|
153 |
+ |
// What the declaration says and the copy could not.
|
|
154 |
+ |
assert!(real.contains(r#"data-tone="danger""#), "{real}");
|
|
155 |
+ |
assert!(real.contains("hx-confirm="), "{real}");
|
|
156 |
+ |
assert!(real.contains(r#"data-awaiting="indeterminate""#), "{real}");
|
|
157 |
+ |
assert!(!hand.contains("hx-confirm="), "{hand}");
|
|
158 |
+ |
|
|
159 |
+ |
// `navigating`: the anchor is the whole of it, so no swap is asked for.
|
|
160 |
+ |
assert!(!real.contains(r#"hx-get="/u/buyer0000""#), "{real}");
|
|
161 |
+ |
assert!(hand.contains(r#"hx-get="/u/buyer0000""#), "{hand}");
|
|
162 |
+ |
|
|
163 |
+ |
// What must survive regardless, which is the acceptance rule.
|
|
164 |
+ |
for size in SIZES {
|
|
165 |
+ |
let rows = Rows::new(size);
|
|
166 |
+ |
let real = webview.fragment(&describe(&rows));
|
|
167 |
+ |
for i in 0..size {
|
|
168 |
+ |
assert!(real.contains(&format!(r#"href="/u/buyer{i:04}""#)), "{i}");
|
|
169 |
+ |
assert!(
|
|
170 |
+ |
real.contains(&format!(r#"href="mailto:buyer{i:04}@example.com""#)),
|
|
171 |
+ |
"{i}"
|
|
172 |
+ |
);
|
|
173 |
+ |
assert!(
|
|
174 |
+ |
real.contains(&format!(
|
|
175 |
+ |
r#"hx-delete="/library/tabs/contacts/revoke/{:08}""#,
|
|
176 |
+ |
i * 31 + 7
|
|
177 |
+ |
)),
|
|
178 |
+ |
"{i}"
|
|
179 |
+ |
);
|
|
180 |
+ |
}
|
|
181 |
+ |
assert_eq!(
|
|
182 |
+ |
real.matches("table-row").count(),
|
|
183 |
+ |
size * 2,
|
|
184 |
+ |
"at {size} rows"
|
|
185 |
+ |
);
|
|
186 |
+ |
assert!(real.contains(&format!("Your Buyers ({size})")), "at {size}");
|
|
187 |
+ |
}
|
|
188 |
+ |
}
|
|
189 |
+ |
|
|
190 |
+ |
/// The guards the hand-written copy has no way to carry.
|
|
191 |
+ |
#[test]
|
|
192 |
+ |
fn no_rows_places_the_empty_line_and_neither_table() {
|
|
193 |
+ |
let html = Webview::new().fragment(&describe(&Rows::new(0)));
|
|
194 |
+ |
|
|
195 |
+ |
assert!(html.contains("No contacts yet."), "{html}");
|
|
196 |
+ |
assert!(!html.contains("Your Buyers"), "{html}");
|
|
197 |
+ |
assert!(!html.contains("Shared With"), "{html}");
|
|
198 |
+ |
}
|
|
199 |
+ |
}
|