2018-06-15 23:03:24 +08:00
|
|
|
import PreloadStore from "preload-store";
|
2015-08-12 00:27:07 +08:00
|
|
|
|
2017-06-15 01:57:58 +08:00
|
|
|
QUnit.module("preload-store", {
|
|
|
|
beforeEach() {
|
2018-06-15 23:03:24 +08:00
|
|
|
PreloadStore.store("bane", "evil");
|
2013-06-20 03:06:23 +08:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2017-06-15 01:57:58 +08:00
|
|
|
QUnit.test("get", assert => {
|
2018-06-15 23:03:24 +08:00
|
|
|
assert.blank(PreloadStore.get("joker"), "returns blank for a missing key");
|
|
|
|
assert.equal(
|
|
|
|
PreloadStore.get("bane"),
|
|
|
|
"evil",
|
|
|
|
"returns the value for that key"
|
|
|
|
);
|
2013-06-20 03:06:23 +08:00
|
|
|
});
|
|
|
|
|
2017-06-15 01:57:58 +08:00
|
|
|
QUnit.test("remove", assert => {
|
2018-06-15 23:03:24 +08:00
|
|
|
PreloadStore.remove("bane");
|
|
|
|
assert.blank(PreloadStore.get("bane"), "removes the value if the key exists");
|
2013-06-20 03:06:23 +08:00
|
|
|
});
|
|
|
|
|
2018-06-15 23:03:24 +08:00
|
|
|
asyncTestDiscourse(
|
|
|
|
"getAndRemove returns a promise that resolves to null",
|
|
|
|
function(assert) {
|
|
|
|
assert.expect(1);
|
2013-06-20 03:06:23 +08:00
|
|
|
|
2018-06-15 23:03:24 +08:00
|
|
|
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();
|
|
|
|
});
|
|
|
|
}
|
|
|
|
);
|
2013-06-20 03:06:23 +08:00
|
|
|
|
2018-06-15 23:03:24 +08:00
|
|
|
asyncTestDiscourse("returns a promise that resolves to 'evil'", function(
|
|
|
|
assert
|
|
|
|
) {
|
2017-06-15 01:57:58 +08:00
|
|
|
assert.expect(1);
|
2013-06-20 03:06:23 +08:00
|
|
|
|
2017-06-15 01:57:58 +08:00
|
|
|
const done = assert.async();
|
2018-06-15 23:03:24 +08:00
|
|
|
PreloadStore.getAndRemove("bane").then(function(result) {
|
|
|
|
assert.equal(result, "evil");
|
2017-06-15 01:57:58 +08:00
|
|
|
done();
|
2013-06-20 03:06:23 +08:00
|
|
|
});
|
|
|
|
});
|