1
// SPDX-FileCopyrightText: 2024 Kunal Mehta <legoktm@debian.org>
2
// SPDX-License-Identifier: GPL-3.0-or-later
3
use crate::prelude::*;
4
use crate::tests::test_client;
5
use crate::Result;
6

            
7
#[tokio::test]
8
3
async fn test_indicator() -> Result<()> {
9
3
    let client = test_client::mw_client();
10
3
    let code = client
11
3
        .transform_to_html(
12
3
            r#"<indicator name="test">[[Some wikitext]]</indicator>"#,
13
3
        )
14
3
        .await?
15
3
        .into_mutable();
16
3
    dbg!(code.to_string());
17
3
    let indicators: Vec<_> = code
18
3
        .inclusive_descendants()
19
43
        .filter_map(|node| node.as_indicator())
20
3
        .collect();
21
3
    dbg!(&indicators);
22
3
    assert_eq!(indicators.len(), 1);
23
3
    let indicator = &indicators[0];
24
3
    assert_eq!(&indicator.name()?, "test");
25
3
    assert_eq!(&indicator.wikitext()?, "[[Some wikitext]]");
26
3
    indicator.set_name("new name")?;
27
3
    indicator.set_wikitext("[[A new link]]")?;
28
3
    let wikitext = client.transform_to_wikitext(&code).await?;
29
3
    assert_eq!(
30
3
        &wikitext,
31
3
        "<indicator name=\"new name\">[[A new link]]</indicator>"
32
3
    );
33
3
    Ok(())
34
2
}
35

            
36
#[tokio::test]
37
3
async fn test_new_indicator() -> Result<()> {
38
3
    let client = test_client::mw_client();
39
3
    let code = Wikicode::new("");
40
3
    code.prepend(&Indicator::new("test", "[[wikitext]]")?);
41
3
    let wikitext = client.transform_to_wikitext(&code).await?;
42
3
    assert_eq!(
43
3
        wikitext,
44
3
        "<indicator name=\"test\">[[wikitext]]</indicator>"
45
3
    );
46
3
    Ok(())
47
2
}