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

Failed to ignore revisions in .git-blame-ignore-revs.

50 lines
1.6 KiB
JavaScript
Raw Normal View History

2018-06-15 11:03:24 -04:00
QUnit.module("result-set");
2018-06-15 11:03:24 -04:00
import ResultSet from "discourse/models/result-set";
import createStore from "helpers/create-store";
2018-06-15 11:03:24 -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");
2018-06-15 11:03:24 -04:00
});