Skip to content

Commit

Permalink
[FlexibleHeader] Add scroll view did scroll tests.
Browse files Browse the repository at this point in the history
Reviewers: #mdc_ios_owners, ajsecord

Reviewed By: #mdc_ios_owners, ajsecord

Projects: #material_components_ios

Differential Revision: http://codereview.cc/D454
  • Loading branch information
jverkoey committed Apr 4, 2016
1 parent f87efd0 commit c70aabb
Showing 1 changed file with 74 additions and 0 deletions.
@@ -0,0 +1,74 @@
/*
Copyright 2016-present Google Inc. All Rights Reserved.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

import XCTest
import MaterialComponents

// Tests confirming contract with a tracking scroll view that has scrolled
class FlexibleHeaderTrackingScrollViewDidScroll: XCTestCase {

// Implicitly unwrapped to indicate the contract of creating these values in setUp and make our
// accessors cleaner in tests.
var view: MDCFlexibleHeaderView!
var beforeFrame: CGRect!
var scrollView: UIScrollView!

override func setUp() {
view = MDCFlexibleHeaderView()

let originalFrame = CGRect(x: 0, y: 0, width: 100, height: 50)
view.frame = originalFrame
view.sizeToFit()

beforeFrame = view.frame

scrollView = UIScrollView()
scrollView.contentSize = CGSize(width: originalFrame.size.width, height: 1000)
scrollView.frame = CGRect(x: 0, y: 0, width: originalFrame.size.width, height: 250)

view.trackingScrollView = scrollView
}

// MARK: Initial changes are ignored.

func testFirstChangeDoesNothingNegative() {
scrollView.setContentOffset(CGPoint(x: 0, y: -view.maximumHeight), animated: false)

view.trackingScrollViewDidScroll()

XCTAssertEqual(beforeFrame, view.frame)
}

func testFirstChangeDoesNothingPositive() {
scrollView.setContentOffset(CGPoint(x: 0, y: 200), animated: false)

view.trackingScrollViewDidScroll()

XCTAssertEqual(beforeFrame, view.frame)
}

// MARK: Expansion on scroll to top.

func testFullyExpandedOnScrollToTop() {
view.trackingScrollViewDidScroll()

view.maximumHeight = 200
scrollView.setContentOffset(CGPoint(x: 0, y: -view.maximumHeight), animated: false)
view.trackingScrollViewDidScroll()

XCTAssertEqual(view.frame.size.height, view.maximumHeight)
}
}

0 comments on commit c70aabb

Please sign in to comment.