1
//! A cell a fill wrote is still moved by a later pick after the server
2
//! re-renders the form with errors.
3

            
4
use anyhow::{Result, ensure};
5

            
6
use super::harness::{Harness, with_harness};
7
use super::page::{Pick, login, open, pick, submit, wait_for};
8

            
9
const TO_COMMODITY: &str = "[name=\"label:splits.0.to-commodity\"]";
10

            
11
2
async fn pick_commodity(h: &Harness, name: &'static str) -> Result<()> {
12
2
    let address = "splits.0.from-commodity";
13
2
    pick(h, address, name, |l| l == name, 0, Pick::Mouse)
14
2
        .await
15
2
        .map(drop)
16
2
}
17

            
18
2
async fn to_commodity_is(h: &Harness, name: &str) -> Result<()> {
19
2
    wait_for(
20
2
        &h.driver,
21
2
        &format!("return document.querySelector('{TO_COMMODITY}').value === '{name}';"),
22
2
        vec![],
23
2
        "the to commodity to follow the from commodity",
24
2
    )
25
2
    .await
26
2
    .map(drop)
27
2
}
28

            
29
1
async fn survives_a_rerender(h: &Harness) -> Result<()> {
30
1
    login(h).await?;
31
1
    open(h, "/transaction/new").await?;
32
1
    pick_commodity(h, "JPY").await?;
33
1
    to_commodity_is(h, "JPY").await?;
34
1
    let reply = submit(h).await?;
35
1
    ensure!(
36
1
        reply.starts_with("INVALID"),
37
        "the submit was accepted: {reply}"
38
    );
39
1
    let marked = h
40
1
        .driver
41
1
        .run(
42
1
            &format!(
43
1
                "return document.querySelector('{TO_COMMODITY}').hasAttribute('data-filled');"
44
1
            ),
45
1
            vec![],
46
1
        )
47
1
        .await?;
48
1
    ensure!(marked == true, "the fill mark was lost by the re-render");
49
1
    pick_commodity(h, "EUR").await?;
50
1
    to_commodity_is(h, "EUR").await
51
1
}
52

            
53
#[supp_macro::shared_runtime_test]
54
1
async fn a_filled_cell_is_still_moved_after_a_validation_rerender() -> Result<()> {
55
1
    with_harness(|h| Box::pin(survives_a_rerender(h))).await
56
}