Skip to content

Commit

Permalink
Merge pull request #12 from rcaos/snapshot-tests
Browse files Browse the repository at this point in the history
Fix Snapshot tests
  • Loading branch information
rcaos authored Dec 20, 2021
2 parents 53207ef + 182eb67 commit f3d13d5
Show file tree
Hide file tree
Showing 182 changed files with 1,661 additions and 861 deletions.
3 changes: 2 additions & 1 deletion Projects/Features/Account/Project.swift
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ let project = Project.framework(
.package(product: "RxBlocking"),
.package(product: "RxTest"),
.package(product: "Quick"),
.package(product: "Nimble")
.package(product: "Nimble"),
.package(product: "SnapshotTesting")
]
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
//
// AccountViewControllerFactoryMock.swift
// AccountTests
//
// Created by Jeans Ruiz on 20/12/21.
//

import UIKit
@testable import Account

class AccountViewControllerFactoryMock: AccountViewControllerFactory {
func makeSignInViewController() -> UIViewController {
let viewModel = SignInViewModelMock(state: .initial)
return SignInViewController(viewModel: viewModel)
}

func makeProfileViewController(with account: AccountResult) -> UIViewController {
let viewModel = ProfileViewModelMock(account: account)
return ProfileViewController(viewModel: viewModel)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
//
// AccountViewDarkTests.swift
// AccountTests
//
// Created by Jeans Ruiz on 20/12/21.
//

import XCTest
import SnapshotTesting
import RxSwift

@testable import Account

class AccountViewDarkTests: XCTestCase {

private let factory = AccountViewControllerFactoryMock()

override func setUp() {
super.setUp()
isRecording = false
}

func test_WhenViewIsLogin_thenShowLoginScreen() {
// given
let accountViewModel = AccountViewModelMock(state: .login)

let viewController = AccountViewController(viewModel: accountViewModel, viewControllersFactory: factory)
viewController.overrideUserInterfaceStyle = .dark

// then
assertSnapshot(matching: viewController, as: .wait(for: 1, on: .image(on: .iPhoneSe)))
}

func test_WhenViewIsLogged_thenShowProfileScreen() {
// given
let accountViewModel = AccountViewModelMock(state: .profile(account: AccountResult.stub()))

let viewController = AccountViewController(viewModel: accountViewModel, viewControllersFactory: factory)
viewController.overrideUserInterfaceStyle = .dark

// then
assertSnapshot(matching: viewController, as: .wait(for: 1, on: .image(on: .iPhoneSe)))
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
//
// AccountViewLightTests.swift
// AccountTV
//
// Created by Jeans Ruiz on 6/19/20.
// Copyright © 2020 Jeans. All rights reserved.
//

import XCTest
import SnapshotTesting
import RxSwift

@testable import Account

class AccountViewLightTests: XCTestCase {

private let factory = AccountViewControllerFactoryMock()

override func setUp() {
super.setUp()
isRecording = false
}

func test_WhenViewIsLogin_thenShowLoginScreen() {
// given
let accountViewModel = AccountViewModelMock(state: .login)

let viewController = AccountViewController(viewModel: accountViewModel, viewControllersFactory: factory)
viewController.overrideUserInterfaceStyle = .light

// then
assertSnapshot(matching: viewController, as: .wait(for: 1, on: .image(on: .iPhoneSe)))
}

func test_WhenViewIsLogged_thenShowProfileScreen() {
// given
let accountViewModel = AccountViewModelMock(state: .profile(account: AccountResult.stub()))

let viewController = AccountViewController(viewModel: accountViewModel, viewControllersFactory: factory)
viewController.overrideUserInterfaceStyle = .light

// then
assertSnapshot(matching: viewController, as: .wait(for: 1, on: .image(on: .iPhoneSe)))
}
}

This file was deleted.

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.
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
//
// SignInViewDarkTests.swift
// AccountTests
//
// Created by Jeans Ruiz on 20/12/21.
//

import XCTest
import SnapshotTesting
import RxSwift

@testable import Account

class SignInViewDarkTests: XCTestCase {

private var rootWindow: UIWindow!

override func setUp() {
super.setUp()
isRecording = false
}

func test_WhenViewIsInitial_thenShowInitialScreen() {
// given
let signInViewModel = SignInViewModelMock(state: .initial)
let viewController = SignInViewController(viewModel: signInViewModel)
viewController.overrideUserInterfaceStyle = .dark

// then
assertSnapshot(matching: viewController, as: .wait(for: 1, on: .image(on: .iPhoneSe)))
}

func test_WhenViewIsLoading_thenShowLoadingScreen() {
// given
let signInViewModel = SignInViewModelMock(state: .loading)
let viewController = SignInViewController(viewModel: signInViewModel)
viewController.overrideUserInterfaceStyle = .dark

// then
assertSnapshot(matching: viewController, as: .wait(for: 1, on: .image(on: .iPhoneSe)))
}

func test_WhenViewIsError_thenShowErrorScreen() {
// given
let signInViewModel = SignInViewModelMock(state: .error)
let viewController = SignInViewController(viewModel: signInViewModel)
viewController.overrideUserInterfaceStyle = .dark

// then
assertSnapshot(matching: viewController, as: .wait(for: 1, on: .image(on: .iPhoneSe)))
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
//
// SignInViewLightTests.swift
// AccountTVTests
//
// Created by Jeans Ruiz on 8/8/20.
//

import XCTest
import SnapshotTesting
import RxSwift

@testable import Account

class SignInViewLightTests: XCTestCase {

private var rootWindow: UIWindow!

override func setUp() {
super.setUp()
isRecording = false
}

func test_WhenViewIsInitial_thenShowInitialScreen() {
// given
let signInViewModel = SignInViewModelMock(state: .initial)
let viewController = SignInViewController(viewModel: signInViewModel)
viewController.overrideUserInterfaceStyle = .light

// then
assertSnapshot(matching: viewController, as: .wait(for: 1, on: .image(on: .iPhoneSe)))
}

func test_WhenViewIsLoading_thenShowLoadingScreen() {
// given
let signInViewModel = SignInViewModelMock(state: .loading)
let viewController = SignInViewController(viewModel: signInViewModel)
viewController.overrideUserInterfaceStyle = .light

// then
assertSnapshot(matching: viewController, as: .wait(for: 1, on: .image(on: .iPhoneSe)))
}

func test_WhenViewIsError_thenShowErrorScreen() {
// given
let signInViewModel = SignInViewModelMock(state: .error)
let viewController = SignInViewController(viewModel: signInViewModel)
viewController.overrideUserInterfaceStyle = .light

// then
assertSnapshot(matching: viewController, as: .wait(for: 1, on: .image(on: .iPhoneSe)))
}
}

This file was deleted.

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
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.
3 changes: 2 additions & 1 deletion Projects/Features/AiringToday/Project.swift
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ let project = Project.framework(
.package(product: "RxBlocking"),
.package(product: "RxTest"),
.package(product: "Quick"),
.package(product: "Nimble")
.package(product: "Nimble"),
.package(product: "SnapshotTesting")
]
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
//
// AiringTodayViewModelMock.swift
// AiringTodayTests
//
// Created by Jeans Ruiz on 19/12/21.
//

import Shared
import RxSwift
@testable import AiringToday

class AiringTodayViewModelMock: AiringTodayViewModelProtocol {

func viewDidLoad() { }

func didLoadNextPage() { }

func showIsPicked(with id: Int) { }

func refreshView() { }

func getCurrentViewState() -> SimpleViewState<AiringTodayCollectionViewModel> {
if let currentViewState = try? viewStateObservableSubject.value() {
return currentViewState
}
return .empty
}

var viewState: Observable<SimpleViewState<AiringTodayCollectionViewModel>>

var viewStateObservableSubject: BehaviorSubject<SimpleViewState<AiringTodayCollectionViewModel>>

init(state: SimpleViewState<AiringTodayCollectionViewModel>) {
viewStateObservableSubject = BehaviorSubject(value: state)
viewState = viewStateObservableSubject.asObservable()
}
}
Loading

0 comments on commit f3d13d5

Please sign in to comment.