Lines
98.31 %
Functions
100 %
Branches
//! The balance report's descriptor form: change a date and the filter,
//! generate, and see the table follow while the form keeps its values.
use anyhow::{Result, ensure};
use serde_json::json;
use super::harness::{Harness, with_harness};
use super::page::{login, open, wait_for};
use super::report_filter::transfer;
const AS_OF: &str = "input[name=\"as-of\"]";
async fn rows_text(h: &Harness) -> Result<String> {
let text = h
.driver
.run(
"const t = document.querySelector('.report-data table');\
return t ? t.textContent : null;",
vec![],
)
.await?;
Ok(text.as_str().unwrap_or_default().to_string())
}
async fn set_as_of(h: &Harness, local: &str) -> Result<()> {
h.driver
"const input = document.querySelector(arguments[0]);\
input.value = arguments[1];\
input.dispatchEvent(new Event('input', { bubbles: true }));",
vec![json!(AS_OF), json!(local)],
.await
.map(drop)
async fn set_filter(h: &Harness, text: &str) -> Result<()> {
"const area = document.querySelector('textarea[name=\"filter\"]');\
area.value = arguments[0];\
area.dispatchEvent(new Event('input', { bubbles: true }));",
vec![json!(text)],
async fn generate(h: &Harness) -> Result<()> {
let button = h
.find("form.nomi-form button[type=\"submit\"]")
h.driver.click(&button).await
async fn kept(h: &Harness) -> Result<serde_json::Value> {
"return [document.querySelector(arguments[0]).value,\
document.querySelector('textarea[name=\"filter\"]').value];",
vec![json!(AS_OF)],
async fn address(h: &Harness) -> Result<String> {
let url = h.driver.run("return location.href;", vec![]).await?;
Ok(url.as_str().unwrap_or_default().to_string())
async fn reload(h: &Harness) -> Result<()> {
let url = address(h).await?;
h.driver.goto(&url).await
async fn change_and_generate(h: &Harness) -> Result<()> {
transfer(h, h.account("Wallet"), h.account("Cafe"), 600).await?;
transfer(h, h.account("Suica"), h.account("Cafe2"), 300).await?;
login(h).await?;
open(h, "/report/balance").await?;
wait_for(
&h.driver,
"return document.querySelector('.report-data table') ? true : null;",
"the default balance table",
let before = rows_text(h).await?;
ensure!(
before.contains("Wallet") && before.contains("Suica"),
"default rows: {before}"
);
set_as_of(h, "2001-01-01").await?;
generate(h).await?;
return !t || !t.textContent.includes('Wallet') ? true : null;",
"the table before any transaction",
let early = kept(h).await?;
ensure!(early == json!(["2001-01-01", ""]), "kept {early}");
address(h).await?.contains("as-of=2001-01-01"),
"address {}",
address(h).await?
reload(h).await?;
"const i = document.querySelector(arguments[0]);\
return i && i.value === '2001-01-01' ? true : null;",
"the reloaded page keeping its settings",
let filter = format!("(account= \"{}\")", h.account("Wallet"));
let today = chrono::Utc::now().format("%Y-%m-%d").to_string();
set_as_of(h, &today).await?;
set_filter(h, &filter).await?;
return t && t.textContent.includes('Wallet') ? true : null;",
"the filtered table",
let after = rows_text(h).await?;
ensure!(!after.contains("Suica"), "filtered rows: {after}");
let kept = kept(h).await?;
ensure!(kept == json!([today, filter]), "kept {kept}");
Ok(())
#[supp_macro::shared_runtime_test]
async fn changing_the_date_and_filter_regenerates_the_balance_table() -> Result<()> {
with_harness(|h| Box::pin(change_and_generate(h))).await