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

54 lines
1.6 KiB
Plaintext
Raw Normal View History

2018-06-15 23:03:24 +08:00
QUnit.module("result-set");
2018-06-15 23:03:24 +08:00
import ResultSet from "discourse/models/result-set";
import createStore from "helpers/create-store";
2018-06-15 23:03:24 +08:00
QUnit.test("defaults", assert => {
const rs = ResultSet.create({ content: [] });
2018-06-15 23:03:24 +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"));
});
2018-06-15 23:03:24 +08:00
QUnit.test("pagination support", assert => {
const store = createStore();
2018-06-15 23:03:24 +08:00
return store.findAll("widget").then(function(rs) {
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();
2018-06-15 23:03:24 +08:00
assert.ok(rs.get("loadingMore"), "it is loading more");
2015-04-28 01:52:37 +08:00
promise.then(function() {
2018-06-15 23:03:24 +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
});
2018-06-15 23:03:24 +08:00
QUnit.test("refresh support", assert => {
2015-04-28 01:52:37 +08:00
const store = createStore();
2018-06-15 23:03:24 +08:00
return store.findAll("widget").then(function(rs) {
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();
2018-06-15 23:03:24 +08:00
assert.ok(rs.get("refreshing"), "it is refreshing");
2015-04-28 01:52:37 +08:00
promise.then(function() {
2018-06-15 23:03:24 +08:00
assert.ok(!rs.get("refreshing"), "it is finished refreshing");
2015-04-28 01:52:37 +08:00
});
});
2018-06-15 23:03:24 +08:00
});