describe("Initialisation", function() {

  beforeEach(function(){
   this.addMatchers({
     toBeA: function(expected) { return this.env.equals_(this.actual, jasmine.any(expected)); }
   });
 });

  it("requires a Firebase reference", function() {
    expect(Parallel.init()).toBe(false);
    expect(Parallel.init(false)).toBe(false);
    expect(Parallel.init("")).toBe(false);
    expect(Parallel.init("invalid")).toBe(false);
    expect(Parallel.init("https://something.firebaseio-demo.com/")).toBe(true);
    expect(Parallel.init("https://something.firebaseio.com/more/")).toBe(true);
  });
});

describe("DOM Manipulation", function() {
  it("can create a selector for a specific node", function() {
    
    var parent = document.createElement("DIV");
    parent.classList.add("parent");
    parent.classList.add("node");
    parent.id = "parent-id";
    var child = document.createElement("SPAN");
    child.className = "child node";
    child.id = "child-id";
    parent.appendChild(child);
    document.body.appendChild(parent);
    
    var docChild = document.querySelector("span.child");
    
    expect(docChild).not.toBeNull();
    
    expect(Parallel.selector(child)).toBe("div#parent-id.parent.node span#child-id.child.node");
  });
});

describe("Parallel Event Management", function() {
  
  it("can trigger events on an element", function() {
    var Handler = function(){};
    Handler.onclick = function(arg){};
    spyOn(Handler, "onclick");
    var element = document.createElement("DIV");
    element.addEventListener("click", Handler.onclick);
    document.body.appendChild(element);
    
    expect(Handler.onclick).not.toHaveBeenCalled();
    Parallel.trigger(element,"click");
    expect(Handler.onclick).toHaveBeenCalled();
  });

  it("can trigger events based on a selector", function() {
    expect(true).toBe(false);
  });

  it("Events triggered bu Parallel are not processed by it", function() {
    expect(true).toBe(false);
  });

});

@@ -1302,52 +1302,75 @@
 ) %7B%0A
-  
 %0A  
-it(%22can trigger events on an element%22, 
+var Handler = function()%7B%7D,%0A      element = null;%0A%0A  beforeEach(
 func
@@ -1379,26 +1379,55 @@
 on()
- 
 %7B%0A    
-var
+document.body.innerHTML = '';%0A   
  Handler
  = f
@@ -1414,32 +1414,39 @@
  '';%0A    Handler
+.handle
  = function()%7B%7D;
@@ -1441,19 +1441,51 @@
 unction(
-)%7B%7D
+arg)%7B%7D%0A    spyOn(Handler, %22handle%22)
 ;%0A    Ha
@@ -1552,20 +1552,16 @@
 %22);%0A    
-var 
 element 
@@ -1589,24 +1589,51 @@
 ent(%22DIV%22);%0A
+    element.id = 'unique';%0A
     element.
@@ -1722,355 +1722,1048 @@
 ;%0A  
+%7D);%0A
   %0A  
-  expect(Handler.onclick).not.toHaveBeenCalled();%0A    Parallel.trigger(element,%22click%22);%0A    expect(Handler.onclick).toHaveBeenCalled();%0A  %7D);%0A%0A  it(%22can trigger events based on a selector%22, function() %7B%0A    expect(true).toBe(false);%0A  %7D);%0A%0A  it(%22Events triggered bu Parallel are not processed by it%22, function() %7B%0A    expect(true).toBe(false
+it(%22Can handle an Event%22, function() %7B%0A    Parallel.chain(Handler.handle);%0A    expect(Handler.handle).not.toHaveBeenCalled();%0A%0A    var eventObj = document.createEvent('HTMLEvents');%0A    eventObj.initEvent('click', true, true);%0A    element.dispatchEvent(eventObj);%0A    expect(Handler.handle).toHaveBeenCalled();%0A  %7D);%0A%0A  it(%22can trigger events on an element%22, function() %7B%0A    expect(Handler.onclick).not.toHaveBeenCalled();%0A    Parallel.trigger(element,%22click%22);%0A    expect(Handler.onclick).toHaveBeenCalled();%0A  %7D);%0A%0A  it(%22can trigger events based on a selector%22, function() %7B%0A    expect(Handler.onclick).not.toHaveBeenCalled();%0A    Parallel.trigger('div#unique',%22click%22);%0A    expect(Handler.onclick).toHaveBeenCalled();%0A  %7D);%0A%0A  it(%22Events triggered bu Parallel are not processed by it%22, function() %7B%0A    expect(Handler.onclick).not.toHaveBeenCalled();%0A    Parallel.chain(Handler.handle);%0A    Parallel.trigger('div#unique','click');%0A    expect(Handler.onclick.calls.length).toBe(1);%0A    expect(Handler.handle.calls.length).toBe(0
 );%0A 
@@ -2767,13 +2767,12 @@
 ;%0A  %7D);%0A
-%0A
 %7D);%0A

Test coverage for event handling