cartodb/lib/assets/test/spec/builder/components/pagination-search-view/pagination-search-model.spec.js

42 lines
1.1 KiB
JavaScript
Raw Normal View History

2020-06-15 10:58:47 +08:00
var Backbone = require('backbone');
var PaginationSearchModel = require('builder/components/pagination-search/pagination-search-model');
describe('components/pagination-search/pagination-search-model', function () {
var onFetching = jasmine.createSpy('onFetching');
var onFetched = jasmine.createSpy('onFetched');
beforeEach(function () {
this.collection = new Backbone.Collection([{
user: 'foo'
}, {
user: 'bar'
}, {
user: 'baz'
}]);
this.collection.totalCount = function () {
return 3;
};
spyOn(this.collection, 'fetch');
this.model = new PaginationSearchModel({}, {
collection: this.collection
});
this.model.on('fetching', onFetching);
this.model.on('fetched', onFetched);
});
it('should fetch a collection', function () {
this.model.fetch();
expect(this.collection.fetch).toHaveBeenCalled();
});
it('should trigger events', function () {
this.model.fetch();
expect(onFetching).toHaveBeenCalled();
this.collection.trigger('sync');
expect(onFetched).toHaveBeenCalled();
});
});