Add Snapshots tests
MODIFY
.travis.yml
.travis.yml
@@ -260,3 +260,17 @@ matrix:
- cd swift/Samples/TicTacToe
- bundle exec pod repo update
- bundle exec pod install
+
+ - language: swift
+ name: "Swift - WorkflowSplitScreenContainer Snapshot Tests - Cocoapods (Xcode 10.2)"
+ os: osx
+ osx_image: xcode10.2
+ xcode_workspace: WorkflowSplitScreenContainer.xcworkspace
+ xcode_scheme: WorkflowSplitScreenContainer-Unit-SnapshotTests
+ xcode_destination: platform=iOS Simulator,OS=12.2,name=iPad Pro (9.7-inch)
+ before_install:
+ - yes | gem update --system
+ - gem install bundler
+ - bundle install
+ - WORKFLOW_VERSION=$(git describe --tags $(git rev-list --tags --max-count=1) | sed s/v//) pod gen WorkflowSplitScreenContainer.podspec
+ - cd gen/WorkflowSplitScreenContainer

MODIFY
WorkflowSplitScreenContainer.podspec
WorkflowSplitScreenContainer.podspec
@@ -12,15 +12,25 @@ Pod::Spec.new do |s|
s.swift_versions = ['5.0']
s.ios.deployment_target = '9.3'
- s.osx.deployment_target = '10.12'
s.source_files = 'swift/WorkflowSplitScreenContainer/Sources/**/*.swift'
- s.dependency 'Workflow', "#{s.version}"
- s.dependency 'WorkflowUI', "#{s.version}"
+ s.dependency 'Workflow', "#{ENV['WORKFLOW_VERSION'] || s.version}"
+ s.dependency 'WorkflowUI', "#{ENV['WORKFLOW_VERSION'] || s.version}"
s.app_spec 'DemoApp' do |app_spec|
app_spec.source_files = 'swift/WorkflowSplitScreenContainer/DemoApp/**/*.swift'
end
+ s.test_spec 'SnapshotTests' do |test_spec|
+ test_spec.requires_app_host = true
+ test_spec.source_files = 'swift/WorkflowSplitScreenContainer/SnapshotTests/**/*.swift'
+
+ test_spec.framework = 'XCTest'
+
+ test_spec.dependency 'iOSSnapshotTestCase'
+
+ test_spec.scheme = { environment_variables: { 'FB_REFERENCE_IMAGE_DIR' => '$PODS_TARGET_SRCROOT/swift/WorkflowSplitScreenContainer/SnapshotTests/ReferenceImages' } }
+ end
+
end

MODIFY
swift/WorkflowSplitScreenContainer/DemoApp/BaseScreen.swift
swift/WorkflowSplitScreenContainer/DemoApp/BaseScreen.swift
@@ -37,7 +37,9 @@ fileprivate final class BaseScreenViewController: ScreenViewController<BaseScree
private let titleLabel: UILabel
required init(screen: BaseScreen, viewRegistry: ViewRegistry) {
- titleLabel = UILabel(frame: .zero)
+ titleLabel = UILabel(frame: CGRect(x: 0, y: 0, width: 100, height: 20))
+ titleLabel.textAlignment = .center
+
super.init(screen: screen, viewRegistry: viewRegistry)
update(with: screen)
@@ -52,15 +54,7 @@ fileprivate final class BaseScreenViewController: ScreenViewController<BaseScree
override func viewDidLayoutSubviews() {
super.viewDidLayoutSubviews()
- let height: CGFloat = 44.0
-
- var (top, bottom) = view.bounds.divided(atDistance: view.bounds.height / 2, from: CGRectEdge.minYEdge)
-
- top.size.height -= (height / 2.0)
- bottom.origin.y += (height)
- bottom.size.height -= (height / 2.0)
-
- titleLabel.frame = top
+ titleLabel.center = view.center
}
override func screenDidChange(from previousScreen: BaseScreen) {

ADD
swift/WorkflowSplitScreenContainer/SnapshotTests/ReferenceImages_64/WorkflowSplitScreenContainer_Unit_SnapshotTests.SplitScreenContainerScreenSnapshotTests/test_splitRatio_custom@2x.png
swift/WorkflowSplitScreenContainer/SnapshotTests/ReferenceImages_64/WorkflowSplitScreenContainer_Unit_SnapshotTests.SplitScreenContainerScreenSnapshotTests/test_splitRatio_custom@2x.png
Binary files /dev/null and b/swift/WorkflowSplitScreenContainer/SnapshotTests/ReferenceImages_64/WorkflowSplitScreenContainer_Unit_SnapshotTests.SplitScreenContainerScreenSnapshotTests/test_splitRatio_custom@2x.png differ

ADD
swift/WorkflowSplitScreenContainer/SnapshotTests/ReferenceImages_64/WorkflowSplitScreenContainer_Unit_SnapshotTests.SplitScreenContainerScreenSnapshotTests/test_splitRatio_half@2x.png
swift/WorkflowSplitScreenContainer/SnapshotTests/ReferenceImages_64/WorkflowSplitScreenContainer_Unit_SnapshotTests.SplitScreenContainerScreenSnapshotTests/test_splitRatio_half@2x.png
Binary files /dev/null and b/swift/WorkflowSplitScreenContainer/SnapshotTests/ReferenceImages_64/WorkflowSplitScreenContainer_Unit_SnapshotTests.SplitScreenContainerScreenSnapshotTests/test_splitRatio_half@2x.png differ

ADD
swift/WorkflowSplitScreenContainer/SnapshotTests/ReferenceImages_64/WorkflowSplitScreenContainer_Unit_SnapshotTests.SplitScreenContainerScreenSnapshotTests/test_splitRatio_quarter@2x.png
swift/WorkflowSplitScreenContainer/SnapshotTests/ReferenceImages_64/WorkflowSplitScreenContainer_Unit_SnapshotTests.SplitScreenContainerScreenSnapshotTests/test_splitRatio_quarter@2x.png
Binary files /dev/null and b/swift/WorkflowSplitScreenContainer/SnapshotTests/ReferenceImages_64/WorkflowSplitScreenContainer_Unit_SnapshotTests.SplitScreenContainerScreenSnapshotTests/test_splitRatio_quarter@2x.png differ

ADD
swift/WorkflowSplitScreenContainer/SnapshotTests/ReferenceImages_64/WorkflowSplitScreenContainer_Unit_SnapshotTests.SplitScreenContainerScreenSnapshotTests/test_splitRatio_third@2x.png
swift/WorkflowSplitScreenContainer/SnapshotTests/ReferenceImages_64/WorkflowSplitScreenContainer_Unit_SnapshotTests.SplitScreenContainerScreenSnapshotTests/test_splitRatio_third@2x.png
Binary files /dev/null and b/swift/WorkflowSplitScreenContainer/SnapshotTests/ReferenceImages_64/WorkflowSplitScreenContainer_Unit_SnapshotTests.SplitScreenContainerScreenSnapshotTests/test_splitRatio_third@2x.png differ

ADD
swift/WorkflowSplitScreenContainer/SnapshotTests/SplitScreenContainerScreenSnapshotTests.swift
+import Workflow
+import WorkflowUI
+import XCTest
+import FBSnapshotTestCase
+@testable import WorkflowSplitScreenContainer
+
+
+class SplitScreenContainerScreenSnapshotTests: FBSnapshotTestCase {
+ override func setUp() {
+ super.setUp()
+ recordMode = false
+ }
+
+ func test_splitRatio() {
+ var viewRegistry = ViewRegistry()
+ viewRegistry.register(screenViewControllerType: BaseScreenViewController.self)
+
+ let ratios: [String : SplitScreenContainerScreen.Ratio] = [
+ "third" : .third,
+ "quarter" : .quarter,
+ "half" : .half,
+ "custom" : .init(0.3125)
+ ]
+
+ for (name, ratio) in ratios {
+ let splitScreenContainerScreen = SplitScreenContainerScreen(
+ leftScreen: BaseScreen(title: "Left screen", backgroundColor: .green),
+ rightScreen: BaseScreen(title: "Right screen", backgroundColor: .red),
+ ratio: ratio
+ )
+
+ let viewController = SplitScreenContainerViewController(
+ screen: splitScreenContainerScreen,
+ viewRegistry: viewRegistry
+ )
+ viewController.view.layoutIfNeeded()
+
+ FBSnapshotVerifyView(viewController.view, identifier: name)
+ }
+ }
+}
+
+
+struct BaseScreen: Screen {
+ var title: String
+ var backgroundColor: UIColor
+}
+
+
+fileprivate final class BaseScreenViewController: ScreenViewController<BaseScreen> {
+
+ private let titleLabel: UILabel
+
+ required init(screen: BaseScreen, viewRegistry: ViewRegistry) {
+ titleLabel = UILabel(frame: CGRect(x: 0, y: 0, width: 100, height: 20))
+ titleLabel.textAlignment = .center
+
+ super.init(screen: screen, viewRegistry: viewRegistry)
+
+ update(with: screen)
+ }
+
+ override func viewDidLoad() {
+ super.viewDidLoad()
+
+ view.addSubview(titleLabel)
+ }
+
+ override func viewDidLayoutSubviews() {
+ super.viewDidLayoutSubviews()
+
+ titleLabel.center = view.center
+ }
+
+ override func screenDidChange(from previousScreen: BaseScreen) {
+ update(with: screen)
+ }
+
+ private func update(with screen: BaseScreen) {
+ view.backgroundColor = screen.backgroundColor
+ titleLabel.text = screen.title
+ }
+}
+

Add Snapshots tests