2015-08-11 12:27:07 -04:00
|
|
|
import { blank } from 'helpers/qunit-helpers';
|
|
|
|
|
2013-06-19 15:06:23 -04:00
|
|
|
module("Discourse.PreloadStore", {
|
|
|
|
setup: function() {
|
|
|
|
PreloadStore.store('bane', 'evil');
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
test("get", function() {
|
|
|
|
blank(PreloadStore.get('joker'), "returns blank for a missing key");
|
|
|
|
equal(PreloadStore.get('bane'), 'evil', "returns the value for that key");
|
|
|
|
});
|
|
|
|
|
|
|
|
test("remove", function() {
|
|
|
|
PreloadStore.remove('bane');
|
|
|
|
blank(PreloadStore.get('bane'), "removes the value if the key exists");
|
|
|
|
});
|
|
|
|
|
2013-07-15 19:47:13 -04:00
|
|
|
asyncTestDiscourse("getAndRemove returns a promise that resolves to null", function() {
|
2013-06-19 15:06:23 -04:00
|
|
|
expect(1);
|
|
|
|
|
|
|
|
PreloadStore.getAndRemove('joker').then(function(result) {
|
|
|
|
blank(result);
|
|
|
|
start();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2013-07-15 19:47:13 -04:00
|
|
|
asyncTestDiscourse("getAndRemove returns a promise that resolves to the result of the finder", function() {
|
2013-06-19 15:06:23 -04:00
|
|
|
expect(1);
|
|
|
|
|
|
|
|
var finder = function() { return 'batdance'; };
|
|
|
|
PreloadStore.getAndRemove('joker', finder).then(function(result) {
|
|
|
|
equal(result, 'batdance');
|
|
|
|
start();
|
|
|
|
});
|
|
|
|
|
|
|
|
});
|
|
|
|
|
2013-07-15 19:47:13 -04:00
|
|
|
asyncTestDiscourse("getAndRemove returns a promise that resolves to the result of the finder's promise", function() {
|
2013-06-19 15:06:23 -04:00
|
|
|
expect(1);
|
|
|
|
|
|
|
|
var 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
|
|
|
};
|
|
|
|
|
|
|
|
PreloadStore.getAndRemove('joker', finder).then(function(result) {
|
|
|
|
equal(result, 'hahahah');
|
|
|
|
start();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2013-07-15 19:47:13 -04:00
|
|
|
asyncTestDiscourse("returns a promise that rejects with the result of the finder's rejected promise", function() {
|
2013-06-19 15:06:23 -04:00
|
|
|
expect(1);
|
|
|
|
|
|
|
|
var 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
|
|
|
};
|
|
|
|
|
|
|
|
PreloadStore.getAndRemove('joker', finder).then(null, function(result) {
|
|
|
|
equal(result, 'error');
|
|
|
|
start();
|
|
|
|
});
|
|
|
|
|
|
|
|
});
|
|
|
|
|
2013-07-15 19:47:13 -04:00
|
|
|
asyncTestDiscourse("returns a promise that resolves to 'evil'", function() {
|
2013-06-19 15:06:23 -04:00
|
|
|
expect(1);
|
|
|
|
|
|
|
|
PreloadStore.getAndRemove('bane').then(function(result) {
|
|
|
|
equal(result, 'evil');
|
|
|
|
start();
|
|
|
|
});
|
|
|
|
});
|