Skip to content

Commit

Permalink
Merge testing-improvements into master
Browse files Browse the repository at this point in the history
  • Loading branch information
balavor committed Mar 24, 2018
2 parents 10f1a7b + 6a8a7c1 commit 4b48847
Show file tree
Hide file tree
Showing 9 changed files with 127 additions and 17 deletions.
8 changes: 8 additions & 0 deletions SnappyShrimp.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
/* Begin PBXBuildFile section */
065B45BC20605201001E1F41 /* ViewController.xib in Resources */ = {isa = PBXBuildFile; fileRef = 065B45BB20605201001E1F41 /* ViewController.xib */; };
065B45BE20605323001E1F41 /* ViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 065B45BD20605323001E1F41 /* ViewController.swift */; };
06C01E1C206647CF00C63FBB /* iPhone4S.swift in Sources */ = {isa = PBXBuildFile; fileRef = 06C01E1B206647CF00C63FBB /* iPhone4S.swift */; };
06C01E692067032C00C63FBB /* iPadPro12_2nd_generation.swift in Sources */ = {isa = PBXBuildFile; fileRef = 06C01E682067032C00C63FBB /* iPadPro12_2nd_generation.swift */; };
06CF33A11FE81F90007B0B74 /* FBSnapshotTestCase.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 06CF33A01FE81F90007B0B74 /* FBSnapshotTestCase.framework */; };
06F6C6581FF3F73B00E055F0 /* Media.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 06F6C6571FF3F73B00E055F0 /* Media.xcassets */; };
06F6C6601FF3FE6F00E055F0 /* SnappyShrimpTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 06F6C65F1FF3FE6F00E055F0 /* SnappyShrimpTests.swift */; };
Expand Down Expand Up @@ -52,6 +54,8 @@
/* Begin PBXFileReference section */
065B45BB20605201001E1F41 /* ViewController.xib */ = {isa = PBXFileReference; lastKnownFileType = file.xib; path = ViewController.xib; sourceTree = "<group>"; };
065B45BD20605323001E1F41 /* ViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ViewController.swift; sourceTree = "<group>"; };
06C01E1B206647CF00C63FBB /* iPhone4S.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; name = iPhone4S.swift; path = iPhone/iPhone4S.swift; sourceTree = "<group>"; };
06C01E682067032C00C63FBB /* iPadPro12_2nd_generation.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = iPadPro12_2nd_generation.swift; path = iPad/iPadPro12_2nd_generation.swift; sourceTree = "<group>"; };
06CF33A01FE81F90007B0B74 /* FBSnapshotTestCase.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = FBSnapshotTestCase.framework; path = Carthage/Build/iOS/FBSnapshotTestCase.framework; sourceTree = "<group>"; };
06F6C6571FF3F73B00E055F0 /* Media.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Media.xcassets; sourceTree = "<group>"; };
06F6C65D1FF3FE6F00E055F0 /* SnappyShrimpTests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = SnappyShrimpTests.xctest; sourceTree = BUILT_PRODUCTS_DIR; };
Expand Down Expand Up @@ -195,6 +199,7 @@
427E96251FF2A09000B4A2B4 /* iPadPro9.swift */,
427E96221FF2A09000B4A2B4 /* iPadPro10.swift */,
427E96241FF2A09000B4A2B4 /* iPadPro12.swift */,
06C01E682067032C00C63FBB /* iPadPro12_2nd_generation.swift */,
);
name = iPad;
sourceTree = "<group>";
Expand All @@ -210,6 +215,7 @@
427E96101FF2A08600B4A2B4 /* iPhone7Plus.swift */,
427E960D1FF2A08600B4A2B4 /* iPhone8.swift */,
427E960A1FF2A08600B4A2B4 /* iPhone8Plus.swift */,
06C01E1B206647CF00C63FBB /* iPhone4S.swift */,
427E960C1FF2A08600B4A2B4 /* iPhoneSE.swift */,
427E96121FF2A08600B4A2B4 /* iPhoneX.swift */,
);
Expand Down Expand Up @@ -390,6 +396,8 @@
427E96191FF2A08600B4A2B4 /* iPhone7.swift in Sources */,
427E962B1FF2A09000B4A2B4 /* iPadMini.swift in Sources */,
427E96161FF2A08600B4A2B4 /* iPhoneSE.swift in Sources */,
06C01E1C206647CF00C63FBB /* iPhone4S.swift in Sources */,
06C01E692067032C00C63FBB /* iPadPro12_2nd_generation.swift in Sources */,
4214CC2C1FDFE62700C7AB61 /* Specifications.swift in Sources */,
4214CC2D1FDFE62700C7AB61 /* SnapshotTest.swift in Sources */,
427E961A1FF2A08600B4A2B4 /* iPhone7Plus.swift in Sources */,
Expand Down
4 changes: 2 additions & 2 deletions SnappyShrimp/Device/iPad/iPadAir.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@ extension Device {
public static let portrait = Presentation(
name: "iPad Air FullScreen",
size: CGSize.iPadPro9,
traitCollection: UITraitCollection.iPadOld.fullScreen)
traitCollection: UITraitCollection.iPadOld.portrait)
public static let landscape = Presentation(
name: "iPad Air Landscape FullScreen",
size: CGSize.iPadPro9.rotated,
traitCollection: UITraitCollection.iPadOld.fullScreen)
traitCollection: UITraitCollection.iPadOld.landscape)
}
}
4 changes: 2 additions & 2 deletions SnappyShrimp/Device/iPad/iPadAir2.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@ extension Device {
public static let portrait = Presentation(
name: "iPad Air2 FullScreen",
size: CGSize.iPadPro9,
traitCollection: UITraitCollection.iPadOld.fullScreen)
traitCollection: UITraitCollection.iPadOld.portrait)
public static let landscape = Presentation(
name: "iPad Air2 Landscape FullScreen",
size: CGSize.iPadPro9.rotated,
traitCollection: UITraitCollection.iPadOld.fullScreen)
traitCollection: UITraitCollection.iPadOld.landscape)
}
}
4 changes: 2 additions & 2 deletions SnappyShrimp/Device/iPad/iPadMini.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@ extension Device {
public static let portrait = Presentation(
name: "iPad mini FullScreen",
size: CGSize.iPadPro9,
traitCollection: UITraitCollection.iPadOld.fullScreen)
traitCollection: UITraitCollection.iPadOld.portrait)
public static let landscape = Presentation(
name: "iPad mini Landscape FullScreen",
size: CGSize.iPadPro9.rotated,
traitCollection: UITraitCollection.iPadOld.fullScreen)
traitCollection: UITraitCollection.iPadOld.landscape)
}
}
67 changes: 67 additions & 0 deletions SnappyShrimp/Device/iPad/iPadPro12_2nd_generation.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
// Copyright 2018, Roman Tysiachnik, Andrii Doroshko.
// Licensed under the terms of the MIT License. See LICENSE.md file in project root for terms.

import Foundation

extension Device {
@available(iOS 10.0, *)
public enum iPadPro12_2nd_generation {
public enum portrait {
public static let fullScreen = Presentation(
name: "iPad Pro12 Portrait FullScreen",
size: CGSize.iPadPro12,
traitCollection: UITraitCollection(
traitsFrom: [UITraitCollection.iPad.portrait.fullScreen,
UITraitCollection.Compability.ForceTouch.available,
UITraitCollection.Compability.DisplayGamut.P3]))
public static let twoThirds = Presentation(
name: "iPad Pro12 Portrait Two Third",
size: CGSize.iPadPro12.splitViewTwoThirds,
traitCollection: UITraitCollection(
traitsFrom: [UITraitCollection.iPad.portrait.splitTwoThirds,
UITraitCollection.Compability.ForceTouch.available,
UITraitCollection.Compability.DisplayGamut.P3]))
public static let oneThird = Presentation(
name: "iPad Pro12 Portrait SplitView One Third",
size: CGSize.iPadPro12.splitViewOneThird,
traitCollection: UITraitCollection(
traitsFrom: [UITraitCollection.iPad.portrait.splitOneThird,
UITraitCollection.Compability.ForceTouch.available,
UITraitCollection.Compability.DisplayGamut.P3]))
}
public enum landscape {
public static let fullScreen = Presentation(
name: "iPad Pro12 Landscape FullScreen",
size: CGSize.iPadPro12.rotated,
traitCollection: UITraitCollection(
traitsFrom: [UITraitCollection.iPad.landscape.fullScreen,
UITraitCollection.Compability.ForceTouch.available,
UITraitCollection.Compability.DisplayGamut.P3]))
public static let half = Presentation(
name: "iPad Pro12 Landscape SplitView Half",
size: CGSize.iPadPro12.rotated.splitViewHalf,
traitCollection: UITraitCollection(
traitsFrom: [UITraitCollection.Display.InterfaceIdiom.pad,
UITraitCollection.Display.SizeClass.Vertical.regular,
UITraitCollection.Display.SizeClass.Horizontal.regular,
UITraitCollection.Display.Scale.x2,
UITraitCollection.Compability.ForceTouch.available,
UITraitCollection.Compability.DisplayGamut.P3]))
public static let twoThird = Presentation(
name: "iPad Pro12 Landscape SplitView Two-Thirds",
size: CGSize.iPadPro12.rotated.splitViewTwoThirds,
traitCollection: UITraitCollection(
traitsFrom: [UITraitCollection.iPad.landscape.splitTwoThirds,
UITraitCollection.Compability.ForceTouch.available,
UITraitCollection.Compability.DisplayGamut.P3]))
public static let oneThird = Presentation(
name: "iPad Pro12 Landscape SplitView One Third",
size: CGSize.iPadPro12.rotated.splitViewOneThird,
traitCollection: UITraitCollection(
traitsFrom: [UITraitCollection.iPad.landscape.splitOneThird,
UITraitCollection.Compability.ForceTouch.available,
UITraitCollection.Compability.DisplayGamut.P3]))
}
}
}

18 changes: 18 additions & 0 deletions SnappyShrimp/Device/iPhone/iPhone4S.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
// Copyright 2018, Roman Tysiachnik, Andrii Doroshko.
// Licensed under the terms of the MIT License. See LICENSE.md file in project root for terms.

import Foundation

extension Device {
public enum iPhone4S {
public static let portrait = Presentation(
name: "iPhone 4S Portrait",
size: CGSize.iPhone4S,
traitCollection: UITraitCollection.iPhone.portrait)
public static let landscape = Presentation(
name: "iPhone 4S Landscape",
size: CGSize.iPhone4S.rotated,
traitCollection: UITraitCollection.iPhone.landscape)
}
}

4 changes: 4 additions & 0 deletions SnappyShrimp/Presentation.swift
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,8 @@ extension Presentation {
var scale: CGFloat {
return self.traitCollection.displayScale
}
@available(iOS 10.0, *)
var gamut: UIDisplayGamut {
return self.traitCollection.displayGamut
}
}
6 changes: 6 additions & 0 deletions SnappyShrimp/SnapshotTest.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ import UIKit
///The base class of view snapshotting tests on all possible screens. By default, you have to create schemes for testing and for record. Both of them must contain enviroment arguments with paths to save images and with a value that indicates the record mode state ("RECORD_MODE" by default). For your own implementation of setting record mode true or false, override the setUp method and design your own way of running tests.
open class SnapshotTest: FBSnapshotTestCase{

open var isGamutSupportEnabled = false

///Settings for snapshot testing.
override open func setUp() {
super.setUp()
Expand All @@ -24,6 +26,10 @@ open class SnapshotTest: FBSnapshotTestCase{
guard presentation.userInterfaceIdiom == UIDevice.current.userInterfaceIdiom else { return }
guard presentation.scale == UIScreen.main.scale else { return }

if isGamutSupportEnabled, #available(iOS 10.0, *) {
guard presentation.gamut == UIScreen.main.traitCollection.displayGamut else { return }
}

let window = HostWindow(presentation: presentation, context: context)

window.addSubview(controller.view)
Expand Down
29 changes: 18 additions & 11 deletions SnappyShrimp/Specifications.swift
Original file line number Diff line number Diff line change
Expand Up @@ -154,22 +154,29 @@ extension UITraitCollection {
}
}
enum iPadOld {
static let fullScreen = iPad.portrait.fullScreen
static let portrait = UITraitCollection(
traitsFrom: [Display.InterfaceIdiom.pad,
Display.SizeClass.Vertical.regular,
Display.SizeClass.Horizontal.regular,
Display.Scale.x2])
static let landscape = UITraitCollection(
traitsFrom: [Display.InterfaceIdiom.pad,
Display.SizeClass.Vertical.regular,
Display.SizeClass.Horizontal.regular,
Display.Scale.x2])
}
}

extension CGSize {
static let iPhoneSE = CGSize(width: 320, height: 568)
static let iPhoneX = CGSize(width: 375, height: 812)
static let iPhone = CGSize(width: 375, height: 667)
static let iPhonePlus = CGSize(width: 414, height: 736)

static let iPadPro9 = CGSize(width: 768, height: 1024)
static let iPadPro10 = CGSize(width: 834, height: 1112)
static let iPadPro12 = CGSize(width: 1024, height: 1366)
static let iPhone4S = CGSize(width: 320, height: 480)
static let iPhoneSE = CGSize(width: 320, height: 568)
static let iPhoneX = CGSize(width: 375, height: 812)
static let iPhone = CGSize(width: 375, height: 667)
static let iPhonePlus = CGSize(width: 414, height: 736)

static let watch38mm = CGSize(width: 272, height: 340)
static let watch42mm = CGSize(width: 312, height: 390)
static let iPadPro9 = CGSize(width: 768, height: 1024)
static let iPadPro10 = CGSize(width: 834, height: 1112)
static let iPadPro12 = CGSize(width: 1024, height: 1366)
}
extension CGSize {
var rotated: CGSize {
Expand Down

0 comments on commit 4b48847

Please sign in to comment.