mirror of
https://github.com/discourse/discourse.git
synced 2024-11-26 06:23:43 +08:00
102 lines
2.3 KiB
JavaScript
102 lines
2.3 KiB
JavaScript
import PreloadStore from "preload-store";
|
|
import { asyncTestDiscourse } from "helpers/qunit-helpers";
|
|
|
|
QUnit.module("preload-store", {
|
|
beforeEach() {
|
|
PreloadStore.store("bane", "evil");
|
|
}
|
|
});
|
|
|
|
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"
|
|
);
|
|
});
|
|
|
|
QUnit.test("remove", assert => {
|
|
PreloadStore.remove("bane");
|
|
assert.blank(PreloadStore.get("bane"), "removes the value if the key exists");
|
|
});
|
|
|
|
asyncTestDiscourse(
|
|
"getAndRemove returns a promise that resolves to null",
|
|
function(assert) {
|
|
assert.expect(1);
|
|
|
|
const done = assert.async();
|
|
PreloadStore.getAndRemove("joker").then(function(result) {
|
|
assert.blank(result);
|
|
done();
|
|
});
|
|
}
|
|
);
|
|
|
|
asyncTestDiscourse(
|
|
"getAndRemove returns a promise that resolves to the result of the finder",
|
|
function(assert) {
|
|
assert.expect(1);
|
|
|
|
const done = assert.async();
|
|
const finder = function() {
|
|
return "batdance";
|
|
};
|
|
PreloadStore.getAndRemove("joker", finder).then(function(result) {
|
|
assert.equal(result, "batdance");
|
|
done();
|
|
});
|
|
}
|
|
);
|
|
|
|
asyncTestDiscourse(
|
|
"getAndRemove returns a promise that resolves to the result of the finder's promise",
|
|
function(assert) {
|
|
assert.expect(1);
|
|
|
|
const finder = function() {
|
|
return new Ember.RSVP.Promise(function(resolve) {
|
|
resolve("hahahah");
|
|
});
|
|
};
|
|
|
|
const done = assert.async();
|
|
PreloadStore.getAndRemove("joker", finder).then(function(result) {
|
|
assert.equal(result, "hahahah");
|
|
done();
|
|
});
|
|
}
|
|
);
|
|
|
|
asyncTestDiscourse(
|
|
"returns a promise that rejects with the result of the finder's rejected promise",
|
|
function(assert) {
|
|
assert.expect(1);
|
|
|
|
const finder = function() {
|
|
return new Ember.RSVP.Promise(function(resolve, reject) {
|
|
reject("error");
|
|
});
|
|
};
|
|
|
|
const done = assert.async();
|
|
PreloadStore.getAndRemove("joker", finder).then(null, function(result) {
|
|
assert.equal(result, "error");
|
|
done();
|
|
});
|
|
}
|
|
);
|
|
|
|
asyncTestDiscourse("returns a promise that resolves to 'evil'", function(
|
|
assert
|
|
) {
|
|
assert.expect(1);
|
|
|
|
const done = assert.async();
|
|
PreloadStore.getAndRemove("bane").then(function(result) {
|
|
assert.equal(result, "evil");
|
|
done();
|
|
});
|
|
});
|