mirror of
https://github.com/robb/Cartography.git
synced 2024-10-06 21:47:18 +03:00
Adding tests for the layout guides in ViewProxy
This commit is contained in:
parent
0cb77898d6
commit
daa1c56428
@ -139,8 +139,8 @@
|
||||
97D17CAC1F8E779300C57CE1 /* LayoutGuideProxy.swift in Sources */ = {isa = PBXBuildFile; fileRef = 97D17CA91F8E779300C57CE1 /* LayoutGuideProxy.swift */; };
|
||||
97E7F0A91F8D598A004857CE /* ViewProxy.swift in Sources */ = {isa = PBXBuildFile; fileRef = 97E7F0A81F8D598A004857CE /* ViewProxy.swift */; };
|
||||
97F50E521F962CF300C6DCF5 /* LayoutProxy+TypeErasure.swift in Sources */ = {isa = PBXBuildFile; fileRef = 97F50E511F962CF300C6DCF5 /* LayoutProxy+TypeErasure.swift */; };
|
||||
97F50E541F9633AA00C6DCF5 /* SafeAreaLayoutGuideSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 97F50E531F9633AA00C6DCF5 /* SafeAreaLayoutGuideSpec.swift */; };
|
||||
97F50E551F9633AA00C6DCF5 /* SafeAreaLayoutGuideSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 97F50E531F9633AA00C6DCF5 /* SafeAreaLayoutGuideSpec.swift */; };
|
||||
97F50E541F9633AA00C6DCF5 /* ViewLayoutGuideSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 97F50E531F9633AA00C6DCF5 /* ViewLayoutGuideSpec.swift */; };
|
||||
97F50E551F9633AA00C6DCF5 /* ViewLayoutGuideSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 97F50E531F9633AA00C6DCF5 /* ViewLayoutGuideSpec.swift */; };
|
||||
97F50E561F96401200C6DCF5 /* LayoutProxy+TypeErasure.swift in Sources */ = {isa = PBXBuildFile; fileRef = 97F50E511F962CF300C6DCF5 /* LayoutProxy+TypeErasure.swift */; };
|
||||
97F50E571F96401300C6DCF5 /* LayoutProxy+TypeErasure.swift in Sources */ = {isa = PBXBuildFile; fileRef = 97F50E511F962CF300C6DCF5 /* LayoutProxy+TypeErasure.swift */; };
|
||||
A75B6143FF12C54FF3223B47 /* Pods_TestPods_Cartography_tvOS_tests.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 0827A83361EACF1E6062607E /* Pods_TestPods_Cartography_tvOS_tests.framework */; };
|
||||
@ -268,7 +268,7 @@
|
||||
97D17CA91F8E779300C57CE1 /* LayoutGuideProxy.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LayoutGuideProxy.swift; sourceTree = "<group>"; };
|
||||
97E7F0A81F8D598A004857CE /* ViewProxy.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ViewProxy.swift; sourceTree = "<group>"; };
|
||||
97F50E511F962CF300C6DCF5 /* LayoutProxy+TypeErasure.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "LayoutProxy+TypeErasure.swift"; sourceTree = "<group>"; };
|
||||
97F50E531F9633AA00C6DCF5 /* SafeAreaLayoutGuideSpec.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SafeAreaLayoutGuideSpec.swift; sourceTree = "<group>"; };
|
||||
97F50E531F9633AA00C6DCF5 /* ViewLayoutGuideSpec.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ViewLayoutGuideSpec.swift; sourceTree = "<group>"; };
|
||||
EE85314F1F9363DC003EC021 /* LayoutItem.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LayoutItem.swift; sourceTree = "<group>"; };
|
||||
EEDD4098FF7503B1F9188F10 /* Pods_Cartography_iOS_Tests.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Pods_Cartography_iOS_Tests.framework; sourceTree = BUILT_PRODUCTS_DIR; };
|
||||
/* End PBXFileReference section */
|
||||
@ -472,7 +472,7 @@
|
||||
97D17CA51F8E774700C57CE1 /* MemoryLeakSpec.swift */,
|
||||
97D17CA61F8E774700C57CE1 /* ConstraintGroupSpec.swift */,
|
||||
97D17CA81F8E774700C57CE1 /* SizeSpec.swift */,
|
||||
97F50E531F9633AA00C6DCF5 /* SafeAreaLayoutGuideSpec.swift */,
|
||||
97F50E531F9633AA00C6DCF5 /* ViewLayoutGuideSpec.swift */,
|
||||
);
|
||||
path = CartographyTests;
|
||||
sourceTree = SOURCE_ROOT;
|
||||
@ -934,7 +934,7 @@
|
||||
buildActionMask = 2147483647;
|
||||
files = (
|
||||
979558F61F97017D0096BBEA /* LayoutSupportSpec.swift in Sources */,
|
||||
97F50E541F9633AA00C6DCF5 /* SafeAreaLayoutGuideSpec.swift in Sources */,
|
||||
97F50E541F9633AA00C6DCF5 /* ViewLayoutGuideSpec.swift in Sources */,
|
||||
9795590B1F9701CD0096BBEA /* ConstraintGroupSpec.swift in Sources */,
|
||||
979559081F9701C90096BBEA /* MemoryLeakSpec.swift in Sources */,
|
||||
979558FC1F97019E0096BBEA /* Matchers.swift in Sources */,
|
||||
@ -1045,7 +1045,7 @@
|
||||
buildActionMask = 2147483647;
|
||||
files = (
|
||||
979558F71F97017F0096BBEA /* LayoutSupportSpec.swift in Sources */,
|
||||
97F50E551F9633AA00C6DCF5 /* SafeAreaLayoutGuideSpec.swift in Sources */,
|
||||
97F50E551F9633AA00C6DCF5 /* ViewLayoutGuideSpec.swift in Sources */,
|
||||
9795590D1F9701CF0096BBEA /* ConstraintGroupSpec.swift in Sources */,
|
||||
9795590A1F9701CA0096BBEA /* MemoryLeakSpec.swift in Sources */,
|
||||
979558FD1F9701A10096BBEA /* Matchers.swift in Sources */,
|
||||
|
@ -1,58 +0,0 @@
|
||||
//
|
||||
// SafeAreaLayoutGuideSpec.swift
|
||||
// Cartography
|
||||
//
|
||||
// Created by Vitor Travain on 17/10/17.
|
||||
// Copyright © 2017 Robert Böhnke. All rights reserved.
|
||||
//
|
||||
|
||||
import UIKit
|
||||
import Quick
|
||||
import Nimble
|
||||
@testable import Cartography
|
||||
|
||||
@available(iOS, introduced: 11.0)
|
||||
@available(tvOS, introduced: 11.0)
|
||||
final class SafeAreaLayoutGuideSpec: QuickSpec {
|
||||
override func spec() {
|
||||
describe("SafeAreaLayoutGuide") {
|
||||
var superview: UIView!
|
||||
var view: UIView!
|
||||
|
||||
beforeEach {
|
||||
superview = TestView(frame: UIScreen.main.bounds)
|
||||
view = TestView(frame: CGRect.zero)
|
||||
|
||||
superview.addSubview(view)
|
||||
}
|
||||
|
||||
it("Views should align to edges") {
|
||||
constrain(view) { view in
|
||||
view.edges == view.superview!.safeAreaLayoutGuide.edges
|
||||
}
|
||||
|
||||
superview.layoutIfNeeded()
|
||||
|
||||
expect(view.frame.minX) == (superview.safeAreaLayoutGuide.layoutFrame.minX)
|
||||
expect(view.frame.minY) == (superview.safeAreaLayoutGuide.layoutFrame.maxX)
|
||||
expect(view.frame.width) == (superview.safeAreaLayoutGuide.layoutFrame.width)
|
||||
expect(view.frame.height) == (superview.safeAreaLayoutGuide.layoutFrame.height)
|
||||
}
|
||||
|
||||
it("View should center in safe area") {
|
||||
constrain(view) { view in
|
||||
view.center == view.superview!.safeAreaLayoutGuide.center
|
||||
view.width == 200
|
||||
view.height == 200
|
||||
}
|
||||
|
||||
superview.layoutIfNeeded()
|
||||
|
||||
expect(view.frame.midX) == (superview.safeAreaLayoutGuide.layoutFrame.midX)
|
||||
expect(view.frame.midY) == (superview.safeAreaLayoutGuide.layoutFrame.midY)
|
||||
expect(view.frame.width) == 200
|
||||
expect(view.frame.height) == 200
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
146
CartographyTests/ViewLayoutGuideSpec.swift
Normal file
146
CartographyTests/ViewLayoutGuideSpec.swift
Normal file
@ -0,0 +1,146 @@
|
||||
//
|
||||
// SafeAreaLayoutGuideSpec.swift
|
||||
// Cartography
|
||||
//
|
||||
// Created by Vitor Travain on 17/10/17.
|
||||
// Copyright © 2017 Robert Böhnke. All rights reserved.
|
||||
//
|
||||
|
||||
import UIKit
|
||||
import Quick
|
||||
import Nimble
|
||||
@testable import Cartography
|
||||
|
||||
@available(iOS, introduced: 9.0)
|
||||
@available(iOS, introduced: 9.0)
|
||||
final class ViewLayoutGuideSpec: QuickSpec {
|
||||
override func spec() {
|
||||
describe("Layout margin guide") {
|
||||
var superview: UIView!
|
||||
var view: UIView!
|
||||
|
||||
beforeEach {
|
||||
superview = UIView(frame: UIScreen.main.bounds)
|
||||
view = UIView(frame: .zero)
|
||||
|
||||
superview.addSubview(view)
|
||||
}
|
||||
|
||||
it("Views should align to edges within margins") {
|
||||
constrain(view) { view in
|
||||
view.edges == view.superview!.layoutMarginsGuide.edges
|
||||
}
|
||||
|
||||
superview.layoutIfNeeded()
|
||||
|
||||
expect(view.frame.minX) == superview.layoutMarginsGuide.layoutFrame.minX
|
||||
expect(view.frame.minY) == superview.layoutMarginsGuide.layoutFrame.minY
|
||||
expect(view.frame.width) == superview.layoutMarginsGuide.layoutFrame.width
|
||||
expect(view.frame.height) == superview.layoutMarginsGuide.layoutFrame.height
|
||||
}
|
||||
|
||||
it("Views should center within margins") {
|
||||
constrain(view) { view in
|
||||
view.center == view.superview!.layoutMarginsGuide.center
|
||||
|
||||
view.width == 200
|
||||
view.height == 200
|
||||
}
|
||||
|
||||
superview.layoutIfNeeded()
|
||||
|
||||
expect(view.frame.midX) == (superview.layoutMarginsGuide.layoutFrame.midX)
|
||||
expect(view.frame.midY) == (superview.layoutMarginsGuide.layoutFrame.midY)
|
||||
expect(view.frame.width) == 200
|
||||
expect(view.frame.height) == 200
|
||||
}
|
||||
}
|
||||
|
||||
describe("Readable content guide") {
|
||||
var superview: UIView!
|
||||
var view: UIView!
|
||||
|
||||
beforeEach {
|
||||
superview = UIView(frame: UIScreen.main.bounds)
|
||||
view = UIView(frame: .zero)
|
||||
|
||||
superview.addSubview(view)
|
||||
}
|
||||
|
||||
it("Views should align to edges within readable margins") {
|
||||
constrain(view) { view in
|
||||
view.edges == view.superview!.readableContentGuide.edges
|
||||
}
|
||||
|
||||
superview.layoutIfNeeded()
|
||||
|
||||
expect(view.frame.minX) == superview.readableContentGuide.layoutFrame.minX
|
||||
expect(view.frame.minY) == superview.readableContentGuide.layoutFrame.minY
|
||||
expect(view.frame.width) == superview.readableContentGuide.layoutFrame.width
|
||||
expect(view.frame.height) == superview.readableContentGuide.layoutFrame.height
|
||||
}
|
||||
|
||||
it("Views should center within readable margins") {
|
||||
constrain(view) { view in
|
||||
view.center == view.superview!.readableContentGuide.center
|
||||
|
||||
view.width == 200
|
||||
view.height == 200
|
||||
}
|
||||
|
||||
superview.layoutIfNeeded()
|
||||
|
||||
expect(view.frame.midX) == (superview.readableContentGuide.layoutFrame.midX)
|
||||
expect(view.frame.midY) == (superview.readableContentGuide.layoutFrame.midY)
|
||||
expect(view.frame.width) == 200
|
||||
expect(view.frame.height) == 200
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@available(iOS, introduced: 11.0)
|
||||
@available(tvOS, introduced: 11.0)
|
||||
final class SafeAreaLayoutGuideSpec: QuickSpec {
|
||||
override func spec() {
|
||||
describe("Safe area layout guide") {
|
||||
var superview: UIView!
|
||||
var view: UIView!
|
||||
|
||||
beforeEach {
|
||||
superview = TestView(frame: UIScreen.main.bounds)
|
||||
view = TestView(frame: CGRect.zero)
|
||||
|
||||
superview.addSubview(view)
|
||||
}
|
||||
|
||||
it("Views should align to safe area edges") {
|
||||
constrain(view) { view in
|
||||
view.edges == view.superview!.safeAreaLayoutGuide.edges
|
||||
}
|
||||
|
||||
superview.layoutIfNeeded()
|
||||
|
||||
expect(view.frame.minX) == (superview.safeAreaLayoutGuide.layoutFrame.minX)
|
||||
expect(view.frame.minY) == (superview.safeAreaLayoutGuide.layoutFrame.maxX)
|
||||
expect(view.frame.width) == (superview.safeAreaLayoutGuide.layoutFrame.width)
|
||||
expect(view.frame.height) == (superview.safeAreaLayoutGuide.layoutFrame.height)
|
||||
}
|
||||
|
||||
it("View should center in safe area") {
|
||||
constrain(view) { view in
|
||||
view.center == view.superview!.safeAreaLayoutGuide.center
|
||||
view.width == 200
|
||||
view.height == 200
|
||||
}
|
||||
|
||||
superview.layoutIfNeeded()
|
||||
|
||||
expect(view.frame.midX) == (superview.safeAreaLayoutGuide.layoutFrame.midX)
|
||||
expect(view.frame.midY) == (superview.safeAreaLayoutGuide.layoutFrame.midY)
|
||||
expect(view.frame.width) == 200
|
||||
expect(view.frame.height) == 200
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user