forked from ParisiLabs/wire-ios
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathZMSnapshotTestCase+Swift.swift
97 lines (78 loc) · 3.52 KB
/
ZMSnapshotTestCase+Swift.swift
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
//
// Wire
// Copyright (C) 2016 Wire Swiss GmbH
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see http://www.gnu.org/licenses/.
//
import Foundation
import Cartography
extension UITableViewCell: UITableViewDelegate, UITableViewDataSource {
public func wrapInTableView() -> UITableView {
let tableView = UITableView(frame: self.bounds, style: .plain)
tableView.delegate = self
tableView.dataSource = self
tableView.backgroundColor = .clear
tableView.separatorStyle = .none
tableView.rowHeight = UITableViewAutomaticDimension
tableView.layoutMargins = self.layoutMargins
let size = self.systemLayoutSizeFitting(CGSize(width: 320.0, height: 0.0) , withHorizontalFittingPriority: UILayoutPriorityRequired, verticalFittingPriority: UILayoutPriorityFittingSizeLevel)
self.layoutSubviews()
self.bounds = CGRect(x: 0.0, y: 0.0, width: size.width, height: size.height)
self.contentView.bounds = self.bounds
tableView.reloadData()
tableView.bounds = self.bounds
tableView.layoutIfNeeded()
constrain(tableView) { tableView in
tableView.height == size.height
}
CASStyler.default().styleItem(self)
self.layoutSubviews()
return tableView
}
public func numberOfSections(in tableView: UITableView) -> Int {
return 1
}
public func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return 1
}
public func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
return self.bounds.size.height
}
public func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
return self
}
}
extension StaticString {
func utf8SignedStart() -> UnsafePointer<Int8> {
let fileUnsafePointer = self.utf8Start
let reboundToSigned = fileUnsafePointer.withMemoryRebound(to: Int8.self, capacity: self.utf8CodeUnitCount) {
return UnsafePointer($0)
}
return reboundToSigned
}
}
extension ZMSnapshotTestCase {
func verify(view: UIView, tolerance: Float = 0, file: StaticString = #file, line: UInt = #line) {
verifyView(view, tolerance: tolerance, file: file.utf8SignedStart(), line: line)
}
func verifyInAllPhoneWidths(view: UIView, file: StaticString = #file, line: UInt = #line) {
verifyView(inAllPhoneWidths: view, file: file.utf8SignedStart(), line: line)
}
func verifyInAllTabletWidths(view: UIView, file: StaticString = #file, line: UInt = #line) {
verifyView(inAllTabletWidths: view, file: file.utf8SignedStart(), line: line)
}
func verifyInAllIPhoneSizes(view: UIView, file: StaticString = #file, line: UInt = #line) {
verifyView(inAllPhoneSizes: view, file: file.utf8SignedStart(), line: line, configurationBlock: nil)
}
}