2013-02-20 13:15:50 -05:00
|
|
|
/*global waitsFor:true expect:true describe:true beforeEach:true it:true runs:true */
|
|
|
|
|
2013-02-27 21:26:20 -05:00
|
|
|
describe("PreloadStore", function() {
|
|
|
|
|
|
|
|
beforeEach(function() {
|
|
|
|
PreloadStore.store('bane', 'evil');
|
|
|
|
});
|
|
|
|
|
2013-03-20 11:26:46 -04:00
|
|
|
describe('get', function() {
|
2013-02-27 21:26:20 -05:00
|
|
|
|
2013-03-20 11:26:46 -04:00
|
|
|
it("returns undefined if the key doesn't exist", function() {
|
|
|
|
expect(PreloadStore.get('joker')).toBe(undefined);
|
2013-02-27 21:26:20 -05:00
|
|
|
});
|
|
|
|
|
2013-03-20 11:26:46 -04:00
|
|
|
it("returns the value if the key exists", function() {
|
|
|
|
expect(PreloadStore.get('bane')).toBe('evil');
|
2013-02-27 21:26:20 -05:00
|
|
|
});
|
|
|
|
|
|
|
|
});
|
|
|
|
|
2013-03-20 11:26:46 -04:00
|
|
|
describe('remove', function() {
|
2013-02-27 21:26:20 -05:00
|
|
|
|
2013-03-20 11:26:46 -04:00
|
|
|
it("removes the value if the key exists", function() {
|
|
|
|
PreloadStore.remove('bane');
|
|
|
|
expect(PreloadStore.get('bane')).toBe(undefined);
|
2013-02-27 21:26:20 -05:00
|
|
|
});
|
|
|
|
|
2013-03-20 11:26:46 -04:00
|
|
|
});
|
2013-02-27 21:26:20 -05:00
|
|
|
|
2013-03-20 11:26:46 -04:00
|
|
|
describe('getAndRemove', function() {
|
2013-02-27 21:26:20 -05:00
|
|
|
|
2013-03-08 15:10:57 -05:00
|
|
|
it("returns a promise that resolves to null", function() {
|
2013-02-27 21:26:20 -05:00
|
|
|
var done, storeResult;
|
|
|
|
done = storeResult = null;
|
2013-03-20 11:26:46 -04:00
|
|
|
PreloadStore.getAndRemove('joker').then(function(result) {
|
2013-02-27 21:26:20 -05:00
|
|
|
done = true;
|
|
|
|
storeResult = result;
|
2013-02-20 13:15:50 -05:00
|
|
|
});
|
2013-02-27 21:26:20 -05:00
|
|
|
waitsFor((function() { return done; }), "Promise never resolved", 1000);
|
|
|
|
runs(function() {
|
2013-03-08 15:10:57 -05:00
|
|
|
expect(storeResult).toBe(null);
|
2013-02-20 13:15:50 -05:00
|
|
|
});
|
|
|
|
});
|
2013-02-27 21:26:20 -05:00
|
|
|
|
|
|
|
it("returns a promise that resolves to the result of the finder", function() {
|
|
|
|
var done, finder, storeResult;
|
|
|
|
done = storeResult = null;
|
|
|
|
finder = function() { return 'evil'; };
|
2013-03-20 11:26:46 -04:00
|
|
|
PreloadStore.getAndRemove('joker', finder).then(function(result) {
|
2013-02-27 21:26:20 -05:00
|
|
|
done = true;
|
|
|
|
storeResult = result;
|
2013-02-20 13:15:50 -05:00
|
|
|
});
|
2013-02-27 21:26:20 -05:00
|
|
|
waitsFor((function() { return done; }), "Promise never resolved", 1000);
|
|
|
|
runs(function() {
|
|
|
|
expect(storeResult).toBe('evil');
|
2013-02-20 13:15:50 -05:00
|
|
|
});
|
|
|
|
});
|
2013-02-27 21:26:20 -05:00
|
|
|
|
|
|
|
it("returns a promise that resolves to the result of the finder's promise", function() {
|
|
|
|
var done, finder, storeResult;
|
|
|
|
done = storeResult = null;
|
|
|
|
finder = function() {
|
2013-03-14 14:45:29 -04:00
|
|
|
return Ember.Deferred.promise(function(promise) { promise.resolve('evil'); });
|
2013-02-27 21:26:20 -05:00
|
|
|
};
|
2013-03-20 11:26:46 -04:00
|
|
|
PreloadStore.getAndRemove('joker', finder).then(function(result) {
|
2013-02-27 21:26:20 -05:00
|
|
|
done = true;
|
|
|
|
storeResult = result;
|
2013-02-20 13:15:50 -05:00
|
|
|
});
|
2013-02-27 21:26:20 -05:00
|
|
|
waitsFor((function() { return done; }), "Promise never resolved", 1000);
|
|
|
|
runs(function() {
|
|
|
|
expect(storeResult).toBe('evil');
|
2013-02-20 13:15:50 -05:00
|
|
|
});
|
2013-02-27 21:26:20 -05:00
|
|
|
});
|
|
|
|
|
|
|
|
it("returns a promise that resolves to the result of the finder's rejected promise", function() {
|
|
|
|
var done, finder, storeResult;
|
|
|
|
done = storeResult = null;
|
|
|
|
finder = function() {
|
2013-03-14 14:45:29 -04:00
|
|
|
return Ember.Deferred.promise(function(promise) { promise.reject('evil'); });
|
2013-02-27 21:26:20 -05:00
|
|
|
};
|
2013-03-20 11:26:46 -04:00
|
|
|
PreloadStore.getAndRemove('joker', finder).then(null, function(rejectedResult) {
|
2013-02-27 21:26:20 -05:00
|
|
|
done = true;
|
|
|
|
storeResult = rejectedResult;
|
2013-02-20 13:15:50 -05:00
|
|
|
});
|
2013-02-27 21:26:20 -05:00
|
|
|
waitsFor((function() { return done; }), "Promise never rejected", 1000);
|
|
|
|
runs(function() {
|
|
|
|
expect(storeResult).toBe('evil');
|
2013-02-20 13:15:50 -05:00
|
|
|
});
|
2013-02-27 21:26:20 -05:00
|
|
|
});
|
|
|
|
|
|
|
|
it("returns a promise that resolves to 'evil'", function() {
|
|
|
|
var done, storeResult;
|
|
|
|
done = storeResult = null;
|
2013-03-20 11:26:46 -04:00
|
|
|
PreloadStore.getAndRemove('bane').then(function(result) {
|
2013-02-27 21:26:20 -05:00
|
|
|
done = true;
|
|
|
|
storeResult = result;
|
|
|
|
});
|
|
|
|
waitsFor((function() { return done; }), "Promise never resolved", 1000);
|
|
|
|
runs(function() {
|
|
|
|
expect(storeResult).toBe('evil');
|
2013-02-20 13:15:50 -05:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2013-02-27 21:26:20 -05:00
|
|
|
});
|
2013-02-22 15:41:12 -05:00
|
|
|
|
2013-02-27 21:26:20 -05:00
|
|
|
});
|