Skip to content

Commit

Permalink
Merge pull request #140 from diogot/test-in-many-devices
Browse files Browse the repository at this point in the history
Test in many devices
  • Loading branch information
diogot authored Feb 24, 2018
2 parents 9d0268d + 86226e1 commit 2b2a62b
Show file tree
Hide file tree
Showing 42 changed files with 144 additions and 132 deletions.
14 changes: 7 additions & 7 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@ source 'https://rubygems.org'

eval_gemfile File.join(File.dirname(__FILE__), 'rakelib/Gemfile')

gem 'cocoapods', '1.4.0'
gem 'danger', '5.5.10'
gem 'danger-rubocop', '0.6.0'
gem 'danger-slather', '0.0.6'
gem 'danger-xcode_summary', '0.4.0'
gem 'cocoapods', '~>1.4'
gem 'danger', '~>5.5'
gem 'danger-rubocop', '~>0.6'
gem 'danger-slather', '~>0.0.6'
gem 'danger-xcode_summary', '~>0.4'
gem 'rubocop', '~>0.50'
gem 'xcpretty-json-formatter', '0.1.0'
gem 'xcpretty-travis-formatter', '0.0.4'
gem 'xcpretty-json-formatter', '~>0.1'
gem 'xcpretty-travis-formatter', '~>0.0.4'
14 changes: 7 additions & 7 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -151,17 +151,17 @@ PLATFORMS
ruby

DEPENDENCIES
cocoapods (= 1.4.0)
danger (= 5.5.10)
danger-rubocop (= 0.6.0)
danger-slather (= 0.0.6)
danger-xcode_summary (= 0.4.0)
cocoapods (~> 1.4)
danger (~> 5.5)
danger-rubocop (~> 0.6)
danger-slather (~> 0.0.6)
danger-xcode_summary (~> 0.4)
git (~> 1.3)
plist (~> 3.2)
rake (~> 12.0)
rubocop (~> 0.50)
xcpretty-json-formatter (= 0.1.0)
xcpretty-travis-formatter (= 0.0.4)
xcpretty-json-formatter (~> 0.1)
xcpretty-travis-formatter (~> 0.0.4)

RUBY VERSION
ruby 2.4.2p198
Expand Down
4 changes: 4 additions & 0 deletions MyWeight.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,7 @@
D9BEBD0A1DAB24B7002263E2 /* Style.swift in Sources */ = {isa = PBXBuildFile; fileRef = D9BEBD091DAB24B7002263E2 /* Style.swift */; };
D9C3155B1E63A43700579208 /* AlertViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = D9C3155A1E63A43700579208 /* AlertViewModel.swift */; };
D9C3155D1E63A4EB00579208 /* UIAlertView+AlertViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = D9C3155C1E63A4EB00579208 /* UIAlertView+AlertViewModel.swift */; };
D9CD00F61FC917C500D3B50E /* MassRepositoryMock.swift in Sources */ = {isa = PBXBuildFile; fileRef = D9CD00F51FC917C500D3B50E /* MassRepositoryMock.swift */; };
D9D0D0AC1D88EB5D00191596 /* Log.swift in Sources */ = {isa = PBXBuildFile; fileRef = D9D0D0AB1D88EB5D00191596 /* Log.swift */; };
D9D69A6C1EA2E11F0032B048 /* Localizable.strings in Resources */ = {isa = PBXBuildFile; fileRef = D9D69A6F1EA2E11F0032B048 /* Localizable.strings */; };
D9D69A6D1EA2E11F0032B048 /* Localizable.strings in Resources */ = {isa = PBXBuildFile; fileRef = D9D69A6F1EA2E11F0032B048 /* Localizable.strings */; };
Expand Down Expand Up @@ -328,6 +329,7 @@
D9BEBD091DAB24B7002263E2 /* Style.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Style.swift; sourceTree = "<group>"; };
D9C3155A1E63A43700579208 /* AlertViewModel.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = AlertViewModel.swift; path = AlertViewController/AlertViewModel.swift; sourceTree = "<group>"; };
D9C3155C1E63A4EB00579208 /* UIAlertView+AlertViewModel.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = "UIAlertView+AlertViewModel.swift"; path = "AlertViewController/UIAlertView+AlertViewModel.swift"; sourceTree = "<group>"; };
D9CD00F51FC917C500D3B50E /* MassRepositoryMock.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MassRepositoryMock.swift; sourceTree = "<group>"; };
D9D0D0AB1D88EB5D00191596 /* Log.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Log.swift; sourceTree = "<group>"; };
D9D69A6E1EA2E11F0032B048 /* en */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = en; path = en.lproj/Localizable.strings; sourceTree = "<group>"; };
D9D69A701EA2E1210032B048 /* pt-BR */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = "pt-BR"; path = "pt-BR.lproj/Localizable.strings"; sourceTree = "<group>"; };
Expand Down Expand Up @@ -468,6 +470,7 @@
isa = PBXGroup;
children = (
1DB0707D1DCE9DCC00367276 /* SnapshotService.swift */,
D9CD00F51FC917C500D3B50E /* MassRepositoryMock.swift */,
);
name = Util;
sourceTree = "<group>";
Expand Down Expand Up @@ -1427,6 +1430,7 @@
B25889A61D1AFA1C00A88EAF /* UITableViewExtensionsTests.swift in Sources */,
1DB0707E1DCE9DCC00367276 /* SnapshotService.swift in Sources */,
D97F44191CAB5E51000F4E12 /* MyWeightTests.swift in Sources */,
D9CD00F61FC917C500D3B50E /* MassRepositoryMock.swift in Sources */,
1D0104F21DED1BC600C55EA3 /* AppCoordinatorTests.swift in Sources */,
1D0104F01DED1B3B00C55EA3 /* AddViewControllerTests.swift in Sources */,
);
Expand Down
2 changes: 1 addition & 1 deletion MyWeight/AppCoordinator.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import StoreKit
public class AppCoordinator {

let navigationController: UINavigationController
let massService: MassService = MassService()
let massService: MassRepository = MassService()

public init(with navigationController: UINavigationController)
{
Expand Down
4 changes: 2 additions & 2 deletions MyWeight/Screens/Add/AddViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@ public protocol AddViewControllerDelegate {

public class AddViewController: UIViewController {

let massService: MassService
let massService: MassRepository
let startMass: Mass

public required init(with massService: MassService, startMass: Mass)
public required init(with massService: MassRepository, startMass: Mass)
{
self.massService = massService
self.startMass = startMass
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public protocol AuthorizationRequestViewControllerDelegate {

public class AuthorizationRequestViewController: UIViewController {

let massService: MassService
let massService: MassRepository

public var delegate: AuthorizationRequestViewControllerDelegate?

Expand All @@ -24,7 +24,7 @@ public class AuthorizationRequestViewController: UIViewController {
return self.view as! AuthorizationRequestView
}

public required init(with massService: MassService)
public required init(with massService: MassRepository)
{
self.massService = massService
super.init(nibName: nil, bundle: nil)
Expand Down
12 changes: 12 additions & 0 deletions MyWeight/Services/MassRepository.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,18 @@
import Foundation

public protocol MassRepository {
var authorizationStatus: MassRepositoryAuthorizationStatus { get }
func fetch(_ completion: @escaping (_ results: [Mass]) -> Void)
func save(_ mass: Mass, completion: @escaping (_ error: Error?) -> Void)
func delete(_ mass: Mass, completion: @escaping (_ error: Error?) -> Void)
func requestAuthorization(_ completion: @escaping (_ error: Error?) -> Void )
#if os(iOS)
func requestAuthorizationForExtension()
#endif
}

public enum MassRepositoryAuthorizationStatus {
case notDetermined
case denied
case authorized
}
16 changes: 3 additions & 13 deletions MyWeight/Services/MassService.swift
Original file line number Diff line number Diff line change
Expand Up @@ -118,19 +118,9 @@ public class MassService: MassRepository {

// MARK: - Authorization

public enum AuthorizationStatus {
public var authorizationStatus: MassRepositoryAuthorizationStatus {

case notDetermined

case denied

case authorized

}

public var authorizationStatus: AuthorizationStatus {

let status: AuthorizationStatus
let status: MassRepositoryAuthorizationStatus

switch healthStore.authorizationStatus(for: massType) {
case .notDetermined:
Expand Down Expand Up @@ -161,7 +151,7 @@ public class MassService: MassRepository {
}

#if os(iOS)
func requestAuthorizationForExtension() {
public func requestAuthorizationForExtension() {
healthStore.handleAuthorizationForExtension { [weak self] (success, error) in
self?.startObservingMass()
Log.debug("Extension request \(success.description)")
Expand Down
9 changes: 5 additions & 4 deletions MyWeightTests/AccessDeniedViewControllerTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,17 @@ import Nimble_Snapshots
class AccessDeniedViewControllerTests: QuickSpec {

var viewController: AccessDeniedViewController!
let snapshoService = SnapshotService()
let snapshotService = SnapshotService()

override func spec() {
describe("AccessDeniedViewController Layout") {
describe("AccessDeniedViewController") {
beforeEach {
self.viewController = AccessDeniedViewController()
self.viewController.view.frame = UIScreen.main.bounds
}

it("should have the correct portrait layout on all iPhones") {
expect(self.viewController.view) == self.snapshoService.snapshot("AccessDeniedViewControllerTests", sizes: self.snapshoService.iPhonePortraitSizes)
it("should have the correct layout") {
expect(self.viewController.view).to(self.snapshotService.haveSnapshot())
}
}

Expand Down
30 changes: 13 additions & 17 deletions MyWeightTests/AddViewControllerTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,34 +7,30 @@ import Nimble_Snapshots
class AddViewControllerTests: QuickSpec {

var viewController: AddViewController!
let snapshoService = SnapshotService()
let snapshotService = SnapshotService()
var window: UIWindow!

override func spec() {
describe("AddViewController Layout") {
beforeEach {
self.window = nil
self.viewController = AddViewController(with: MassService(), startMass: Mass())
self.viewController = AddViewController(with: MassRepositoryMock(), startMass: Mass())

//For some misterios (apple bug) reason, setDate not work if you don't add the view to a window.
let frame = UIScreen.main.bounds
let window = UIWindow(frame: frame)
window.rootViewController = self.viewController
window.makeKeyAndVisible()
self.window = window
self.viewController.view.frame = frame
}

it("should have the correct portrait layout on all Sizes") {
let dateFormatter = DateFormatter()
dateFormatter.dateFormat = "dd/MM/yyyy"
let testDate = dateFormatter.date(from: "10/10/2016")!

expect(self.viewController.view) == self.snapshoService.snapshot("AddViewController - With Items", sizes: self.snapshoService.iPhonePortraitSizes, usesDrawRect: true, customResize: { view, size in
//For some misterios (apple bug) reason, setDate not work if you don't add the view to a window.

let newRect = CGRect(origin: CGPoint.zero, size: size)
let window = UIWindow(frame: newRect)
window.rootViewController = self.viewController
window.makeKeyAndVisible()
self.window = window

self.viewController.view.bounds = newRect

self.viewController.theView.datePicker.setDate(testDate, animated: false)
})

self.viewController.theView.datePicker.setDate(testDate, animated: false)
expect(self.viewController.view).to(self.snapshotService.haveSnapshot(usesDrawRect: true))
}
}
}
Expand Down
11 changes: 6 additions & 5 deletions MyWeightTests/AuthorizationRequestViewControllerTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,17 @@ import Nimble_Snapshots
class AuthorizationRequestViewControllerTests: QuickSpec {

var viewController: AuthorizationRequestViewController!
let snapshoService = SnapshotService()
let snapshotService = SnapshotService()

override func spec() {
describe("AuthorizationRequestViewController Layout") {
describe("AuthorizationRequestViewController") {
beforeEach {
self.viewController = AuthorizationRequestViewController(with: MassService())
self.viewController = AuthorizationRequestViewController(with: MassRepositoryMock())
self.viewController.view.frame = UIScreen.main.bounds
}

it("should have the correct portrait layout on all Sizes") {
expect(self.viewController.view) == self.snapshoService.snapshot("AuthorizationRequestViewController", sizes: self.snapshoService.iPhonePortraitSizes)
it("should have the correct layout") {
expect(self.viewController.view).to(self.snapshotService.haveSnapshot())
}
}
}
Expand Down
37 changes: 9 additions & 28 deletions MyWeightTests/ListViewControllerTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -16,29 +16,25 @@ class ListViewControllerTests: QuickSpec {

var viewController: ListViewController!
var massRepositoryMock: MassRepositoryMock!
let snapshoService = SnapshotService()
let snapshotService = SnapshotService()

override func spec() {
describe("ListViewController Layout") {
describe("ListViewController") {
beforeEach {
self.massRepositoryMock = MassRepositoryMock()
self.viewController = ListViewController(with: self.massRepositoryMock)
}

context("On empty response") {
it("should have the correct portrait layout on all Sizes") {
expect(self.viewController.view) == self.snapshoService.snapshot("ListViewController - Empty", sizes: self.snapshoService.iPhonePortraitSizes)
context("with empty response") {
it("should have the correct layout") {
expect(self.viewController.view).to(self.snapshotService.haveSnapshot())
}
}

context("On items") {

context("with items") {
let dateFormatter = DateFormatter()
dateFormatter.dateFormat = "dd/MM/yyyy HH:mm"

dateFormatter.dateFormat = "dd/MM/yyyy HH:mm"
beforeEach {


self.massRepositoryMock.fetchResponse = [
Mass(value: Measurement(value: 60, unit: .kilograms), date: dateFormatter.date(from: "10/10/2016 10:10")!),
Mass(value: Measurement(value: 62, unit: .kilograms), date: dateFormatter.date(from: "08/10/2016 9:10")!),
Expand All @@ -53,27 +49,12 @@ class ListViewControllerTests: QuickSpec {
_ = self.viewController.view
self.viewController.viewWillAppear(true)
self.viewController.viewDidAppear(true)

}

it("should have the correct portrait layout on all Sizes") {
expect(self.viewController.view) == self.snapshoService.snapshot("ListViewController - With Items", sizes: self.snapshoService.iPhonePortraitSizes)
it("should have the correct layout") {
expect(self.viewController.view).to(self.snapshotService.haveSnapshot())
}
}
}
}
}

class MassRepositoryMock: MassRepository {
var deleteResponse: Error?

public func delete(_ mass: Mass, completion: @escaping (Error?) -> Void) {
completion(self.deleteResponse)
}

var fetchResponse: [Mass]?

func fetch(_ completion: @escaping (_ results: [Mass]) -> Void) {
completion(self.fetchResponse ?? [])
}
}
37 changes: 37 additions & 0 deletions MyWeightTests/MassRepositoryMock.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
//
// MassRepositoryMock.swift
// MyWeightTests
//
// Created by Diogo Tridapalli on 25/11/17.
// Copyright © 2017 Diogo Tridapalli. All rights reserved.
//

import Foundation
@testable import MyWeight

class MassRepositoryMock: MassRepository {
var authorizationStatus: MassRepositoryAuthorizationStatus = .notDetermined

var fetchResponse: [Mass]?
func fetch(_ completion: @escaping (_ results: [Mass]) -> Void) {
completion(self.fetchResponse ?? [])
}

var saveError: Error?
func save(_ mass: Mass, completion: @escaping (Error?) -> Void) {
completion(saveError)
}

var requestAuthorizationError: Error?
func requestAuthorization(_ completion: @escaping (Error?) -> Void) {
completion(requestAuthorizationError)
}

func requestAuthorizationForExtension() {
}

var deleteResponse: Error?
public func delete(_ mass: Mass, completion: @escaping (Error?) -> Void) {
completion(self.deleteResponse)
}
}
Binary file removed ...sDeniedViewControllerTests/[email protected]
Binary file not shown.
Binary file removed ...essDeniedViewControllerTests/[email protected]
Binary file not shown.
Binary file removed ...sDeniedViewControllerTests/[email protected]
Binary file not shown.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file removed ...ages/AddViewControllerTests/[email protected]
Binary file not shown.
Binary file removed ...Images/AddViewControllerTests/[email protected]
Binary file not shown.
Binary file removed ...ages/AddViewControllerTests/[email protected]
Binary file not shown.
Binary file removed ...uestViewControllerTests/[email protected]
Binary file not shown.
Binary file removed ...equestViewControllerTests/[email protected]
Binary file not shown.
Binary file removed ...uestViewControllerTests/[email protected]
Binary file not shown.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file removed ...es/ListViewControllerTests/[email protected]
Binary file not shown.
Binary file removed ...ages/ListViewControllerTests/[email protected]
Binary file not shown.
Binary file removed ...es/ListViewControllerTests/[email protected]
Binary file not shown.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading

0 comments on commit 2b2a62b

Please sign in to comment.