Check that relation appending member and setting member end up in the right place
[potlatch2.git] / tests / src / net / systemeD / halcyon / connection / actions / AddMemberToRelationActionTest.as
1 package net.systemeD.halcyon.connection.actions {
2
3     import org.flexunit.Assert;
4     import net.systemeD.halcyon.connection.actions.AddMemberToRelationAction;
5     import net.systemeD.halcyon.connection.Relation;
6     import net.systemeD.halcyon.connection.Node;
7     import net.systemeD.halcyon.connection.RelationMember;
8     import net.systemeD.halcyon.connection.UndoableAction;
9     import net.systemeD.halcyon.connection.*;
10
11     public class AddMemberToRelationActionTest {
12
13         [Test]
14         public function addMember():void {
15
16             var n:Node = new Node(1,1,{},true,5,10);
17
18             var rel:Relation = new Relation(1,1,{},true,[]);
19             var member:RelationMember = new RelationMember(n, "foo");
20
21             //Instantiate the connection first to prevent errors
22             Connection.getConnection();
23             rel.appendMember(member, function(action:UndoableAction):void { action.doAction(); });
24             Assert.assertEquals(1, rel.length);
25
26         }
27
28         [Test]
29         public function spliceStuff():void {
30
31             // create an array
32             var arr:Array = ["a", "b", "c", "d"];
33             Assert.assertEquals(4, arr.length);
34
35             // doesn't actually splice onto the end, inserts at position 4
36             arr.splice(-1, 0, "e");
37             Assert.assertEquals(5, arr.length);
38             Assert.assertEquals("e", arr[3]);
39             Assert.assertEquals("d", arr[4]);
40         }
41
42         [Test]
43         public function appendMember():void {
44             var n:Node = new Node(1,1,{},true,5,10);
45             var n2:Node = new Node(2,1,{},true,5,10);
46             var n3:Node = new Node(3,1,{},true,5,10);
47
48             var member1:RelationMember = new RelationMember(n, "first");
49             var member2:RelationMember = new RelationMember(n2, "second");
50             var member3:RelationMember = new RelationMember(n3, "third");
51
52             var rel:Relation = new Relation(1,1,{},true, [member1, member2]);
53             Assert.assertEquals(2, rel.length);
54
55             rel.appendMember(member3, function(action:UndoableAction):void { action.doAction(); });
56             Assert.assertEquals(member3, rel.getMember(2));
57         }
58
59         [Test]
60         public function setMember():void {
61             var n:Node = new Node(1,1,{},true,5,10);
62             var n2:Node = new Node(2,1,{},true,5,10);
63             var n3:Node = new Node(3,1,{},true,5,10);
64
65             var member1:RelationMember = new RelationMember(n, "first");
66             var member2:RelationMember = new RelationMember(n2, "second");
67             var member3:RelationMember = new RelationMember(n3, "third");
68
69             var rel:Relation = new Relation(1,1,{},true, [member1, member2]);
70             Assert.assertEquals(2, rel.length);
71
72             rel.setMember(1, member3, function(action:UndoableAction):void { action.doAction(); });
73             Assert.assertEquals(member3, rel.getMember(1));
74
75             Assert.assertEquals(2, rel.length);
76         }
77     }
78 }