| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
|
| 30 |
|
| 31 |
|
| 32 |
|
| 33 |
use crate::form::Markup; |
| 34 |
use crate::{Emit, push_class}; |
| 35 |
use makeover_layout::{CellPart, Column, Flow, Priority, RowPart, Width}; |
| 36 |
use std::fmt::Write as _; |
| 37 |
|
| 38 |
|
| 39 |
|
| 40 |
|
| 41 |
|
| 42 |
|
| 43 |
|
| 44 |
|
| 45 |
|
| 46 |
|
| 47 |
|
| 48 |
#[derive(Debug, Clone, Copy, Default)] |
| 49 |
pub struct Sizing<'a> { |
| 50 |
|
| 51 |
|
| 52 |
pub lengths: &'a [(&'a str, &'a str)], |
| 53 |
|
| 54 |
pub fallback: &'a str, |
| 55 |
} |
| 56 |
|
| 57 |
impl Sizing<'_> { |
| 58 |
|
| 59 |
fn length_for(&self, name: &str) -> &str { |
| 60 |
self.lengths |
| 61 |
.iter() |
| 62 |
.find(|(column, _)| *column == name) |
| 63 |
.map_or_else( |
| 64 |
|| { |
| 65 |
if self.fallback.is_empty() { |
| 66 |
"auto" |
| 67 |
} else { |
| 68 |
self.fallback |
| 69 |
} |
| 70 |
}, |
| 71 |
|(_, length)| *length, |
| 72 |
) |
| 73 |
} |
| 74 |
|
| 75 |
|
| 76 |
fn track(&self, column: &Column<'_>) -> String { |
| 77 |
match column.width { |
| 78 |
Width::Content => "max-content".to_owned(), |
| 79 |
Width::Fixed => self.length_for(column.name).to_owned(), |
| 80 |
Width::Fill => format!("minmax({}, 1fr)", self.length_for(column.name)), |
| 81 |
|
| 82 |
|
| 83 |
|
| 84 |
_ => "auto".to_owned(), |
| 85 |
} |
| 86 |
} |
| 87 |
} |
| 88 |
|
| 89 |
|
| 90 |
|
| 91 |
|
| 92 |
|
| 93 |
|
| 94 |
|
| 95 |
|
| 96 |
#[must_use] |
| 97 |
pub fn column_class(column: &Column<'_>, opts: &Emit) -> String { |
| 98 |
let mut out = String::new(); |
| 99 |
push_column_class(&mut out, column, opts); |
| 100 |
out |
| 101 |
} |
| 102 |
|
| 103 |
|
| 104 |
|
| 105 |
|
| 106 |
|
| 107 |
|
| 108 |
|
| 109 |
pub fn push_column_class(out: &mut String, column: &Column<'_>, opts: &Emit) { |
| 110 |
out.push_str(opts.class_prefix); |
| 111 |
out.push_str("col-"); |
| 112 |
push_column_name(out, column.name); |
| 113 |
} |
| 114 |
|
| 115 |
|
| 116 |
|
| 117 |
|
| 118 |
|
| 119 |
|
| 120 |
|
| 121 |
|
| 122 |
|
| 123 |
|
| 124 |
|
| 125 |
|
| 126 |
|
| 127 |
|
| 128 |
|
| 129 |
|
| 130 |
|
| 131 |
|
| 132 |
|
| 133 |
|
| 134 |
|
| 135 |
|
| 136 |
|
| 137 |
|
| 138 |
|
| 139 |
|
| 140 |
|
| 141 |
|
| 142 |
|
| 143 |
|
| 144 |
|
| 145 |
|
| 146 |
|
| 147 |
|
| 148 |
|
| 149 |
|
| 150 |
|
| 151 |
|
| 152 |
pub fn push_column_name(out: &mut String, name: &str) { |
| 153 |
for ch in name.chars() { |
| 154 |
|
| 155 |
|
| 156 |
|
| 157 |
if ch.is_alphanumeric() || ch == '_' || ch == '-' { |
| 158 |
out.push(ch); |
| 159 |
} else { |
| 160 |
out.push('-'); |
| 161 |
} |
| 162 |
} |
| 163 |
} |
| 164 |
|
| 165 |
|
| 166 |
|
| 167 |
|
| 168 |
|
| 169 |
|
| 170 |
|
| 171 |
|
| 172 |
fn width_class(width: Width) -> &'static str { |
| 173 |
match width { |
| 174 |
Width::Content => "cell-content", |
| 175 |
Width::Fixed => "cell-fixed", |
| 176 |
_ => "cell-fill", |
| 177 |
} |
| 178 |
} |
| 179 |
|
| 180 |
|
| 181 |
|
| 182 |
|
| 183 |
|
| 184 |
|
| 185 |
|
| 186 |
|
| 187 |
fn drop_class(priority: Priority) -> &'static str { |
| 188 |
match priority { |
| 189 |
Priority::Optional => "cell-drops-first", |
| 190 |
Priority::Secondary => "cell-drops-next", |
| 191 |
|
| 192 |
|
| 193 |
|
| 194 |
|
| 195 |
_ => "cell-keeps", |
| 196 |
} |
| 197 |
} |
| 198 |
|
| 199 |
|
| 200 |
|
| 201 |
|
| 202 |
|
| 203 |
|
| 204 |
|
| 205 |
#[must_use] |
| 206 |
pub fn column_classes(column: &Column<'_>, opts: &Emit) -> String { |
| 207 |
let mut out = String::new(); |
| 208 |
push_column_classes(&mut out, column, opts); |
| 209 |
out |
| 210 |
} |
| 211 |
|
| 212 |
|
| 213 |
|
| 214 |
|
| 215 |
|
| 216 |
|
| 217 |
pub fn push_column_classes(out: &mut String, column: &Column<'_>, opts: &Emit) { |
| 218 |
push_column_class(out, column, opts); |
| 219 |
out.push(' '); |
| 220 |
push_class(out, width_class(column.width), opts); |
| 221 |
out.push(' '); |
| 222 |
push_class(out, drop_class(column.priority), opts); |
| 223 |
} |
| 224 |
|
| 225 |
|
| 226 |
|
| 227 |
|
| 228 |
|
| 229 |
|
| 230 |
|
| 231 |
|
| 232 |
#[must_use] |
| 233 |
pub fn grid_template_columns( |
| 234 |
columns: &[Column<'_>], |
| 235 |
sizing: &Sizing<'_>, |
| 236 |
cutoff: Priority, |
| 237 |
) -> String { |
| 238 |
columns |
| 239 |
.iter() |
| 240 |
.filter(|column| column.kept_at(cutoff)) |
| 241 |
.map(|column| sizing.track(column)) |
| 242 |
.collect::<Vec<_>>() |
| 243 |
.join(" ") |
| 244 |
} |
| 245 |
|
| 246 |
|
| 247 |
|
| 248 |
|
| 249 |
|
| 250 |
|
| 251 |
|
| 252 |
|
| 253 |
|
| 254 |
|
| 255 |
|
| 256 |
#[must_use] |
| 257 |
pub fn narrowing_css( |
| 258 |
columns: &[Column<'_>], |
| 259 |
selector: &str, |
| 260 |
sizing: &Sizing<'_>, |
| 261 |
cutoff: Priority, |
| 262 |
opts: &Emit, |
| 263 |
) -> String { |
| 264 |
let parts: Vec<&str> = selector.split(',').map(str::trim).collect(); |
| 265 |
|
| 266 |
let mut css = format!( |
| 267 |
"{} {{\n grid-template-columns: {};\n}}\n", |
| 268 |
parts.join(", "), |
| 269 |
grid_template_columns(columns, sizing, cutoff) |
| 270 |
); |
| 271 |
|
| 272 |
for column in columns.iter().filter(|c| !c.kept_at(cutoff)) { |
| 273 |
let class = column_class(column, opts); |
| 274 |
let targets: Vec<String> = parts |
| 275 |
.iter() |
| 276 |
.map(|part| format!("{part} > .{class}")) |
| 277 |
.collect(); |
| 278 |
let _ = write!(css, "{} {{\n display: none;\n}}\n", targets.join(",\n")); |
| 279 |
} |
| 280 |
css |
| 281 |
} |
| 282 |
|
| 283 |
|
| 284 |
|
| 285 |
|
| 286 |
|
| 287 |
|
| 288 |
|
| 289 |
#[derive(Debug, Clone, Copy)] |
| 290 |
pub struct Cell<'a> { |
| 291 |
|
| 292 |
pub column: &'a str, |
| 293 |
|
| 294 |
|
| 295 |
|
| 296 |
|
| 297 |
|
| 298 |
|
| 299 |
|
| 300 |
|
| 301 |
|
| 302 |
|
| 303 |
|
| 304 |
|
| 305 |
|
| 306 |
|
| 307 |
|
| 308 |
pub part: Option<CellPart>, |
| 309 |
|
| 310 |
pub content: Markup<'a>, |
| 311 |
} |
| 312 |
|
| 313 |
impl<'a> Cell<'a> { |
| 314 |
|
| 315 |
#[must_use] |
| 316 |
pub const fn new(column: &'a str, content: Markup<'a>) -> Self { |
| 317 |
Self { |
| 318 |
column, |
| 319 |
part: None, |
| 320 |
content, |
| 321 |
} |
| 322 |
} |
| 323 |
} |
| 324 |
|
| 325 |
|
| 326 |
|
| 327 |
|
| 328 |
|
| 329 |
|
| 330 |
|
| 331 |
|
| 332 |
|
| 333 |
|
| 334 |
|
| 335 |
|
| 336 |
|
| 337 |
|
| 338 |
|
| 339 |
|
| 340 |
|
| 341 |
|
| 342 |
|
| 343 |
|
| 344 |
|
| 345 |
|
| 346 |
|
| 347 |
pub const ROW_PART_CLASSES: &[&str] = &[ |
| 348 |
"row-primary", |
| 349 |
"row-secondary", |
| 350 |
"row-meta", |
| 351 |
"row-actions", |
| 352 |
"row-tokens", |
| 353 |
"row-proportion", |
| 354 |
"row-part", |
| 355 |
]; |
| 356 |
|
| 357 |
|
| 358 |
|
| 359 |
|
| 360 |
|
| 361 |
|
| 362 |
|
| 363 |
pub const FLOW_CLASSES: &[&str] = &["row-relaxed"]; |
| 364 |
|
| 365 |
|
| 366 |
|
| 367 |
|
| 368 |
|
| 369 |
|
| 370 |
pub const NESTING_CLASSES: &[&str] = &["row-nested", "row-branch", "row-disclose"]; |
| 371 |
|
| 372 |
|
| 373 |
|
| 374 |
|
| 375 |
|
| 376 |
|
| 377 |
|
| 378 |
|
| 379 |
|
| 380 |
#[must_use] |
| 381 |
pub fn flow_class(flow: Flow) -> Option<&'static str> { |
| 382 |
match flow { |
| 383 |
Flow::Relaxed => Some("row-relaxed"), |
| 384 |
_ => None, |
| 385 |
} |
| 386 |
} |
| 387 |
|
| 388 |
|
| 389 |
|
| 390 |
|
| 391 |
|
| 392 |
|
| 393 |
|
| 394 |
|
| 395 |
|
| 396 |
pub const CELL_WIDTH_CLASSES: &[&str] = &["cell-content", "cell-fixed", "cell-fill"]; |
| 397 |
|
| 398 |
|
| 399 |
|
| 400 |
|
| 401 |
|
| 402 |
|
| 403 |
|
| 404 |
pub const CELL_DROP_CLASSES: &[&str] = &["cell-drops-first", "cell-drops-next", "cell-keeps"]; |
| 405 |
|
| 406 |
|
| 407 |
|
| 408 |
|
| 409 |
pub const CELL_PART_CLASSES: &[&str] = &[ |
| 410 |
"cell-value", |
| 411 |
"cell-tokens", |
| 412 |
"cell-actions", |
| 413 |
"cell-link", |
| 414 |
"cell-part", |
| 415 |
]; |
| 416 |
|
| 417 |
#[must_use] |
| 418 |
pub fn part_class(part: RowPart) -> &'static str { |
| 419 |
match part { |
| 420 |
RowPart::Primary => "row-primary", |
| 421 |
RowPart::Secondary => "row-secondary", |
| 422 |
RowPart::Meta => "row-meta", |
| 423 |
RowPart::Actions => "row-actions", |
| 424 |
RowPart::Tokens => "row-tokens", |
| 425 |
RowPart::Proportion => "row-proportion", |
| 426 |
_ => "row-part", |
| 427 |
} |
| 428 |
} |
| 429 |
|
| 430 |
|
| 431 |
|
| 432 |
|
| 433 |
|
| 434 |
|
| 435 |
|
| 436 |
|
| 437 |
#[must_use] |
| 438 |
pub fn cell_part_class(part: CellPart) -> &'static str { |
| 439 |
match part { |
| 440 |
CellPart::Value => "cell-value", |
| 441 |
CellPart::Tokens => "cell-tokens", |
| 442 |
CellPart::Actions => "cell-actions", |
| 443 |
CellPart::Link => "cell-link", |
| 444 |
_ => "cell-part", |
| 445 |
} |
| 446 |
} |
| 447 |
|
| 448 |
|
| 449 |
|
| 450 |
|
| 451 |
|
| 452 |
|
| 453 |
|
| 454 |
|
| 455 |
|
| 456 |
|
| 457 |
|
| 458 |
|
| 459 |
|
| 460 |
|
| 461 |
|
| 462 |
|
| 463 |
|
| 464 |
|
| 465 |
|
| 466 |
|
| 467 |
|
| 468 |
|
| 469 |
|
| 470 |
|
| 471 |
|
| 472 |
#[must_use] |
| 473 |
pub fn cells_html(columns: &[Column<'_>], cells: &[Cell<'_>], opts: &Emit) -> String { |
| 474 |
let mut html = String::new(); |
| 475 |
cells_html_into(columns, cells, opts, &mut html); |
| 476 |
html |
| 477 |
} |
| 478 |
|
| 479 |
|
| 480 |
|
| 481 |
|
| 482 |
|
| 483 |
|
| 484 |
pub fn cells_html_into(columns: &[Column<'_>], cells: &[Cell<'_>], opts: &Emit, out: &mut String) { |
| 485 |
for column in columns { |
| 486 |
let found = cells.iter().find(|cell| cell.column == column.name); |
| 487 |
out.push_str("<div class=\""); |
| 488 |
push_class(out, "cell", opts); |
| 489 |
out.push(' '); |
| 490 |
push_column_classes(out, column, opts); |
| 491 |
if let Some(part) = found.and_then(|cell| cell.part) { |
| 492 |
out.push(' '); |
| 493 |
push_class(out, cell_part_class(part), opts); |
| 494 |
} |
| 495 |
out.push_str("\">"); |
| 496 |
out.push_str(found.map_or("", |cell| cell.content.0)); |
| 497 |
out.push_str("</div>"); |
| 498 |
} |
| 499 |
} |
| 500 |
|
| 501 |
#[cfg(test)] |
| 502 |
mod tests { |
| 503 |
use super::*; |
| 504 |
|
| 505 |
#[test] |
| 506 |
fn every_width_and_drop_class_is_one_the_vocabulary_wrote_down() { |
| 507 |
|
| 508 |
|
| 509 |
|
| 510 |
|
| 511 |
|
| 512 |
for width in [Width::Content, Width::Fixed, Width::Fill] { |
| 513 |
assert!( |
| 514 |
CELL_WIDTH_CLASSES.contains(&width_class(width)), |
| 515 |
"{width:?} is missing from CELL_WIDTH_CLASSES" |
| 516 |
); |
| 517 |
} |
| 518 |
for priority in [Priority::Optional, Priority::Secondary, Priority::Essential] { |
| 519 |
assert!( |
| 520 |
CELL_DROP_CLASSES.contains(&drop_class(priority)), |
| 521 |
"{priority:?} is missing from CELL_DROP_CLASSES" |
| 522 |
); |
| 523 |
} |
| 524 |
let names = crate::vocabulary::names(&Emit::default()); |
| 525 |
for name in CELL_WIDTH_CLASSES.iter().chain(CELL_DROP_CLASSES) { |
| 526 |
assert!(names.contains(*name), "{name} is not in the vocabulary"); |
| 527 |
} |
| 528 |
} |
| 529 |
|
| 530 |
#[test] |
| 531 |
fn a_column_name_cannot_break_out_of_the_class_attribute() { |
| 532 |
|
| 533 |
|
| 534 |
|
| 535 |
|
| 536 |
let name = "a\" onclick=\"steal()"; |
| 537 |
let columns = vec![Column::new(name)]; |
| 538 |
let cells = vec![Cell { |
| 539 |
column: name, |
| 540 |
part: None, |
| 541 |
content: Markup("x"), |
| 542 |
}]; |
| 543 |
let html = cells_html(&columns, &cells, &Emit::default()); |
| 544 |
|
| 545 |
assert!(!html.contains("onclick=\"steal()"), "{html}"); |
| 546 |
assert!(html.contains("col-a--onclick--steal--"), "{html}"); |
| 547 |
|
| 548 |
|
| 549 |
assert_eq!(html.matches('"').count(), 2, "{html}"); |
| 550 |
} |
| 551 |
|
| 552 |
#[test] |
| 553 |
fn the_class_and_the_selector_that_hides_it_agree_on_the_name() { |
| 554 |
|
| 555 |
|
| 556 |
|
| 557 |
|
| 558 |
let columns = vec![Column { |
| 559 |
priority: Priority::Optional, |
| 560 |
..Column::new("Due date") |
| 561 |
}]; |
| 562 |
let cells = vec![Cell { |
| 563 |
column: "Due date", |
| 564 |
part: None, |
| 565 |
content: Markup("x"), |
| 566 |
}]; |
| 567 |
let opts = Emit::default(); |
| 568 |
|
| 569 |
let html = cells_html(&columns, &cells, &opts); |
| 570 |
let css = narrowing_css(&columns, ".row", &sizing(), Priority::Essential, &opts); |
| 571 |
|
| 572 |
|
| 573 |
assert!(html.contains("class=\"cell col-Due-date "), "{html}"); |
| 574 |
assert!(css.contains(".row > .col-Due-date {"), "{css}"); |
| 575 |
} |
| 576 |
|
| 577 |
#[test] |
| 578 |
fn a_name_already_made_of_identifier_characters_is_untouched() { |
| 579 |
|
| 580 |
|
| 581 |
for name in ["description", "due", "progress", "Name", "col_2", "a-b"] { |
| 582 |
let mut out = String::new(); |
| 583 |
push_column_name(&mut out, name); |
| 584 |
assert_eq!(out, name); |
| 585 |
} |
| 586 |
} |
| 587 |
|
| 588 |
#[test] |
| 589 |
fn a_name_outside_ascii_keeps_itself() { |
| 590 |
|
| 591 |
|
| 592 |
let mut out = String::new(); |
| 593 |
push_column_name(&mut out, "Größe"); |
| 594 |
assert_eq!(out, "Größe"); |
| 595 |
} |
| 596 |
|
| 597 |
fn columns() -> Vec<Column<'static>> { |
| 598 |
vec![ |
| 599 |
Column { |
| 600 |
width: Width::Fill, |
| 601 |
priority: Priority::Essential, |
| 602 |
..Column::new("description") |
| 603 |
}, |
| 604 |
Column { |
| 605 |
width: Width::Fixed, |
| 606 |
priority: Priority::Secondary, |
| 607 |
..Column::new("due") |
| 608 |
}, |
| 609 |
Column { |
| 610 |
width: Width::Fixed, |
| 611 |
priority: Priority::Optional, |
| 612 |
..Column::new("progress") |
| 613 |
}, |
| 614 |
] |
| 615 |
} |
| 616 |
|
| 617 |
fn sizing() -> Sizing<'static> { |
| 618 |
Sizing { |
| 619 |
lengths: &[ |
| 620 |
("description", "200px"), |
| 621 |
("due", "110px"), |
| 622 |
("progress", "100px"), |
| 623 |
], |
| 624 |
fallback: "", |
| 625 |
} |
| 626 |
} |
| 627 |
|
| 628 |
#[test] |
| 629 |
fn a_fill_column_gets_a_floor_and_the_slack() { |
| 630 |
let tracks = grid_template_columns(&columns(), &sizing(), Priority::Optional); |
| 631 |
assert_eq!(tracks, "minmax(200px, 1fr) 110px 100px"); |
| 632 |
} |
| 633 |
|
| 634 |
#[test] |
| 635 |
fn a_column_with_no_length_makes_no_claim() { |
| 636 |
let sizing = Sizing::default(); |
| 637 |
let tracks = grid_template_columns(&columns(), &sizing, Priority::Optional); |
| 638 |
assert_eq!(tracks, "minmax(auto, 1fr) auto auto"); |
| 639 |
} |
| 640 |
|
| 641 |
|
| 642 |
|
| 643 |
|
| 644 |
|
| 645 |
#[test] |
| 646 |
fn raising_the_cutoff_drops_columns_and_their_tracks_together() { |
| 647 |
let columns = columns(); |
| 648 |
|
| 649 |
let wide = grid_template_columns(&columns, &sizing(), Priority::Optional); |
| 650 |
assert_eq!(wide.split(' ').count(), 4); |
| 651 |
|
| 652 |
let narrow = grid_template_columns(&columns, &sizing(), Priority::Secondary); |
| 653 |
assert_eq!(narrow, "minmax(200px, 1fr) 110px"); |
| 654 |
|
| 655 |
let narrowest = grid_template_columns(&columns, &sizing(), Priority::Essential); |
| 656 |
assert_eq!(narrowest, "minmax(200px, 1fr)"); |
| 657 |
} |
| 658 |
|
| 659 |
#[test] |
| 660 |
fn narrowing_hides_a_dropped_column_by_its_own_class_not_its_position() { |
| 661 |
let css = narrowing_css( |
| 662 |
&columns(), |
| 663 |
".ui-mode-mobile .task-row", |
| 664 |
&sizing(), |
| 665 |
Priority::Secondary, |
| 666 |
&Emit::default(), |
| 667 |
); |
| 668 |
assert!( |
| 669 |
css.contains("grid-template-columns: minmax(200px, 1fr) 110px;"), |
| 670 |
"{css}" |
| 671 |
); |
| 672 |
assert!( |
| 673 |
css.contains(".ui-mode-mobile .task-row > .col-progress {"), |
| 674 |
"{css}" |
| 675 |
); |
| 676 |
assert!(!css.contains("nth-child"), "{css}"); |
| 677 |
|
| 678 |
assert!(!css.contains(".col-due {\n display: none"), "{css}"); |
| 679 |
} |
| 680 |
|
| 681 |
|
| 682 |
|
| 683 |
|
| 684 |
#[test] |
| 685 |
fn a_selector_list_distributes_the_hidden_column() { |
| 686 |
let css = narrowing_css( |
| 687 |
&columns(), |
| 688 |
".task-header-row, .task-row", |
| 689 |
&sizing(), |
| 690 |
Priority::Secondary, |
| 691 |
&Emit::default(), |
| 692 |
); |
| 693 |
assert!( |
| 694 |
css.contains(".task-header-row > .col-progress,\n.task-row > .col-progress {"), |
| 695 |
"{css}" |
| 696 |
); |
| 697 |
|
| 698 |
assert!( |
| 699 |
!css.contains(".task-header-row {\n display: none"), |
| 700 |
"{css}" |
| 701 |
); |
| 702 |
assert!( |
| 703 |
css.contains(".task-header-row, .task-row {\n grid-template-columns:"), |
| 704 |
"{css}" |
| 705 |
); |
| 706 |
} |
| 707 |
|
| 708 |
#[test] |
| 709 |
fn cells_follow_the_columns_and_carry_their_column_class() { |
| 710 |
let cells = [ |
| 711 |
Cell { |
| 712 |
column: "due", |
| 713 |
part: Some(CellPart::Value), |
| 714 |
content: Markup("tomorrow"), |
| 715 |
}, |
| 716 |
Cell::new("description", Markup("<span>Ship it</span>")), |
| 717 |
]; |
| 718 |
let html = cells_html(&columns(), &cells, &Emit::default()); |
| 719 |
|
| 720 |
|
| 721 |
let description = html.find("Ship it").expect("description cell"); |
| 722 |
let due = html.find("tomorrow").expect("due cell"); |
| 723 |
assert!(description < due, "{html}"); |
| 724 |
|
| 725 |
|
| 726 |
|
| 727 |
|
| 728 |
assert!( |
| 729 |
html.contains(r#"<div class="cell col-description cell-fill cell-keeps">"#), |
| 730 |
"{html}" |
| 731 |
); |
| 732 |
assert!( |
| 733 |
html.contains(r#"<div class="cell col-due cell-fixed cell-drops-next cell-value">"#), |
| 734 |
"{html}" |
| 735 |
); |
| 736 |
|
| 737 |
|
| 738 |
assert!( |
| 739 |
html.contains(r#"<div class="cell col-progress cell-fixed cell-drops-first"></div>"#), |
| 740 |
"{html}" |
| 741 |
); |
| 742 |
} |
| 743 |
|
| 744 |
|
| 745 |
|
| 746 |
#[test] |
| 747 |
fn streamed_cells_are_the_cells_the_other_form_returns() { |
| 748 |
let opts = Emit { |
| 749 |
class_prefix: "mk-", |
| 750 |
..Emit::default() |
| 751 |
}; |
| 752 |
let cells = [ |
| 753 |
Cell { |
| 754 |
column: "due", |
| 755 |
part: Some(CellPart::Value), |
| 756 |
content: Markup("tomorrow"), |
| 757 |
}, |
| 758 |
Cell::new("description", Markup("<span>Ship it</span>")), |
| 759 |
]; |
| 760 |
for cells in [&cells[..], &[]] { |
| 761 |
let mut streamed = String::new(); |
| 762 |
cells_html_into(&columns(), cells, &opts, &mut streamed); |
| 763 |
assert_eq!(streamed, cells_html(&columns(), cells, &opts)); |
| 764 |
} |
| 765 |
for column in &columns() { |
| 766 |
let mut streamed = String::new(); |
| 767 |
push_column_classes(&mut streamed, column, &opts); |
| 768 |
assert_eq!(streamed, column_classes(column, &opts)); |
| 769 |
} |
| 770 |
} |
| 771 |
|
| 772 |
#[test] |
| 773 |
fn a_cell_naming_no_column_is_dropped() { |
| 774 |
let cells = [Cell::new("nonexistent", Markup("nowhere"))]; |
| 775 |
let html = cells_html(&columns(), &cells, &Emit::default()); |
| 776 |
assert!(!html.contains("nowhere"), "{html}"); |
| 777 |
} |
| 778 |
|
| 779 |
#[test] |
| 780 |
fn the_class_prefix_reaches_the_cells_and_the_narrowing() { |
| 781 |
let opts = Emit { |
| 782 |
class_prefix: "mk-", |
| 783 |
..Emit::default() |
| 784 |
}; |
| 785 |
let cells = [Cell::new("due", Markup("x"))]; |
| 786 |
assert!( |
| 787 |
cells_html(&columns(), &cells, &opts).contains("mk-cell mk-col-due"), |
| 788 |
"prefix missing" |
| 789 |
); |
| 790 |
assert!( |
| 791 |
narrowing_css(&columns(), ".t", &sizing(), Priority::Secondary, &opts) |
| 792 |
.contains(".mk-col-progress"), |
| 793 |
"prefix missing" |
| 794 |
); |
| 795 |
} |
| 796 |
} |
| 797 |
|