discourse/test/javascripts/models/result-set-test.js.es6

49 lines
1.5 KiB
Plaintext
Raw Normal View History

2017-06-15 01:57:58 +08:00
QUnit.module('result-set');
import ResultSet from 'discourse/models/result-set';
import createStore from 'helpers/create-store';
2017-06-15 01:57:58 +08:00
QUnit.test('defaults', assert => {
const rs = ResultSet.create({ content: [] });
2017-06-15 01:57:58 +08:00
assert.equal(rs.get('length'), 0);
assert.equal(rs.get('totalRows'), 0);
assert.ok(!rs.get('loadMoreUrl'));
assert.ok(!rs.get('loading'));
assert.ok(!rs.get('loadingMore'));
assert.ok(!rs.get('refreshing'));
});
2017-06-15 01:57:58 +08:00
QUnit.test('pagination support', assert => {
const store = createStore();
return store.findAll('widget').then(function(rs) {
2017-06-15 01:57:58 +08:00
assert.equal(rs.get('length'), 2);
assert.equal(rs.get('totalRows'), 4);
assert.ok(rs.get('loadMoreUrl'), 'has a url to load more');
assert.ok(!rs.get('loadingMore'), 'it is not loading more');
assert.ok(rs.get('canLoadMore'));
2015-04-28 01:52:37 +08:00
const promise = rs.loadMore();
2017-06-15 01:57:58 +08:00
assert.ok(rs.get('loadingMore'), 'it is loading more');
2015-04-28 01:52:37 +08:00
promise.then(function() {
2017-06-15 01:57:58 +08:00
assert.ok(!rs.get('loadingMore'), 'it finished loading more');
assert.equal(rs.get('length'), 4);
assert.ok(!rs.get('loadMoreUrl'));
assert.ok(!rs.get('canLoadMore'));
});
});
2015-04-28 01:52:37 +08:00
});
2017-06-15 01:57:58 +08:00
QUnit.test('refresh support', assert => {
2015-04-28 01:52:37 +08:00
const store = createStore();
return store.findAll('widget').then(function(rs) {
2017-06-15 01:57:58 +08:00
assert.equal(rs.get('refreshUrl'), '/widgets?refresh=true', 'it has the refresh url');
2015-04-28 01:52:37 +08:00
const promise = rs.refresh();
2017-06-15 01:57:58 +08:00
assert.ok(rs.get('refreshing'), 'it is refreshing');
2015-04-28 01:52:37 +08:00
promise.then(function() {
2017-06-15 01:57:58 +08:00
assert.ok(!rs.get('refreshing'), 'it is finished refreshing');
2015-04-28 01:52:37 +08:00
});
});
2017-06-15 01:57:58 +08:00
});