use topcoat::context::CxTestBuilder;
use super::{super::core::tests::User, *};
use crate::{TablePage, TextColumn, lens};
#[test]
fn live_search_debounce_sits_in_the_locked_band() {
assert!(
(150..=250).contains(&LIVE_SEARCH_DEBOUNCE_MS),
"debounce must sit in the 150-250ms band, got {LIVE_SEARCH_DEBOUNCE_MS}"
);
}
#[tokio::test]
async fn bulk_checkboxes_render_with_keys_and_select_all() {
let cx = CxTestBuilder::new().build();
let bulk_table = Table::<User>::new(TextColumn::new(lens!(User.name)))
.with_delete("/admin/users".to_string())
.with_bulk_delete(true);
let rows = vec![
User {
id: uuid::Uuid::new_v4(),
name: "Ada".to_string(),
},
User {
id: uuid::Uuid::new_v4(),
name: "Bob".to_string(),
},
];
let page: TablePage<User> = rows.clone().into();
let html = bulk_table
.render(&cx, page)
.await
.unwrap()
.single()
.await
.unwrap()
.render(&cx);
for row in &rows {
assert!(
html.contains(&format!("value=\"{}\"", row.id)),
"missing checkbox value for {} in {html}",
row.id
);
}
assert!(
html.contains("data-row-select"),
"missing row checkbox marker in {html}"
);
assert!(
html.contains("data-bulk-select-all"),
"missing select-all in {html}"
);
assert!(
html.contains("data-bulk-form"),
"missing bulk form in {html}"
);
assert!(
html.contains("name=\"ids\"") && !html.contains("ids comma-separated"),
"missing hidden ids transport in {html}"
);
assert!(
html.contains("data-bulk-confirm-trigger"),
"missing the bulk confirm trigger in {html}"
);
assert!(
html.contains("data-bulk-confirm-dialog"),
"missing the bulk confirm dialog in {html}"
);
assert!(
html.contains("name=\"confirm\"") && html.contains("value=\"1\""),
"the dialog must carry the confirm marker in {html}"
);
let dialog_at = html
.find("data-bulk-confirm-dialog")
.expect("the dialog marker");
let dialog_tag_start = html[..dialog_at].rfind("<dialog").expect("its <dialog>");
let dialog_tag_end = html[dialog_tag_start..].find('>').expect("the tag's end");
let dialog_tag = &html[dialog_tag_start..dialog_tag_start + dialog_tag_end];
assert!(
!dialog_tag.contains("open=\""),
"the bulk confirm dialog must render closed, got {dialog_tag}"
);
assert!(
dialog_tag.contains("role=\"alertdialog\""),
"the bulk confirm dialog must be an alert dialog, got {dialog_tag}"
);
assert!(
html.contains("Delete the selected records?"),
"the dialog must ask before it deletes, got {html}"
);
assert!(
html.contains("data-dialog-close"),
"the dialog needs a way out that is not deleting, got {html}"
);
let form_at = html.find("data-bulk-form").expect("the bulk form");
assert!(
form_at < dialog_at,
"the dialog must live inside the bulk form, got {html}"
);
assert!(
html.contains("Delete selected"),
"missing bulk button in {html}"
);
assert!(
html.contains("data-table-root"),
"missing table root scope in {html}"
);
let plain = Table::<User>::new(TextColumn::new(lens!(User.name)));
let page: TablePage<User> = rows.into();
let html = plain
.render(&cx, page)
.await
.unwrap()
.single()
.await
.unwrap()
.render(&cx);
assert!(
!html.contains("data-row-select") && !html.contains("data-bulk-form"),
"plain table must not render bulk chrome in {html}"
);
}