1
/*
2
Copyright (C) 2022 Kunal Mehta <legoktm@debian.org>
3

            
4
This program is free software: you can redistribute it and/or modify
5
it under the terms of the GNU General Public License as published by
6
the Free Software Foundation, either version 3 of the License, or
7
(at your option) any later version.
8

            
9
This program is distributed in the hope that it will be useful,
10
but WITHOUT ANY WARRANTY; without even the implied warranty of
11
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12
GNU General Public License for more details.
13

            
14
You should have received a copy of the GNU General Public License
15
along with this program.  If not, see <http://www.gnu.org/licenses/>.
16
 */
17
use crate::prelude::*;
18
use crate::tests::test_client;
19
use anyhow::Result;
20

            
21
#[tokio::test]
22
3
async fn test_gallery() -> Result<()> {
23
3
    let client = test_client::testwp_client();
24
3
    let code = client.get("Mwbot-rs/Gallery").await?.into_mutable();
25
3
    let galleries: Vec<_> = code
26
3
        .inclusive_descendants()
27
111
        .filter_map(|node| node.as_gallery())
28
3
        .collect();
29
3
    assert_eq!(galleries.len(), 1);
30
3
    assert_eq!(galleries[0].caption().unwrap(), "caption1");
31
3
    galleries[0].set_caption("test".to_string())?;
32
3
    assert_eq!(galleries[0].caption().unwrap(), "test");
33
3
    let images = galleries[0].images();
34
3
    assert_eq!(images.len(), 3);
35
3
    assert_eq!(images[0].title(), "File:Image.jpg");
36
3
    assert_eq!(images[1].title(), "File:Foobar.jpg");
37
3
    assert_eq!(
38
3
        images[2].title(),
39
3
        "File:Drop of water on water-resistant textile (100% polyester).jpg"
40
3
    );
41
2

            
42
3
    let code = client.get("Mwbot-rs/Gallery2").await?.into_mutable();
43
3
    let galleries: Vec<_> = code
44
3
        .inclusive_descendants()
45
65
        .filter_map(|node| node.as_gallery())
46
3
        .collect();
47
3
    assert_eq!(galleries.len(), 1);
48
3
    assert_eq!(galleries[0].caption(), None);
49
3
    galleries[0].set_caption("test2".to_string())?;
50
3
    assert_eq!(galleries[0].caption().unwrap(), "test2");
51
2

            
52
3
    Ok(())
53
2
}