|
| 1 | +// Copyright (c) 2017 Luc Dion |
| 2 | +// Permission is hereby granted, free of charge, to any person obtaining a copy |
| 3 | +// of this software and associated documentation files (the "Software"), to deal |
| 4 | +// in the Software without restriction, including without limitation the rights |
| 5 | +// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
| 6 | +// copies of the Software, and to permit persons to whom the Software is |
| 7 | +// furnished to do so, subject to the following conditions: |
| 8 | +// |
| 9 | +// The above copyright notice and this permission notice shall be included in |
| 10 | +// all copies or substantial portions of the Software. |
| 11 | +// |
| 12 | +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
| 13 | +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 14 | +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
| 15 | +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
| 16 | +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
| 17 | +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN |
| 18 | +// THE SOFTWARE. |
| 19 | + |
| 20 | +import Quick |
| 21 | +import Nimble |
| 22 | +import PinLayout |
| 23 | + |
| 24 | +class UIScrollViewSpec: QuickSpec { |
| 25 | + override func spec() { |
| 26 | + var viewController: UIViewController! |
| 27 | + |
| 28 | + var rootView: BasicView! |
| 29 | + var scrollView: UIScrollView! |
| 30 | + |
| 31 | + /* |
| 32 | + root |
| 33 | + | |
| 34 | + |- scrollView |
| 35 | + */ |
| 36 | + |
| 37 | + beforeEach { |
| 38 | + viewController = UIViewController() |
| 39 | + |
| 40 | + rootView = BasicView(text: "", color: .white) |
| 41 | + viewController.view.addSubview(rootView) |
| 42 | + |
| 43 | + scrollView = UIScrollView() |
| 44 | + rootView.addSubview(scrollView) |
| 45 | + |
| 46 | + rootView.frame = CGRect(x: 0, y: 0, width: 400, height: 400) |
| 47 | + scrollView.frame = CGRect(x: 0, y: 0, width: 400, height: 400) |
| 48 | + } |
| 49 | + |
| 50 | + describe("Layout a UIScrollView") { |
| 51 | + it("layout the UIScrollView") { |
| 52 | + scrollView.pin.all() |
| 53 | + |
| 54 | + expect(scrollView.frame).to(equal(CGRect(x: 0, y: 0, width: 400.0, height: 400.0))) |
| 55 | + expect(scrollView.bounds).to(equal(CGRect(x: 0, y: 0, width: 400.0, height: 400.0))) |
| 56 | + expect(scrollView.contentOffset).to(equal(CGPoint(x: 0, y: 0))) |
| 57 | + } |
| 58 | + |
| 59 | + it("should keep the contentOffset") { |
| 60 | + scrollView.contentOffset = CGPoint(x: 30, y: 30) |
| 61 | + |
| 62 | + scrollView.pin.all() |
| 63 | + |
| 64 | + expect(scrollView.frame).to(equal(CGRect(x: 0, y: 0, width: 400.0, height: 400.0))) |
| 65 | + expect(scrollView.bounds).to(equal(CGRect(x: 30, y: 30, width: 400.0, height: 400.0))) |
| 66 | + expect(scrollView.contentOffset).to(equal(CGPoint(x: 30, y: 30))) |
| 67 | + } |
| 68 | + } |
| 69 | + } |
| 70 | +} |
0 commit comments