2017-06-14 13:57:58 -04:00
|
|
|
QUnit.module("result-set");
|
2015-03-16 15:14:33 -04:00
|
|
|
|
|
|
|
import ResultSet from "discourse/models/result-set";
|
|
|
|
import createStore from "helpers/create-store";
|
|
|
|
|
2017-06-14 13:57:58 -04:00
|
|
|
QUnit.test("defaults", assert => {
|
2015-03-16 15:14:33 -04:00
|
|
|
const rs = ResultSet.create({ content: [] });
|
2017-06-14 13:57:58 -04: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"));
|
2015-03-16 15:14:33 -04:00
|
|
|
});
|
|
|
|
|
2017-06-14 13:57:58 -04:00
|
|
|
QUnit.test("pagination support", assert => {
|
2015-03-16 15:14:33 -04:00
|
|
|
const store = createStore();
|
2016-12-19 11:19:10 -05:00
|
|
|
return store.findAll("widget").then(function(rs) {
|
2017-06-14 13:57:58 -04: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-03-16 15:14:33 -04:00
|
|
|
|
2015-04-27 13:52:37 -04:00
|
|
|
const promise = rs.loadMore();
|
|
|
|
|
2017-06-14 13:57:58 -04:00
|
|
|
assert.ok(rs.get("loadingMore"), "it is loading more");
|
2015-04-27 13:52:37 -04:00
|
|
|
promise.then(function() {
|
2017-06-14 13:57:58 -04: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-03-16 15:14:33 -04:00
|
|
|
});
|
|
|
|
});
|
2015-04-27 13:52:37 -04:00
|
|
|
});
|
|
|
|
|
2017-06-14 13:57:58 -04:00
|
|
|
QUnit.test("refresh support", assert => {
|
2015-04-27 13:52:37 -04:00
|
|
|
const store = createStore();
|
2016-12-19 11:19:10 -05:00
|
|
|
return store.findAll("widget").then(function(rs) {
|
2017-06-14 13:57:58 -04:00
|
|
|
assert.equal(
|
|
|
|
rs.get("refreshUrl"),
|
|
|
|
"/widgets?refresh=true",
|
|
|
|
"it has the refresh url"
|
|
|
|
);
|
2015-04-27 13:52:37 -04:00
|
|
|
|
|
|
|
const promise = rs.refresh();
|
2015-03-16 15:14:33 -04:00
|
|
|
|
2017-06-14 13:57:58 -04:00
|
|
|
assert.ok(rs.get("refreshing"), "it is refreshing");
|
2015-04-27 13:52:37 -04:00
|
|
|
promise.then(function() {
|
2017-06-14 13:57:58 -04:00
|
|
|
assert.ok(!rs.get("refreshing"), "it is finished refreshing");
|
2015-04-27 13:52:37 -04:00
|
|
|
});
|
|
|
|
});
|
2017-06-14 13:57:58 -04:00
|
|
|
});
|