Lines
96.15 %
Functions
81.25 %
Branches
100 %
//! Editing an account's tag rows on the manage page the way a person does.
use anyhow::{Result, anyhow, ensure};
use forms::ACCOUNT_EDIT;
use server::command::account::SetAccountTag;
use super::harness::{Harness, with_harness};
use super::page::{login, open, wait_for};
const ROWS: &str = "#nf-account-edit fieldset[data-rows=\"tags\"]";
async fn set_tag(h: &Harness, name: &str, value: &str) -> Result<()> {
SetAccountTag::new()
.user_id(h.tenant.id)
.account_id(h.account("Wallet"))
.tag_name(name.to_string())
.tag_value(value.to_string())
.run()
.await
.map_err(|e| anyhow!("{e:?}"))?;
Ok(())
}
async fn click(h: &Harness, css: &str) -> Result<()> {
let element = h.driver.find(css).await?;
h.driver.click(&element).await
async fn type_last(h: &Harness, css: &str, text: &str) -> Result<()> {
let inputs = h.driver.find_all(css).await?;
let input = inputs.last().ok_or_else(|| anyhow!("no {css}"))?;
h.driver.type_into(input, text).await
async fn stored_tags(h: &Harness) -> Result<Vec<(String, String)>> {
let values = rpc::forms::load(h.tenant.id, &ACCOUNT_EDIT, &h.account("Wallet").to_string())
let mut tags: Vec<(String, String)> = values
.rows("tags")
.unwrap_or_default()
.iter()
.map(|row| (row["name"].clone(), row["value"].clone()))
.collect();
tags.sort();
Ok(tags)
async fn replace_a_tag_row(h: &Harness) -> Result<()> {
set_tag(h, "color", "red").await?;
set_tag(h, "kind", "cash").await?;
login(h).await?;
open(
h,
&format!("/account/manage?account={}", h.account("Wallet")),
)
.await?;
wait_for(
&h.driver,
"const f = document.querySelector('#nf-account-edit');\
return f && f.hasAttribute('data-suggest-ready') ? true : null;",
vec![],
"the account edit form",
click(
&format!("{ROWS} .row-group [data-action=\"remove-row\"]"),
click(h, &format!("{ROWS} > button[data-action=\"add-row\"]")).await?;
type_last(h, &format!("{ROWS} input[name$=\".name\"]"), "owner").await?;
type_last(h, &format!("{ROWS} input[name$=\".value\"]"), "ray").await?;
click(h, "#nf-account-edit button[type=\"submit\"]").await?;
let saved = wait_for(
"const m = document.querySelector('.success-message');\
return m ? m.textContent.trim() : null;",
"the saved message",
ensure!(saved.as_str() == Some("Account saved"), "{saved}");
let tags = stored_tags(h).await?;
ensure!(
tags == [
("kind".to_string(), "cash".to_string()),
("owner".to_string(), "ray".to_string())
],
"{tags:?}"
);
#[supp_macro::shared_runtime_test]
async fn a_removed_and_an_added_tag_row_are_stored() -> Result<()> {
with_harness(|h| Box::pin(replace_a_tag_row(h))).await