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

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

103 lines
2.4 KiB
Plaintext
Raw Normal View History

2016-07-05 02:15:51 +08:00
import PreloadStore from "preload-store";
import { asyncTestDiscourse } from "helpers/qunit-helpers";
import { Promise } from "rsvp";
2017-06-15 01:57:58 +08:00
QUnit.module("preload-store", {
beforeEach() {
PreloadStore.store("bane", "evil");
}
});
2017-06-15 01:57:58 +08: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-15 01:57:58 +08:00
QUnit.test("remove", assert => {
PreloadStore.remove("bane");
2017-06-15 01:57:58 +08:00
assert.blank(PreloadStore.get("bane"), "removes the value if the key exists");
});
2017-06-15 01:57:58 +08:00
asyncTestDiscourse(
"getAndRemove returns a promise that resolves to null",
function(assert) {
assert.expect(1);
2017-06-15 01:57:58 +08:00
const done = assert.async();
PreloadStore.getAndRemove("joker").then(function(result) {
2017-06-15 01:57:58 +08:00
assert.blank(result);
2018-06-15 23:03:24 +08:00
done();
});
}
);
2017-06-15 01:57:58 +08:00
asyncTestDiscourse(
"getAndRemove returns a promise that resolves to the result of the finder",
function(assert) {
assert.expect(1);
2018-06-15 23:03:24 +08:00
2017-06-15 01:57:58 +08:00
const done = assert.async();
const finder = function() {
return "batdance";
2018-06-15 23:03:24 +08:00
};
PreloadStore.getAndRemove("joker", finder).then(function(result) {
2017-06-15 01:57:58 +08:00
assert.equal(result, "batdance");
2018-06-15 23:03:24 +08:00
done();
});
}
);
2017-06-15 01:57:58 +08:00
asyncTestDiscourse(
"getAndRemove returns a promise that resolves to the result of the finder's promise",
2017-06-15 01:57:58 +08:00
function(assert) {
assert.expect(1);
2018-06-15 23:03:24 +08:00
2017-06-15 01:57:58 +08:00
const finder = function() {
return new Promise(function(resolve) {
2014-09-25 02:17:09 +08:00
resolve("hahahah");
2018-06-15 23:03:24 +08:00
});
};
2017-06-15 01:57:58 +08:00
const done = assert.async();
PreloadStore.getAndRemove("joker", finder).then(function(result) {
2017-06-15 01:57:58 +08:00
assert.equal(result, "hahahah");
done();
});
2018-06-15 23:03:24 +08:00
}
);
2017-06-15 01:57:58 +08:00
asyncTestDiscourse(
"returns a promise that rejects with the result of the finder's rejected promise",
function(assert) {
assert.expect(1);
2018-06-15 23:03:24 +08:00
2017-06-15 01:57:58 +08:00
const finder = function() {
return new Promise(function(resolve, reject) {
2014-09-25 02:17:09 +08:00
reject("error");
});
};
2018-06-15 23:03:24 +08:00
2017-06-15 01:57:58 +08:00
const done = assert.async();
PreloadStore.getAndRemove("joker", finder).then(null, function(result) {
2017-06-15 01:57:58 +08:00
assert.equal(result, "error");
done();
});
2018-06-15 23:03:24 +08:00
}
);
2017-06-15 01:57:58 +08:00
asyncTestDiscourse("returns a promise that resolves to 'evil'", function(
assert
) {
assert.expect(1);
2017-06-15 01:57:58 +08:00
const done = assert.async();
PreloadStore.getAndRemove("bane").then(function(result) {
2017-06-15 01:57:58 +08:00
assert.equal(result, "evil");
done();
});
});