Lines
100 %
Functions
Branches
use forms::{REPORT_CATEGORY, TRANSACTION_CREATE, TRANSACTION_QUERY};
use super::tests::{all_controls, filled};
use super::*;
fn html_of(form: &'static Form) -> String {
render_form(
form,
&filled(form, Some(1)),
&[],
"/x",
&References::default(),
)
.unwrap()
}
fn attr_of(html: &str, name: &str, attr: &str) -> Option<String> {
all_controls(html)
.iter()
.find(|c| c.attr("name") == Some(name))
.and_then(|c| c.attr(attr).map(str::to_string))
#[test]
fn tag_cells_name_their_suggestion_endpoint() {
let html = html_of(&TRANSACTION_CREATE);
for (name, url, by) in [
(
"tags.0.name",
"/api/forms/suggestions/transaction-tag-names",
None,
),
"tags.0.value",
"/api/forms/suggestions/transaction-tag-values",
Some("name"),
"split-tags.0.name",
"/api/forms/suggestions/split-tag-names",
"split-tags.0.value",
"/api/forms/suggestions/split-tag-values",
] {
assert_eq!(
attr_of(&html, name, "data-suggest").as_deref(),
Some(url),
"{name}"
);
attr_of(&html, name, "data-suggest-by").as_deref(),
by,
fn pickers_and_suggest_inputs_suppress_browser_autofill() {
for name in [
"label:splits.0.from",
"label:splits.0.to",
attr_of(&html, name, "autocomplete").as_deref(),
Some("off"),
fn other_cells_carry_no_suggestion_endpoint() {
"note",
"tags.0.description",
"split-tags.0.row",
"splits.0.value",
"splits.0.key",
let found = all_controls(&html)
.into_iter()
.find(|c| c.attr("name") == Some(name));
assert!(
found.is_some_and(|c| c.attr("data-suggest").is_none()),
fn only_the_from_cells_fill() {
let fills = |name: &str| attr_of(&html, name, "data-fills");
fills("label:splits.0.from").as_deref(),
Some("from-commodity")
fills("label:splits.0.from-commodity").as_deref(),
Some("to-commodity")
assert_eq!(html.matches("data-fills=").count(), 4);
"label:splits.0.to-commodity",
assert_eq!(fills(name), None, "{name}");
fn select_cells_keep_their_source() {
let html = html_of(&TRANSACTION_QUERY);
attr_of(&html, "label:account", "data-source").as_deref(),
Some("accounts")
assert_eq!(attr_of(&html, "label:account", "data-fills"), None);
assert_eq!(attr_of(&html, "account", "type").as_deref(), Some("hidden"));
fn the_report_filter_is_a_textarea_in_the_builder_container() {
let mut values = FormValues::default();
values.set("filter", "(and)");
let html = render_form(
&forms::REPORT_BALANCE,
&values,
.unwrap();
assert!(html.contains("tag-filter-container"), "{html}");
assert!(html.contains("tag-filter-visual"), "{html}");
html.contains("name=\"filter\"\n class=\"tag-filter-sexpr\""),
"{html}"
assert!(html.contains(">\n(and)</textarea>"), "{html}");
fn report_and_list_dates_are_whole_days_and_transaction_dates_stay_instants() {
let report = html_of(&forms::REPORT_BALANCE);
let list = html_of(&forms::TRANSACTION_QUERY);
let transaction = html_of(&TRANSACTION_CREATE);
for name in ["from", "to"] {
list.contains(&format!("type=\"date\" name=\"{name}\"")),
"{list}"
assert!(!list.contains("datetime-local"), "{list}");
assert!(report.contains("type=\"date\" name=\"as-of\""), "{report}");
assert!(!report.contains("datetime-local"), "{report}");
assert!(transaction.contains("datetime-local"), "{transaction}");
fn entity_edit_tag_cells_suggest_that_entitys_tags() {
for (form, owner) in [
(&forms::ACCOUNT_EDIT, "account"),
(&forms::COMMODITY_EDIT, "commodity"),
let html = html_of(form);
attr_of(&html, "tags.0.name", "data-suggest").as_deref(),
Some(format!("/api/forms/suggestions/{owner}-tag-names").as_str()),
"{owner}"
attr_of(&html, "tags.0.value", "data-suggest").as_deref(),
Some(format!("/api/forms/suggestions/{owner}-tag-values").as_str()),
assert_eq!(attr_of(&html, "tags.0.name", "data-suggest-by"), None);
attr_of(&html, "tags.0.value", "data-suggest-by").as_deref(),
fn every_form_with_tag_rows_suggests_tag_names() {
let tagged: Vec<_> = forms::all()
.filter(|form| {
form.fields
.any(|f| f.key == "tags" && matches!(f.kind, forms::Kind::Rows { .. }))
})
.collect();
assert!(tagged.len() >= 4, "{}", tagged.len());
for form in tagged {
attr_of(&html, "tags.0.name", "data-suggest").is_some(),
"{}",
form.name
fn the_report_category_tag_name_suggests_split_tag_names() {
let html = html_of(&REPORT_CATEGORY);
attr_of(&html, "tag", "data-suggest").as_deref(),
Some("/api/forms/suggestions/split-tag-names")
assert_eq!(attr_of(&html, "tag", "data-suggest-by"), None);
fn only_the_to_commodity_cell_carries_its_empty_meaning() {
let hint = |name: &str| attr_of(&html, name, "placeholder");
assert_eq!(hint("label:splits.0.to-commodity").as_deref(), Some("same"));
for name in ["label:splits.0.from-commodity", "label:splits.0.to"] {
assert_eq!(hint(name), None, "{name}");