           @linkManager.toJsonString().should.match(/"links":/)
           @linkManager.toJsonString().should.equal(@serializedForm)
 
-      describe "loadData", () ->
-        beforeEach () ->
+      describe "loadData", ->
+        beforeEach ->
           @linkManager = new LinkManager()
-        it "should read the serialized data without error", () ->
+        it "should read the serialized data without error", ->
           data = JSON.parse(@serializedForm)
           @linkManager.loadData(data)
           @linkManager.nodeKeys.should.have.any.keys("a")

        targetTerminal: 'b',
        title: 'unkown link'
      )
    it "should have a reasonable text based terminalKey", () ->
      @link.terminalKey().should.equal("source[a] ---Link-1---> target[b]")

describe 'Node', () ->
  beforeEach () ->
    @node_a = new Node({title: "Node a"},'a')
    @node_b = new Node({title: "Node b"},'b')
    @node_c = new Node({title: "Node c"},'c')

        targetTerminal: "a"
        sourceTerminal: "b"
      })
      @newLink.terminalKey = ->
        "newLink"

      @otherNewLink = new Link({
        sourceNode: @nodeB
        targetNode: @nodeA
      })
      @otherNewLink.terminalKey = ->
        "otherNewLink"

    describe "addLink", ->
      describe "When the link doesn't already exist", ->
        it "should add a new link", ->
          should.not.exist @linkManager.linkKeys['newLink']
          @linkManager.addLink(@newLink).should.equal(true)
          @linkManager.addLink(@otherNewLink).should.equal(true)
          @linkManager.linkKeys['newLink'].should.equal(@newLink)
          @linkManager.linkKeys['otherNewLink'].should.equal(@otherNewLink)
      describe "When the link does already exist", ->
        beforeEach ->
          @linkManager.linkKeys['newLink'] = 'oldValue'
        it "should not add the new link", ->
          @linkManager.addLink(@newLink).should.equal(false)
          @linkManager.linkKeys['newLink'].should.equal('oldValue')

    describe "Serialization", ->
      beforeEach ->
        @serializedForm = """{"version":0.1,"filename":null,"nodes":[{"title":"a","x":10,"y":10,"key":"a"},{"title":"b","x":20,"y":20,"key":"b"}],"links":[{"title":"","color":"#777","sourceNodeKey":"a","sourceTerminal":"b","targetNodeKey":"b","targetTerminal":"a"}],"imageMetadata":{}}"""

      describe "toJsonString", ->
        it "should include nodes and links", ->
          expectedValue = "{}"
          @nodeA.key.should.equal("a")
          @linkManager.addLink(@newLink)
