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