1
use forms::{Action, Field, Form, FormValues, Kind, TRANSACTION_EDIT};
2

            
3
use super::row;
4
use crate::forms::copy_carried;
5

            
6
const CELLS: &[Field] = &[Field {
7
    key: "name",
8
    label: "Name",
9
    kind: Kind::Text {
10
        multiline: false,
11
        suggest: None,
12
    },
13
    required: false,
14
}];
15

            
16
const PLAIN: Form = Form {
17
    name: "test-plain",
18
    title: "Plain",
19
    fields: &[Field {
20
        key: "tags",
21
        label: "Tags",
22
        kind: Kind::Rows {
23
            fields: CELLS,
24
            nested_under: None,
25
        },
26
        required: false,
27
    }],
28
    action: Action::Mutation,
29
};
30

            
31
2
fn tagged() -> FormValues {
32
2
    let mut values = FormValues::default();
33
2
    values.push_row("tags", row(&[("name", "trip")]));
34
2
    values
35
2
}
36

            
37
#[test]
38
1
fn a_form_without_carried_fields_copies_nothing() {
39
1
    let mut to = FormValues::default();
40
1
    copy_carried(&PLAIN, &tagged(), &mut to);
41
1
    assert_eq!(to.rows("tags"), None);
42
1
}
43

            
44
#[test]
45
1
fn only_the_split_tags_are_carried_by_the_transaction_form() {
46
1
    let mut from = tagged();
47
1
    from.push_row("split-tags", row(&[("row", "r1"), ("name", "memo")]));
48
1
    let mut to = FormValues::default();
49
1
    to.push_row("splits", row(&[("key", "r1")]));
50
1
    copy_carried(&TRANSACTION_EDIT, &from, &mut to);
51
1
    assert_eq!(to.rows("split-tags"), from.rows("split-tags"));
52
1
    assert_eq!(to.rows("tags"), None);
53
1
}