Lines
95.45 %
Functions
100 %
Branches
//! Every page loads clean; buttons say what they do; a refusal is a page.
use anyhow::{Result, ensure};
use serde_json::json;
use super::checks::check_page;
use super::harness::{Harness, with_harness};
use super::page::{
Pick, add_split, add_split_tag, button_texts, login, open, pick, submit, wait_for,
};
use super::report_filter::transfer_in;
use super::rows::named;
const PAGES: &[(&str, &str)] = &[
("/transaction/list", "list"),
("/transaction/new", "new"),
("/report/activity", "report-activity"),
("/report/category-breakdown", "report-category"),
];
/// Real-sized amounts and a two-commodity balance, which a phone table that
/// cannot wrap them pushes past the screen.
async fn long_rows(h: &Harness) -> Result<()> {
let (bank, suica) = (h.account("Bank"), h.account("Suica"));
transfer_in(h, "JPY", bank, suica, 1_234_567).await?;
transfer_in(h, "EUR", bank, suica, 98_765).await
}
async fn pages_load(h: &Harness) -> Result<()> {
long_rows(h).await?;
login(h).await?;
open(h, "/").await?;
wait_for(
&h.driver,
"return document.querySelectorAll('.account-status .account-row').length > 0;",
vec![],
"the home account table",
)
.await?;
check_page(h, "home", &[]).await?;
for (path, name) in PAGES {
open(h, path).await?;
check_page(h, name, &[]).await?;
open(h, "/transaction/list").await?;
pick(h, "account", "Suica", named("Suica"), 0, Pick::Mouse).await?;
let query = h
.driver
.find("form.nomi-form button[type=\"submit\"]")
h.driver.click(&query).await?;
let url = wait_for(
"return location.search.includes('account=') ? location.search : null;",
"the filtered list",
let suica = h.account("Suica").to_string();
ensure!(
url.as_str()
.is_some_and(|q| q.contains(&format!("account={suica}"))),
"the filter posts {url}"
);
check_page(h, "list-filtered", &[]).await
#[supp_macro::shared_runtime_test]
async fn every_page_loads_without_errors() -> Result<()> {
with_harness(|h| Box::pin(pages_load(h))).await
async fn buttons(h: &Harness) -> Result<()> {
open(h, "/transaction/new").await?;
add_split_tag(h, 0).await?;
add_split(h).await?;
let texts = button_texts(h).await?;
texts
== [
"Remove split",
"Remove split tag",
"Add split tag",
"Add tag",
"Add split",
"Create transaction",
],
"create page buttons: {texts:?}"
let legs = h
.run(
"return [...document.querySelectorAll('select[name=\"split-tags.0.side\"] option')]\
.map(o => o.textContent.trim());",
legs == json!(["Both accounts", "From account only", "To account only"]),
"leg choices: {legs}"
let titles = h
"return [...document.querySelectorAll('[data-row=\"splits\"] > label > span:first-child')]\
.slice(0, 6).map(s => s.textContent.trim());",
titles
== json!([
"From",
"To",
"From commodity",
"Value",
"To commodity",
"To amount"
]),
"split titles: {titles}"
check_page(h, "new-buttons", &[]).await?;
texts == ["Show transactions"],
"list filter buttons: {texts:?}"
Ok(())
async fn buttons_name_what_they_do() -> Result<()> {
with_harness(|h| Box::pin(buttons(h))).await
async fn refusals(h: &Harness) -> Result<()> {
for (path, status) in [
("/transaction/not-a-uuid/edit", 400),
(
"/transaction/00000000-0000-4000-8000-000000000000/edit",
404,
),
] {
h.driver.goto(&h.url(path)).await?;
let page = h
"return [document.contentType, !!document.querySelector('link[href$=\"/style.css\"]'),\
document.body.innerText];",
ensure!(page[0] == json!("text/html"), "{path}: {page}");
ensure!(page[1] == json!(true), "{path} is not a full page: {page}");
check_page(h, &format!("refusal-{status}"), &[status]).await?;
let reply = submit(h).await?;
reply.starts_with("INVALID: "),
"an empty create was not refused: {reply}"
check_page(h, "new-refused", &[422]).await
async fn refusals_are_html_pages_and_inline_errors() -> Result<()> {
with_harness(|h| Box::pin(refusals(h))).await