Lines
100 %
Functions
Branches
//! A double click on a create form sends one request and stores one record.
use anyhow::{Result, ensure};
use super::harness::{Harness, with_harness};
use super::page::{login, open, set_text, wait_for};
use super::rows::{Split, fill_splits};
use crate::common::tenant::tenant_connection;
async fn stored_transactions(h: &Harness) -> Result<i64> {
let mut conn = tenant_connection(h.tenant.id).await;
Ok(sqlx::query_scalar("SELECT count(*) FROM transactions")
.fetch_one(&mut *conn)
.await?)
}
async fn double_click(h: &Harness) -> Result<()> {
h.driver
.run(
"window.__posts = 0;\
const send = XMLHttpRequest.prototype.send;\
XMLHttpRequest.prototype.send = function (...args) { window.__posts += 1; return send.apply(this, args); };\
const button = document.querySelector('form.nomi-form button[type=\"submit\"]');\
button.click(); button.click();",
vec![],
)
.await
.map(drop)
async fn creates_once(h: &Harness) -> Result<()> {
login(h).await?;
open(h, "/transaction/new").await?;
fill_splits(h, &[Split::plain("Suica", "JR", "199")]).await?;
let before = stored_transactions(h).await?;
double_click(h).await?;
let reply = wait_for(
&h.driver,
"const box = document.querySelector('form.nomi-form .result-box');\
return box && box.textContent.includes('created with ID') ? {posts: window.__posts} : null;",
"the create reply",
.await?;
let posts = &reply["posts"];
ensure!(posts == 1, "requests sent: {posts}");
let stored = stored_transactions(h).await? - before;
ensure!(stored == 1, "transactions stored: {stored}");
Ok(())
#[supp_macro::shared_runtime_test]
async fn a_double_click_on_create_stores_one_transaction() -> Result<()> {
with_harness(|h| Box::pin(creates_once(h))).await
async fn creates_tag_once(h: &Harness) -> Result<()> {
open(h, "/tag/create").await?;
set_text(h, "name", "double").await?;
set_text(h, "value", "click").await?;
return box && box.textContent.includes('New tag id') ? {posts: window.__posts} : null;",
"the tag create reply",
async fn a_double_click_on_tag_create_sends_one_request() -> Result<()> {
with_harness(|h| Box::pin(creates_tag_once(h))).await
async fn stored_artifacts(h: &Harness) -> Result<i64> {
Ok(sqlx::query_scalar("SELECT count(*) FROM artifacts")
async fn creates_script_once(h: &Harness) -> Result<()> {
open(h, "/script/create").await?;
let before = stored_artifacts(h).await?;
set_text(h, "source", "(+ 1 2)").await?;
return box && box.textContent.includes('Script created') ? {posts: window.__posts} : null;",
"the script create reply",
let stored = stored_artifacts(h).await? - before;
ensure!(stored == 1, "scripts stored: {stored}");
async fn a_double_click_on_script_create_stores_one_script() -> Result<()> {
with_harness(|h| Box::pin(creates_script_once(h))).await