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

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

50 lines
1.6 KiB
JavaScript
Raw Normal View History

2017-06-14 13:57:58 -04:00
QUnit.module("result-set");
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 => {
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"));
});
QUnit.test("pagination support", async assert => {
const store = createStore();
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
});
QUnit.test("refresh support", async assert => {
2015-04-27 13:52:37 -04:00
const store = createStore();
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");
2017-06-14 13:57:58 -04:00
});