Skip to content

Commit

Permalink
Add basic Snapshot testing
Browse files Browse the repository at this point in the history
  • Loading branch information
ephread committed Jun 16, 2018
1 parent 12c8fd5 commit 613b46e
Show file tree
Hide file tree
Showing 17 changed files with 336 additions and 128 deletions.
7 changes: 3 additions & 4 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,7 @@ xcuserdata
# Carthage
#
# Add this line if you want to avoid checking in source code from Carthage dependencies.
# Carthage/Checkouts
**/Carthage/Checkouts
**/Carthage/Build

Carthage/Build

Skassets
Skassets
2 changes: 2 additions & 0 deletions Examples/Cartfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
github "uber/ios-snapshot-test-case" ~> 3.0.0

1 change: 1 addition & 0 deletions Examples/Cartfile.resolved
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
github "uber/ios-snapshot-test-case" "3.0.0"
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
<!--Profile-->
<scene sceneID="WBD-GZ-Xaa">
<objects>
<viewController title="Profile" id="YJG-tQ-EGf" customClass="DefaultViewController" customModule="Instructions_Example" customModuleProvider="target" sceneMemberID="viewController">
<viewController storyboardIdentifier="DefaultViewController" title="Profile" id="YJG-tQ-EGf" customClass="DefaultViewController" customModule="Instructions_Example" customModuleProvider="target" sceneMemberID="viewController">
<view key="view" contentMode="scaleToFill" id="yyL-TN-CqH">
<rect key="frame" x="0.0" y="0.0" width="375" height="603"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// DefaultViewController.swift
//
// Copyright (c) 2015, 2016 Frédéric Maquin <fred@ephread.com>
// Copyright (c) 2015-2018 Frédéric Maquin <fred@ephread.com>
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
Expand All @@ -25,7 +25,8 @@ import Instructions

// That's the default controller, using every defaults made available by Instructions.
// It can't get any simpler.
internal class DefaultViewController: ProfileViewController {
internal class DefaultViewController: ProfileViewController,
CoachMarksControllerDataSource {
var windowLevel: UIWindowLevel?
var presentationContext: Context = .independantWindow

Expand Down Expand Up @@ -63,10 +64,8 @@ internal class DefaultViewController: ProfileViewController {
enum Context {
case independantWindow, controllerWindow, controller
}
}

// MARK: - Protocol Conformance | CoachMarksControllerDataSource
extension DefaultViewController: CoachMarksControllerDataSource {
// MARK: - Protocol Conformance | CoachMarksControllerDataSource
func numberOfCoachMarks(for coachMarksController: CoachMarksController) -> Int {
return 5
}
Expand Down Expand Up @@ -117,9 +116,8 @@ extension DefaultViewController: CoachMarksControllerDataSource {

return (bodyView: coachViews.bodyView, arrowView: coachViews.arrowView)
}
}

extension DefaultViewController: CoachMarksControllerDelegate {
// MARK: Protocol Conformance - CoachMarkControllerDelegate
func coachMarksController(_ coachMarksController: CoachMarksController,
willLoadCoachMarkAt index: Int) -> Bool {
if index == 0 && presentationContext == .controller {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ internal class BackgroundNetworkingViewController: DefaultViewController {
}

// MARK: CoachMarksControllerDelegate
func coachMarksController(_ coachMarksController: CoachMarksController,
override func coachMarksController(_ coachMarksController: CoachMarksController,
willShow coachMark: inout CoachMark, afterSizeTransition: Bool,
at index: Int) {
if index == 2 && !afterSizeTransition {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,57 @@ class TestFlowViewController: ProfileViewController {
self.coachMarksController.stop(immediately: true)
self.coachMarksController.start(in: .window(over: self))
}

// MARK: - Protocol Conformance | CoachMarksControllerDelegate
func coachMarksController(_ coachMarksController: CoachMarksController,
willLoadCoachMarkAt index: Int) -> Bool {
print("willLoadCoachMarkAt: \(index)")
return true
}

override func coachMarksController(_ coachMarksController: CoachMarksController,
willShow coachMark: inout CoachMark,
afterSizeTransition: Bool,
at index: Int) {
print("willShow at: \(index), afterSizeTransition: \(afterSizeTransition)")
}

override func coachMarksController(_ coachMarksController: CoachMarksController,
didShow coachMark: CoachMark,
afterSizeTransition: Bool,
at index: Int) {
print("didShow at: \(index), afterSizeTransition: \(afterSizeTransition)")
}

override func coachMarksController(_ coachMarksController: CoachMarksController,
willHide coachMark: CoachMark,
at index: Int) {
print("willHide at: \(index)")
}

override func coachMarksController(_ coachMarksController: CoachMarksController,
didHide coachMark: CoachMark,
at index: Int) {
print("didHide at: \(index)")
}

override func coachMarksController(_ coachMarksController: CoachMarksController,
didEndShowingBySkipping skipped: Bool) {
print("didEndShowingBySkipping: \(skipped)")
}

func shouldHandleOverlayTap(in coachMarksController: CoachMarksController,
at index: Int) -> Bool {
print("shouldHandleOverlayTap at index: \(index)")

if index >= 2 {
print("Index greater than or equal to 2, skipping")
coachMarksController.stop()
return false
} else {
return true
}
}
}

// MARK: - Protocol Conformance | CoachMarksControllerDataSource
Expand Down Expand Up @@ -115,56 +166,3 @@ extension TestFlowViewController: CoachMarksControllerDataSource {
return (bodyView: coachViews.bodyView, arrowView: coachViews.arrowView)
}
}

// MARK: - Protocol Conformance | CoachMarksControllerDelegate
extension TestFlowViewController: CoachMarksControllerDelegate {
func coachMarksController(_ coachMarksController: CoachMarksController,
willLoadCoachMarkAt index: Int) -> Bool {
print("willLoadCoachMarkAt: \(index)")
return true
}

func coachMarksController(_ coachMarksController: CoachMarksController,
willShow coachMark: inout CoachMark,
afterSizeTransition: Bool,
at index: Int) {
print("willShow at: \(index), afterSizeTransition: \(afterSizeTransition)")
}

func coachMarksController(_ coachMarksController: CoachMarksController,
didShow coachMark: CoachMark,
afterSizeTransition: Bool,
at index: Int) {
print("didShow at: \(index), afterSizeTransition: \(afterSizeTransition)")
}

func coachMarksController(_ coachMarksController: CoachMarksController,
willHide coachMark: CoachMark,
at index: Int) {
print("willHide at: \(index)")
}

func coachMarksController(_ coachMarksController: CoachMarksController,
didHide coachMark: CoachMark,
at index: Int) {
print("didHide at: \(index)")
}

func coachMarksController(_ coachMarksController: CoachMarksController,
didEndShowingBySkipping skipped: Bool) {
print("didEndShowingBySkipping: \(skipped)")
}

func shouldHandleOverlayTap(in coachMarksController: CoachMarksController,
at index: Int) -> Bool {
print("shouldHandleOverlayTap at index: \(index)")

if index >= 2 {
print("Index greater than or equal to 2, skipping")
coachMarksController.stop()
return false
} else {
return true
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import Instructions

// MARK: - Main Controller
// This class is an example of what can be achieved with the delegate methods.
class DelegateViewController: ProfileViewController {
class DelegateViewController: ProfileViewController, CoachMarksControllerDataSource {

// MARK: IBOutlets
@IBOutlet weak var profileBackgroundView: UIView?
Expand All @@ -48,10 +48,8 @@ class DelegateViewController: ProfileViewController {

coachMarksController.skipView = skipView
}
}

// MARK: - Protocol Conformance | CoachMarksControllerDataSource
extension DelegateViewController: CoachMarksControllerDataSource {
// MARK: - Protocol Conformance | CoachMarksControllerDataSource
func numberOfCoachMarks(for coachMarksController: CoachMarksController) -> Int {
return 5
}
Expand Down Expand Up @@ -110,12 +108,10 @@ extension DelegateViewController: CoachMarksControllerDataSource {

return (bodyView: coachViews.bodyView, arrowView: coachViews.arrowView)
}
}

// MARK: - Protocol Conformance | CoachMarksControllerDelegate
extension DelegateViewController: CoachMarksControllerDelegate {
func coachMarksController(_ coachMarksController: CoachMarksController,
configureOrnamentsOfOverlay overlay: UIView) {
// MARK: - Protocol Conformance | CoachMarksControllerDelegate
override func coachMarksController(_ coachMarksController: CoachMarksController,
configureOrnamentsOfOverlay overlay: UIView) {
let label = UILabel()
label.translatesAutoresizingMaskIntoConstraints = false
overlay.addSubview(label)
Expand All @@ -128,7 +124,7 @@ extension DelegateViewController: CoachMarksControllerDelegate {
label.topAnchor.constraint(equalTo: overlay.topAnchor, constant: 100).isActive = true
}

func coachMarksController(_ coachMarksController: CoachMarksController,
override func coachMarksController(_ coachMarksController: CoachMarksController,
willShow coachMark: inout CoachMark,
afterSizeTransition: Bool, at index: Int) {
if index == 0 && !afterSizeTransition {
Expand Down Expand Up @@ -160,7 +156,7 @@ extension DelegateViewController: CoachMarksControllerDelegate {
}
}

func coachMarksController(_ coachMarksController: CoachMarksController,
override func coachMarksController(_ coachMarksController: CoachMarksController,
willHide coachMark: CoachMark, at index: Int) {
if index == 1 {
avatarVerticalPositionConstraint?.constant = 0
Expand All @@ -172,7 +168,7 @@ extension DelegateViewController: CoachMarksControllerDelegate {
}
}

func coachMarksController(_ coachMarksController: CoachMarksController,
override func coachMarksController(_ coachMarksController: CoachMarksController,
didEndShowingBySkipping skipped: Bool) {
let newColor: UIColor

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,15 @@ internal class PausingCodeViewController: ProfileViewController {
// The user tapped on the button, so let's carry on!
coachMarksController.flow.resume()
}

// MARK: - Protocol Conformance | CoachMarksControllerDelegate
override func coachMarksController(_ coachMarksController: CoachMarksController,
willShow coachMark: inout CoachMark,
afterSizeTransition: Bool, at index: Int) {
if index == 2 && !afterSizeTransition {
coachMarksController.flow.pause(and: pauseStyle)
}
}
}

// MARK: - Protocol Conformance | CoachMarksControllerDataSource
Expand Down Expand Up @@ -121,14 +130,3 @@ extension PausingCodeViewController: CoachMarksControllerDataSource {
return (bodyView: coachViews.bodyView, arrowView: coachViews.arrowView)
}
}

// MARK: - Protocol Conformance | CoachMarksControllerDelegate
extension PausingCodeViewController: CoachMarksControllerDelegate {
func coachMarksController(_ coachMarksController: CoachMarksController,
willShow coachMark: inout CoachMark,
afterSizeTransition: Bool, at index: Int) {
if index == 2 && !afterSizeTransition {
coachMarksController.flow.pause(and: pauseStyle)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -140,10 +140,8 @@ extension TransitionFromCodeViewController: CoachMarksControllerDataSource {

return (bodyView: coachViews.bodyView, arrowView: coachViews.arrowView)
}
}

// MARK: - Protocol Conformance | CoachMarksControllerDelegate
extension TransitionFromCodeViewController: CoachMarksControllerDelegate {
// MARK: - Protocol Conformance | CoachMarksControllerDelegate
func coachMarksController(_ coachMarksController: CoachMarksController, willLoadCoachMarkAt index: Int) -> Bool {
switch(index) {
case 1:
Expand Down
Loading

0 comments on commit 613b46e

Please sign in to comment.