// Licensed under the Apache License, Version 2.0 (the "License"); you may not
// use this file except in compliance with the License. You may obtain a copy of
// the License at
//
//   http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
// WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
// License for the specific language governing permissions and limitations under
// the License.
define([
        'addons/documents/views-changes',
        'addons/databases/base',
        'testUtils'
], function (Views, Databases, testUtils) {
  var assert = testUtils.assert;

  describe('Documents Changes', function () {
    var filteredView;
    beforeEach(function () {
      var database = new Databases.Model({id: 'bla'});
      database.buildChanges({descending: 'true', limit: '100', include_docs: 'true'} );
      filteredView = new Views.Changes({
        model: database
      });
    });

    it('filter false in case of deleted documents in the changes feed', function () {
      filteredView.filters = [false];
      var res = filteredView.createFilteredData([
        {id: 'LALA', bar: 'ENTE'},
        {id: '1', bar: '1', deleted: true},
        {id: '2', bar: '2'}
      ]);

      assert.equal(res.length, 2);
    });
  });
});

@@ -729,78 +729,320 @@
 sert
-;%0A%0A  describe('Documents Changes', function () %7B%0A    var filteredView;
+,%0A      ViewSandbox = testUtils.ViewSandbox,%0A      viewSandbox;%0A%0A  describe('Documents Changes', function () %7B%0A    var model = new Databases.Model(%7Bid: 'foo'%7D),%0A        filteredView,%0A        view,%0A        handlerSpy;%0A%0A    model.buildChanges();%0A%0A    handlerSpy = sinon.spy(Views.Changes.prototype, 'toggleJson');%0A
 %0A   
@@ -1284,16 +1284,221 @@
      %7D);
+%0A%0A      view = new Views.Changes(%7B%0A        model: model%0A      %7D);%0A      viewSandbox = new ViewSandbox();%0A      viewSandbox.renderView(view);%0A    %7D);%0A%0A    afterEach(function () %7B%0A      viewSandbox.remove();
 %0A    %7D);
@@ -1833,16 +1833,614 @@
 %0A    %7D);
+%0A%0A    it('the toggle-json button calls a handler', function () %7B%0A      view.$('.js-toggle-json').trigger('click');%0A      assert.ok(handlerSpy.calledOnce);%0A    %7D);%0A%0A    it('rerenders on the sync event', function () %7B%0A      var spy = sinon.spy(view, 'afterRender');%0A      model.changes.trigger('sync');%0A      view.afterRender.restore();%0A      assert.ok(spy.calledOnce);%0A    %7D);%0A%0A    it('rerenders on the cachesync event', function () %7B%0A      var spy = sinon.spy(view, 'afterRender');%0A      model.changes.trigger('cachesync');%0A      assert.ok(spy.calledOnce);%0A      view.afterRender.restore();%0A    %7D);
 %0A  %7D);%0A%7D

Add tests for documents/views-changes