discourse/spec/javascripts/preload_store_spec.js.coffee
Sam Saffron 161420fac0 Added method for testing ember stuff
Collapse user actions in UI so it stops looking crazy
Removed dud dupe user action TOPIC_RESPONSE
Always show the owner of a post on the user page, actions by others at the bottom
2013-02-13 20:38:43 +11:00

81 lines
2.6 KiB
CoffeeScript

describe "PreloadStore", ->
beforeEach ->
PreloadStore.store('bane', 'evil')
describe "contains", ->
it "returns false for a key that doesn't exist", ->
expect(PreloadStore.contains('joker')).toBe(false)
it "returns true for a stored key", ->
expect(PreloadStore.contains('bane')).toBe(true)
describe 'getStatic', ->
it "returns undefined if the key doesn't exist", ->
expect(PreloadStore.getStatic('joker')).toBe(undefined)
it "returns the the key if it exists", ->
expect(PreloadStore.getStatic('bane')).toBe('evil')
it "removes the key after being called", ->
PreloadStore.getStatic('bane')
expect(PreloadStore.getStatic('bane')).toBe(undefined)
describe 'get', ->
it "returns a promise that resolves to undefined", ->
done = storeResult = null
PreloadStore.get('joker').then (result) ->
done = true
storeResult = result
waitsFor (-> return done), "Promise never resolved", 1000
runs -> expect(storeResult).toBe(undefined)
it "returns a promise that resolves to the result of the finder", ->
done = storeResult = null
finder = -> 'evil'
PreloadStore.get('joker', finder).then (result) ->
done = true
storeResult = result
waitsFor (-> return done), "Promise never resolved", 1000
runs -> expect(storeResult).toBe('evil')
it "returns a promise that resolves to the result of the finder's promise", ->
done = storeResult = null
finder = ->
promise = new RSVP.Promise
promise.resolve('evil')
promise
PreloadStore.get('joker', finder).then (result) ->
done = true
storeResult = result
waitsFor (-> return done), "Promise never resolved", 1000
runs -> expect(storeResult).toBe('evil')
it "returns a promise that resolves to the result of the finder's rejected promise", ->
done = storeResult = null
finder = ->
promise = new RSVP.Promise
promise.reject('evil')
promise
PreloadStore.get('joker', finder).then null, (rejectedResult) ->
done = true
storeResult = rejectedResult
waitsFor (-> return done), "Promise never rejected", 1000
runs -> expect(storeResult).toBe('evil')
it "returns a promise that resolves to 'evil'", ->
done = storeResult = null
PreloadStore.get('bane').then (result) ->
done = true
storeResult = result
waitsFor (-> return done), "Promise never resolved", 1000
runs -> expect(storeResult).toBe('evil')