/* globals expect */
/* globals describe */
/* globals it */
/* globals sinon */

describe('Angular2 app', function() {
  this.timeout(4000);

  before(function (done) {
    // Load the HTML page.
    document.write(window.__html__['examples/angular2/dist/my-app/index.html']);

    // Set a timer before stubbing the XHR server, else it will interfere with
    // scripts loaded from the HTML page.
    setTimeout(function() {
      // Stub the xhr interface.
      window.server = sinon.createFakeServer();

      done();
    }, 3000);
  });

  after(function () {
    window.server.restore();
  });

  it('should send a valid log event', function(done) {
    var server = window.server;
    var angularComponent = window.angularAppComponent;

    server.respondWith('POST', 'api/1/item',
      [
        200,
        { 'Content-Type': 'application/json' },
        '{"err": 0, "result":{ "uuid": "d4c7acef55bf4c9ea95e4fe9428a8287"}}'
      ]
    );

    angularComponent.publicRollbarInfo();
    server.respond();

    var body = JSON.parse(server.requests[0].requestBody);

    expect(body.access_token).to.eql('POST_CLIENT_ITEM_TOKEN');
    expect(body.data.body.message.body).to.eql('angular test log');

    done();
  });
});

@@ -75,16 +75,90 @@
 non */%0A%0A
+// To make changes to the example app, see /examples/angular2/README.md.%0A%0A
 describe
@@ -676,148 +676,39 @@
 %0A%0A  
-it('should send a valid log event', function(done) %7B%0A    var server = window.server;%0A    var angularComponent = window.angularAppComponent;%0A
+function stubResponse(server) %7B
 %0A   
@@ -909,16 +909,222 @@
 %5D%0A    );
+%0A  %7D%0A%0A  it('should send a valid log event', function(done) %7B%0A    var server = window.server;%0A    var angularComponent = window.angularAppComponent;%0A%0A    stubResponse(server);%0A    server.requests.length = 0;
 %0A%0A    an
@@ -1371,24 +1371,1266 @@
 est log');%0A%0A
+    done();%0A  %7D);%0A%0A  it('should minimize Angular change detection events', function(done) %7B%0A    var server = window.server;%0A    var angularComponent = window.angularAppComponent;%0A    var doCheckCount = angularComponent.doCheckCount;%0A%0A    stubResponse(server);%0A    server.requests.length = 0;%0A%0A    angularComponent.publicRollbarInfo();%0A    server.respond();%0A%0A    // Angular triggers change detection on all events, timers, and XHR responses.%0A    // Rollbar.js exits the Angular Zone.js zone before API requests, preventing%0A    // change detection from being triggered by Rollbar reporting, and improving%0A    // performance for some apps.%0A    //%0A    // See src/browser/transport.js: _makeZoneRequest().%0A    expect(angularComponent.doCheckCount).to.eql(doCheckCount + 1);%0A%0A    done();%0A  %7D);%0A%0A  it('should report uncaught error', function(done) %7B%0A    var server = window.server;%0A%0A    stubResponse(server)%0A    server.requests.length = 0;%0A%0A    var element = document.getElementById('throw-error');%0A    element.click();%0A    server.respond();%0A%0A    var body = JSON.parse(server.requests%5B0%5D.requestBody);%0A%0A    expect(body.access_token).to.eql('POST_CLIENT_ITEM_TOKEN');%0A    expect(body.data.body.trace.exception.message).to.eql('angular test error');%0A%0A
     done();%0A

add tests for angular2 example