discourse/test/javascripts/lib/preload-store-test.js

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

66 lines
1.7 KiB
JavaScript
Raw Normal View History

import PreloadStore from "discourse/lib/preload-store";
import { Promise } from "rsvp";
2017-06-14 13:57:58 -04:00
QUnit.module("preload-store", {
beforeEach() {
PreloadStore.store("bane", "evil");
},
});
2017-06-14 13:57:58 -04:00
QUnit.test("get", (assert) => {
assert.blank(PreloadStore.get("joker"), "returns blank for a missing key");
assert.equal(
PreloadStore.get("bane"),
"evil",
"returns the value for that key"
);
});
2017-06-14 13:57:58 -04:00
QUnit.test("remove", (assert) => {
PreloadStore.remove("bane");
2017-06-14 13:57:58 -04:00
assert.blank(PreloadStore.get("bane"), "removes the value if the key exists");
});
QUnit.test(
2017-06-14 13:57:58 -04:00
"getAndRemove returns a promise that resolves to null",
async (assert) => {
assert.blank(await PreloadStore.getAndRemove("joker"));
2018-06-15 11:03:24 -04:00
}
);
QUnit.test(
2017-06-14 13:57:58 -04:00
"getAndRemove returns a promise that resolves to the result of the finder",
async (assert) => {
const finder = () => "batdance";
const result = await PreloadStore.getAndRemove("joker", finder);
2018-06-15 11:03:24 -04:00
assert.equal(result, "batdance");
2018-06-15 11:03:24 -04:00
}
);
QUnit.test(
"getAndRemove returns a promise that resolves to the result of the finder's promise",
async (assert) => {
const finder = () => Promise.resolve("hahahah");
const result = await PreloadStore.getAndRemove("joker", finder);
2018-06-15 11:03:24 -04:00
assert.equal(result, "hahahah");
2018-06-15 11:03:24 -04:00
}
);
QUnit.test(
2017-06-14 13:57:58 -04:00
"returns a promise that rejects with the result of the finder's rejected promise",
async (assert) => {
const finder = () => Promise.reject("error");
2018-06-15 11:03:24 -04:00
await PreloadStore.getAndRemove("joker", finder).catch((result) => {
2017-06-14 13:57:58 -04:00
assert.equal(result, "error");
});
2018-06-15 11:03:24 -04:00
}
);
QUnit.test("returns a promise that resolves to 'evil'", async (assert) => {
const result = await PreloadStore.getAndRemove("bane");
assert.equal(result, "evil");
});