aboutsummaryrefslogtreecommitdiffstats
path: root/notmuch/tests/test_thread.rs
blob: 89f1ea00fbd065e88227cc82ca99ab530e4b00e4 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
use std::sync::Arc;
use fixtures::{NotmuchCommand, MailBox};


struct ThreadFixture {
    // Return a single thread with 2 messages
    pub mailbox: MailBox,
    pub thread: notmuch::Thread<'static, 'static>,
}

impl ThreadFixture {
    pub fn new() -> Self{
        let mailbox = MailBox::new();

        let (msgid, _) = mailbox.deliver(None, Some("foo".to_string()), None, None, vec![],  true, None, false, false, false).unwrap();
        mailbox.deliver(None, Some("bar".to_string()), None, None, vec![("In-Reply-To".to_string(), format!("<{}>", msgid))], true, None, false, false, false).unwrap();

        let cmd = NotmuchCommand::new(&mailbox.path());
        cmd.run(vec!["new"]).unwrap();

        let mut threads = {
            let database = Arc::new(notmuch::Database::open(&mailbox.path(), notmuch::DatabaseMode::ReadWrite).unwrap());

            let query = notmuch::Query::create(database.clone(), &"foo".to_string()).unwrap();

            <notmuch::Query as notmuch::QueryExt>::search_threads(query).unwrap()
        };
        let thread = threads.next().unwrap();
    
        Self {
            mailbox,
            thread
        }
    }
}

#[test]
fn test_threadid() {
    let thread = ThreadFixture::new();
    assert!(!thread.thread.id().is_empty());
}


#[test]
fn test_toplevel() {
    let thread = ThreadFixture::new();
    let msgs = thread.thread.toplevel_messages();

    assert_eq!(msgs.count(), 1);
}


#[test]
fn test_toplevel_reply() {
    let thread = ThreadFixture::new();
    let msg = thread.thread.toplevel_messages().next().unwrap();

    assert_eq!(msg.replies().count(), 1);
}

#[test]
fn test_iter() {
    let thread = ThreadFixture::new();
    let msg_count0 = thread.thread.messages().count() as i32;
    let msg_count1 = thread.thread.total_messages();

    assert_eq!(msg_count0, msg_count1);
}

#[test]
fn test_matched() {
    let thread = ThreadFixture::new();
    assert_eq!(thread.thread.matched_messages(), 1);
}


#[test]
fn test_authors() {
    let thread = ThreadFixture::new();

    assert_eq!(thread.thread.authors(), vec!["src@example.com".to_string()]);
}


#[test]
fn test_subject() {
    let thread = ThreadFixture::new();

    println!("{:?}", thread.thread.subject());
    assert_eq!(thread.thread.subject(), "Test mail");
}



#[test]
fn test_tags() {
    let thread = ThreadFixture::new();

    let tags: Vec<String> = thread.thread.tags().collect();
    assert!(tags.iter().any(|x| x == "inbox"));
}