Skip to content

Commit

Permalink
Add spec showing that users can animate revealing when prepending or …
Browse files Browse the repository at this point in the history
…appending, but not when swapping
  • Loading branch information
triskweline committed Jan 30, 2019
1 parent 052e799 commit ae6fced
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 3 deletions.
4 changes: 2 additions & 2 deletions lib/assets/javascripts/unpoly/classes/scroll_motion.coffee
Expand Up @@ -3,14 +3,14 @@ u = up.util
class up.ScrollMotion

# We want to make the default speed mimic Chrome's smooth scrolling behavior.
# We also want to keep the default valuein up.viewport.config.scrollSpeed to be 1.
# We also want to keep the default value in up.viewport.config.scrollSpeed to be 1.
# For our calculation in #animationFrame() we need to multiply it with this factor.
SPEED_CALIBRATION = 0.065

constructor: (@scrollable, @targetTop, options = {}) ->
# The option for up.scroll() is { behavior }, but coming
# from up.replace() it's { scrollBehavior }.
@behavior = options.behavior ? options.scrollBehavior ? 'instant'
@behavior = options.behavior ? options.scrollBehavior ? 'auto'

# The option for up.scroll() is { behavior }, but coming
# from up.replace() it's { scrollSpeed }.
Expand Down
2 changes: 1 addition & 1 deletion lib/assets/javascripts/unpoly/motion.coffee.erb
Expand Up @@ -372,7 +372,7 @@ up.motion = do ->

scrollNew = ->
# Don't animate the scrolling.
scrollOptions = u.merge(options, behavior: 'instant')
scrollOptions = u.merge(options, scrollBehavior: 'auto')
# Scroll newElement into position before we start the enter animation.
up.viewport.scrollAfterInsertFragment(newElement, scrollOptions)

Expand Down
24 changes: 24 additions & 0 deletions spec_app/spec/javascripts/up/fragment_spec.js.coffee
Expand Up @@ -1965,6 +1965,30 @@ describe 'up.fragment', ->
next =>
expect(swapDirectlySpy).toHaveBeenCalled()

describe 'with { scrollBehavior } option', ->

beforeEach ->
up.viewport.knife.mock('reveal').and.callFake (element, options) =>
@revealScrollBehavior = options.behavior ? options.scrollBehavior

it 'animates the revealing when prepending an element', asyncSpec (next) ->
fixture('.element', text: 'version 1')
up.extract('.element:before', '<div class="element">version 2</div>', reveal: true, scrollBehavior: 'smooth')
next =>
expect(@revealScrollBehavior).toEqual('smooth')

it 'animates the revealing when appending an element', asyncSpec (next) ->
fixture('.element', text: 'version 1')
up.extract('.element:after', '<div class="element">version 2</div>', reveal: true, scrollBehavior: 'smooth')
next =>
expect(@revealScrollBehavior).toEqual('smooth')

it 'does not animate the revealing when swapping out an element', asyncSpec (next) ->
fixture('.element', text: 'version 1')
up.extract('.element', '<div class="element">version 2</div>', reveal: true, scrollBehavior: 'smooth')
next =>
expect(@revealScrollBehavior).toEqual('auto')

describe 'handling of [up-keep] elements', ->

squish = (string) ->
Expand Down

0 comments on commit ae6fced

Please sign in to comment.