describe 'up.flow', ->
u = up.util
describe 'Javascript functions', ->
describe 'up.replace', ->
describeCapability 'canPushState', ->
beforeEach ->
@oldBefore = affix('.before').text('old-before')
@oldMiddle = affix('.middle').text('old-middle')
@oldAfter = affix('.after').text('old-after')
@responseText =
"""
new-inside
"""
$keeper = $('.keeper')
expect($keeper).toHaveText('old-inside')
expect(keptListener).toHaveBeenCalledWith($keeper, { key: 'value1' })
expect(keptListener).toHaveBeenCalledWith($keeper, { key: 'value2' })
it "doesn't let the discarded element appear in a transition", (done) ->
oldTextDuringTransition = undefined
newTextDuringTransition = undefined
transition = ($old, $new) ->
oldTextDuringTransition = squish($old.text())
newTextDuringTransition = squish($new.text())
u.resolvedDeferred()
$container = affix('.container')
$container.html """
old-foo
old-bar
"""
newHtml = """
"""
promise = up.extract('.container', newHtml, transition: transition)
promise.then ->
expect(oldTextDuringTransition).toEqual('old-foo old-bar')
expect(newTextDuringTransition).toEqual('new-foo old-bar')
done()
describe 'up.destroy', ->
it 'removes the element with the given selector', ->
affix('.element')
up.destroy('.element')
expect($('.element')).not.toExist()
it 'calls destructors for custom elements', ->
up.compiler('.element', ($element) -> destructor)
destructor = jasmine.createSpy('destructor')
up.hello(affix('.element'))
up.destroy('.element')
expect(destructor).toHaveBeenCalled()
describe 'up.reload', ->
describeCapability 'canPushState', ->
it 'reloads the given selector from the closest known source URL', (done) ->
affix('.container[up-source="/source"] .element').find('.element').text('old text')
up.reload('.element').then ->
expect($('.element')).toHaveText('new text')
done()
expect(@lastRequest().url).toMatch(/\/source$/)
@respondWith """
"""
describeFallback 'canPushState', ->
it 'makes a page load from the closest known source URL', ->
affix('.container[up-source="/source"] .element').find('.element').text('old text')
spyOn(up.browser, 'loadPage')
up.reload('.element')
expect(up.browser.loadPage).toHaveBeenCalledWith('/source', jasmine.anything())
describe 'up.reset', ->
it 'should have tests'