Move the connection fixing to a Before method so it applies to all the tests
[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         [Before]
14         public function setUp():void {
15             //Instantiate the connection first to prevent errors
16             Connection.getConnection();
17         }
18
19
20         [Test]
21         public function addMember():void {
22
23             var n:Node = new Node(1,1,{},true,5,10);
24
25             var rel:Relation = new Relation(1,1,{},true,[]);
26             var member:RelationMember = new RelationMember(n, "foo");
27
28             rel.appendMember(member, function(action:UndoableAction):void { action.doAction(); });
29             Assert.assertEquals(1, rel.length);
30
31         }
32
33         [Test]
34         public function spliceStuff():void {
35
36             // create an array
37             var arr:Array = ["a", "b", "c", "d"];
38             Assert.assertEquals(4, arr.length);
39
40             // doesn't actually splice onto the end, inserts at position 4
41             arr.splice(-1, 0, "e");
42             Assert.assertEquals(5, arr.length);
43             Assert.assertEquals("e", arr[3]);
44             Assert.assertEquals("d", arr[4]);
45         }
46
47         [Test]
48         public function appendMember():void {
49             var n:Node = new Node(1,1,{},true,5,10);
50             var n2:Node = new Node(2,1,{},true,5,10);
51             var n3:Node = new Node(3,1,{},true,5,10);
52
53             var member1:RelationMember = new RelationMember(n, "first");
54             var member2:RelationMember = new RelationMember(n2, "second");
55             var member3:RelationMember = new RelationMember(n3, "third");
56
57             var rel:Relation = new Relation(1,1,{},true, [member1, member2]);
58             Assert.assertEquals(2, rel.length);
59
60             rel.appendMember(member3, function(action:UndoableAction):void { action.doAction(); });
61             Assert.assertEquals(member3, rel.getMember(2));
62         }
63
64         [Test]
65         public function setMember():void {
66             var n:Node = new Node(1,1,{},true,5,10);
67             var n2:Node = new Node(2,1,{},true,5,10);
68             var n3:Node = new Node(3,1,{},true,5,10);
69
70             var member1:RelationMember = new RelationMember(n, "first");
71             var member2:RelationMember = new RelationMember(n2, "second");
72             var member3:RelationMember = new RelationMember(n3, "third");
73
74             var rel:Relation = new Relation(1,1,{},true, [member1, member2]);
75             Assert.assertEquals(2, rel.length);
76
77             rel.setMember(1, member3, function(action:UndoableAction):void { action.doAction(); });
78             Assert.assertEquals(member3, rel.getMember(1));
79
80             Assert.assertEquals(2, rel.length);
81         }
82     }
83 }