1
use super::*;
2
use crate::form_render::fixture::assert_fixture;
3

            
4
6
fn render(scripts: Vec<ScriptData>) -> String {
5
6
    ScriptTableTemplate { scripts }.render().unwrap()
6
6
}
7

            
8
8
fn row(id: u128, name: Option<&str>, enabled: bool) -> ScriptData {
9
8
    ScriptData {
10
8
        id: Uuid::from_u128(id),
11
8
        name: name.map(str::to_string),
12
8
        size: 8,
13
8
        enabled,
14
8
    }
15
8
}
16

            
17
#[test]
18
2
fn delete_is_an_htmx_post_into_the_tables_own_result_box() {
19
2
    let html = render(vec![row(7, Some("tag-sync"), true)]);
20
2
    let id = Uuid::from_u128(7);
21
2
    assert!(html.contains(&format!(r#"hx-post="/api/script/delete/{id}""#)));
22
2
    assert!(html.contains(r##"hx-target="#script-delete-result""##));
23
2
    assert!(html.contains(r#"id="script-delete-result""#));
24
2
    assert!(!html.contains("deleteScript"));
25
2
}
26

            
27
#[test]
28
2
fn the_row_is_removed_only_after_a_successful_request() {
29
2
    let html = render(vec![row(7, None, false)]);
30
2
    assert!(html.contains("if (event.detail.successful) this.closest('tr').remove()"));
31
2
}
32

            
33
#[test]
34
2
fn the_browser_fixture_of_the_script_list_is_up_to_date() {
35
2
    let html = render(vec![row(7, Some("tag-sync"), true), row(8, None, false)]);
36
2
    assert_fixture("script_list.html", &html);
37
2
}