2018-06-15 11:03:24 -04:00
|
|
|
QUnit.module("result-set");
|
2015-03-16 15:14:33 -04:00
|
|
|
|
2018-06-15 11:03:24 -04:00
|
|
|
import ResultSet from "discourse/models/result-set";
|
|
|
|
import createStore from "helpers/create-store";
|
2015-03-16 15:14:33 -04:00
|
|
|
|
2018-06-15 11:03:24 -04:00
|
|
|
QUnit.test("defaults", assert => {
|
2020-03-02 15:20:19 -05:00
|
|
|
const resultSet = ResultSet.create({ content: [] });
|
|
|
|
assert.equal(resultSet.get("length"), 0);
|
|
|
|
assert.equal(resultSet.get("totalRows"), 0);
|
|
|
|
assert.ok(!resultSet.get("loadMoreUrl"));
|
|
|
|
assert.ok(!resultSet.get("loading"));
|
|
|
|
assert.ok(!resultSet.get("loadingMore"));
|
|
|
|
assert.ok(!resultSet.get("refreshing"));
|
2015-03-16 15:14:33 -04:00
|
|
|
});
|
|
|
|
|
2020-03-02 15:20:19 -05:00
|
|
|
QUnit.test("pagination support", async assert => {
|
2015-03-16 15:14:33 -04:00
|
|
|
const store = createStore();
|
2020-03-02 15:20:19 -05:00
|
|
|
const resultSet = await store.findAll("widget");
|
|
|
|
assert.equal(resultSet.get("length"), 2);
|
|
|
|
assert.equal(resultSet.get("totalRows"), 4);
|
|
|
|
assert.ok(resultSet.get("loadMoreUrl"), "has a url to load more");
|
|
|
|
assert.ok(!resultSet.get("loadingMore"), "it is not loading more");
|
|
|
|
assert.ok(resultSet.get("canLoadMore"));
|
|
|
|
|
|
|
|
const promise = resultSet.loadMore();
|
|
|
|
assert.ok(resultSet.get("loadingMore"), "it is loading more");
|
|
|
|
|
|
|
|
await promise;
|
|
|
|
assert.ok(!resultSet.get("loadingMore"), "it finished loading more");
|
|
|
|
assert.equal(resultSet.get("length"), 4);
|
|
|
|
assert.ok(!resultSet.get("loadMoreUrl"));
|
|
|
|
assert.ok(!resultSet.get("canLoadMore"));
|
2015-04-27 13:52:37 -04:00
|
|
|
});
|
|
|
|
|
2020-03-02 15:20:19 -05:00
|
|
|
QUnit.test("refresh support", async assert => {
|
2015-04-27 13:52:37 -04:00
|
|
|
const store = createStore();
|
2020-03-02 15:20:19 -05:00
|
|
|
const resultSet = await store.findAll("widget");
|
|
|
|
assert.equal(
|
|
|
|
resultSet.get("refreshUrl"),
|
|
|
|
"/widgets?refresh=true",
|
|
|
|
"it has the refresh url"
|
|
|
|
);
|
|
|
|
|
|
|
|
const promise = resultSet.refresh();
|
|
|
|
assert.ok(resultSet.get("refreshing"), "it is refreshing");
|
|
|
|
|
|
|
|
await promise;
|
|
|
|
assert.ok(!resultSet.get("refreshing"), "it is finished refreshing");
|
2018-06-15 11:03:24 -04:00
|
|
|
});
|