Support empty view in snapshot tests
Support empty view in snapshot tests
@@ -1,12 +1,7 @@
|
||||
import XCTest
|
||||
|
||||
private let exclusions: [String] = [
|
||||
"div-container/visibility.json",
|
||||
"div-gallery/visibility.json",
|
||||
"div-input/visibility.json",
|
||||
"div-pager/visibility.json",
|
||||
"div-slider/visibility.json",
|
||||
"div-state/visibility.json",
|
||||
|
||||
"div-slider/thumb-style/thumb-primary-style-properties.json",
|
||||
"div-slider/thumb-style/thumb-secondary-style-properties.json",
|
||||
|
||||
@@ -125,11 +125,14 @@ internal class DivKitSnapshotTestCase: XCTestCase {
|
||||
let currentScale = UIScreen.main.scale
|
||||
let devices = ScreenSize.portrait.filter { $0.scale == currentScale }
|
||||
try devices.forEach { device in
|
||||
let view = try makeDivView(
|
||||
var view = try makeDivView(
|
||||
data: data,
|
||||
divKitComponents: divKitComponents,
|
||||
size: device.size
|
||||
)
|
||||
if view.bounds.isEmpty {
|
||||
view = makeEmptyView()
|
||||
}
|
||||
guard let image = view.makeSnapshot() else {
|
||||
throw DivTestingErrors.snapshotCouldNotBeCreated
|
||||
}
|
||||
@@ -218,6 +221,13 @@ private func jsonDict(data: Data) -> [String: Any]? {
|
||||
(try? JSONSerialization.jsonObject(with: data)) as? [String: Any]
|
||||
}
|
||||
|
||||
private func makeEmptyView() -> UIView {
|
||||
let label = UILabel()
|
||||
label.text = "<empty view>"
|
||||
label.frame = CGRect(origin: .zero, size: label.intrinsicContentSize)
|
||||
return label
|
||||
}
|
||||
|
||||
private enum DivTestingErrors: LocalizedError {
|
||||
case invalidData
|
||||
case blockCouldNotBeCreatedFromData
|
||||
|
||||
|
After Width: | Height: | Size: 16 KiB |
|
After Width: | Height: | Size: 11 KiB |
|
After Width: | Height: | Size: 3.3 KiB |
|
After Width: | Height: | Size: 16 KiB |
|
After Width: | Height: | Size: 11 KiB |
|
After Width: | Height: | Size: 3.3 KiB |
|
After Width: | Height: | Size: 29 KiB |
|
After Width: | Height: | Size: 22 KiB |
|
After Width: | Height: | Size: 5.3 KiB |
|
After Width: | Height: | Size: 16 KiB |
|
After Width: | Height: | Size: 11 KiB |
|
After Width: | Height: | Size: 3.3 KiB |
|
After Width: | Height: | Size: 29 KiB |
|
After Width: | Height: | Size: 22 KiB |
|
After Width: | Height: | Size: 5.3 KiB |
|
After Width: | Height: | Size: 4.7 KiB |
|
After Width: | Height: | Size: 2.0 KiB |
|
After Width: | Height: | Size: 3.3 KiB |
|
After Width: | Height: | Size: 5.1 KiB |
|
After Width: | Height: | Size: 2.3 KiB |
|
After Width: | Height: | Size: 3.3 KiB |
|
After Width: | Height: | Size: 9.1 KiB |
|
After Width: | Height: | Size: 4.9 KiB |
|
After Width: | Height: | Size: 5.3 KiB |
|
After Width: | Height: | Size: 5.3 KiB |
|
After Width: | Height: | Size: 2.5 KiB |
|
After Width: | Height: | Size: 3.3 KiB |
|
After Width: | Height: | Size: 9.6 KiB |
|
After Width: | Height: | Size: 5.3 KiB |
|
After Width: | Height: | Size: 5.3 KiB |
|
After Width: | Height: | Size: 16 KiB |
|
After Width: | Height: | Size: 11 KiB |
|
After Width: | Height: | Size: 3.3 KiB |
|
After Width: | Height: | Size: 16 KiB |
|
After Width: | Height: | Size: 11 KiB |
|
After Width: | Height: | Size: 3.3 KiB |
|
After Width: | Height: | Size: 28 KiB |
|
After Width: | Height: | Size: 22 KiB |
|
After Width: | Height: | Size: 5.3 KiB |
|
After Width: | Height: | Size: 16 KiB |
|
After Width: | Height: | Size: 11 KiB |
|
After Width: | Height: | Size: 3.3 KiB |
|
After Width: | Height: | Size: 28 KiB |
|
After Width: | Height: | Size: 22 KiB |
|
After Width: | Height: | Size: 5.3 KiB |
|
After Width: | Height: | Size: 14 KiB |
|
After Width: | Height: | Size: 11 KiB |
|
After Width: | Height: | Size: 3.3 KiB |
|
After Width: | Height: | Size: 14 KiB |
|
After Width: | Height: | Size: 11 KiB |
|
After Width: | Height: | Size: 3.3 KiB |
|
After Width: | Height: | Size: 27 KiB |
|
After Width: | Height: | Size: 22 KiB |
|
After Width: | Height: | Size: 5.3 KiB |
|
After Width: | Height: | Size: 14 KiB |
|
After Width: | Height: | Size: 11 KiB |
|
After Width: | Height: | Size: 3.3 KiB |
|
After Width: | Height: | Size: 27 KiB |
|
After Width: | Height: | Size: 22 KiB |
|
After Width: | Height: | Size: 5.3 KiB |
|
After Width: | Height: | Size: 15 KiB |
|
After Width: | Height: | Size: 11 KiB |
|
After Width: | Height: | Size: 3.3 KiB |
|
After Width: | Height: | Size: 15 KiB |
|
After Width: | Height: | Size: 11 KiB |
|
After Width: | Height: | Size: 3.3 KiB |
|
After Width: | Height: | Size: 29 KiB |
|
After Width: | Height: | Size: 22 KiB |
|
After Width: | Height: | Size: 5.3 KiB |
|
After Width: | Height: | Size: 15 KiB |
|
After Width: | Height: | Size: 11 KiB |
|
After Width: | Height: | Size: 3.3 KiB |
|
After Width: | Height: | Size: 29 KiB |
|
After Width: | Height: | Size: 22 KiB |
|
After Width: | Height: | Size: 5.3 KiB |