1
//! A Reports window counts its own palette lookups: another window's lookup never supersedes them.
2

            
3
use super::report_args::{lookup_ids, options, run};
4
use super::*;
5
use crate::tabs::fetch::Fetch;
6
use crate::tabs::reports::ReportsTab;
7

            
8
4
fn loading(app: &App, window: WindowId) -> bool {
9
4
    let state = app.win::<ReportsTab>(window).map(|tab| &tab.state);
10
4
    matches!(state, Some(Fetch::Loading { .. }))
11
4
}
12

            
13
#[tokio::test]
14
1
async fn report_lookups_of_two_windows_both_land() {
15
1
    let mut app = crate::test_support::app();
16
1
    app.attach_echo();
17
1
    let first = app.window_of(ViewId::Reports);
18
1
    run(&mut app, "reports balance target=usd");
19
1
    let second = app.open_extra(ViewId::Reports);
20
1
    run(&mut app, "reports balance target=usd");
21
1
    let ids = lookup_ids(&app);
22
1
    assert_eq!(ids.len(), 2);
23
1
    for id in ids {
24
2
        app.route_reply(id, &options(&["USD"]));
25
    }
26
1
    assert!(loading(&app, first));
27
1
    assert!(loading(&app, second));
28
1
}
29

            
30
#[tokio::test]
31
1
async fn a_lookup_reply_runs_the_report_in_its_own_window_not_the_front_one() {
32
1
    let mut app = crate::test_support::app();
33
1
    app.attach_echo();
34
1
    let first = app.window_of(ViewId::Reports);
35
1
    run(&mut app, "reports balance target=usd");
36
1
    let second = app.open_extra(ViewId::Reports);
37
1
    assert_eq!(app.front_window(), Some(second));
38
1
    let ids = lookup_ids(&app);
39
1
    app.route_reply(ids[0], &options(&["USD"]));
40
1
    assert!(loading(&app, first), "the report did not run in its window");
41
1
    assert!(!loading(&app, second), "the report ran in the front window");
42
1
}