spec_app/spec/javascripts/up/layout_spec.js.coffee in upjs-rails-0.10.0 vs spec_app/spec/javascripts/up/layout_spec.js.coffee in upjs-rails-0.10.1

- old
+ new

@@ -5,11 +5,13 @@ describe 'Javascript functions', -> describe 'up.reveal', -> beforeEach -> - up.layout.defaults(snap: 0) + up.layout.defaults + snap: 0 + substance: 99999 describe 'when the container is body', -> beforeEach -> @$viewport = $('body') @@ -161,12 +163,10 @@ # [2] ch+50 ... ch+5049 # [F] 0 ............ 99 expect(@$viewport.scrollTop()).toBe(@clientHeight + 50) - - describe 'when the viewport is a container with overflow-y: scroll', -> it 'reveals the given element', -> $viewport = affix('div').css 'position': 'absolute' @@ -199,11 +199,11 @@ # ------------ # [2] 100..149 # [3] 150..199 # ------------ # [4] 200..249 - # [5] 250..399 + # [5] 250..299 expect($viewport.scrollTop()).toBe(100) # See that the view doesn't move if the element # is already revealed up.reveal($elements[2], viewport: $viewport) @@ -216,11 +216,11 @@ # [1] 050..099 # [2] 100..149 # [3] 150..199 # ------------ # [4] 200..249 - # [5] 250..399 + # [5] 250..299 # ------------ expect($viewport.scrollTop()).toBe(200) # See that the view only scrolls up as little as possible # in order to reveal the element @@ -230,11 +230,63 @@ # [1] 050..099 # [2] 100..149 # ------------ # [3] 150..199 # [4] 200..249 - # [5] 250..399 + # [5] 250..299 expect($viewport.scrollTop()).toBe(50) + + it 'only reveals the top number of pixels defined in config.substance', -> + + up.layout.defaults + substance: 20 + + $viewport = affix('div').css + 'position': 'absolute' + 'top': '50px' + 'left': '50px' + 'width': '100px' + 'height': '100px' + 'overflow-y': 'scroll' + $elements = [] + u.each [0..5], -> + $element = $('<div>').css(height: '50px') + $element.appendTo($viewport) + $elements.push($element) + + # [0] 000..049 + # [1] 050..099 + # [2] 100..149 + # [3] 150..199 + # [4] 200..249 + # [5] 250..299 + + # Viewing 0 .. 99 + expect($viewport.scrollTop()).toBe(0) + + # See that the view only scrolls down as little as possible + # in order to reveal the first 20 rows of the element + up.reveal($elements[3], viewport: $viewport) + # Viewing 70 to 169 + expect($viewport.scrollTop()).toBe(50 + 20) + + # See that the view doesn't move if the element + # is already revealed + up.reveal($elements[2], viewport: $viewport) + expect($viewport.scrollTop()).toBe(50 + 20) + + # See that the view scrolls as far down as it cans + # to show the first 20 rows of the bottom element + up.reveal($elements[5], viewport: $viewport) + # Viewing 170 to 269 + expect($viewport.scrollTop()).toBe(150 + 20) + + # See that the view only scrolls up as little as possible + # in order to reveal the first 20 rows element + up.reveal($elements[2], viewport: $viewport) + # Viewing 100 to 199 + expect($viewport.scrollTop()).toBe(100) + describe 'up.scroll', -> it 'should have tests'