Skip to content

Commit

Permalink
✅ SignUpPresenterTests 작성
Browse files Browse the repository at this point in the history
  • Loading branch information
loinsir committed Jan 10, 2024
1 parent d5b192c commit 9468a9e
Show file tree
Hide file tree
Showing 3 changed files with 143 additions and 61 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ final class SignUpPresenter: SignUpPresentationLogic {

func presentNicknameDuplication(with response: SignUpModels.CheckDuplication.Response) {
let viewModel = Models.CheckDuplication.ViewModel(canSignUp: response.isValid)
viewController?.displayNickanmeDuplication(response: viewModel)
viewController?.displayNicknameDuplication(response: viewModel)
}

func presentSignUpSuccess() {
Expand Down
4 changes: 2 additions & 2 deletions iOS/Layover/Layover/Scenes/SignUpViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import UIKit

protocol SignUpDisplayLogic: AnyObject {
func displayNicknameValidation(response: SignUpModels.ValidateNickname.ViewModel)
func displayNickanmeDuplication(response: SignUpModels.CheckDuplication.ViewModel)
func displayNicknameDuplication(response: SignUpModels.CheckDuplication.ViewModel)
func navigateToMain()
}

Expand Down Expand Up @@ -163,7 +163,7 @@ extension SignUpViewController: SignUpDisplayLogic {
nicknameAlertLabel.textColor = .error
}

func displayNickanmeDuplication(response: SignUpModels.CheckDuplication.ViewModel) {
func displayNicknameDuplication(response: SignUpModels.CheckDuplication.ViewModel) {
nicknameAlertLabel.isHidden = false
nicknameAlertLabel.text = response.alertDescription
nicknameAlertLabel.textColor = response.canSignUp ? .correct : .error
Expand Down
198 changes: 140 additions & 58 deletions iOS/Layover/LayoverTests/Scenes/SignUp/SignUpPresenterTests.swift
Original file line number Diff line number Diff line change
@@ -1,62 +1,144 @@
////
//// SignUpPresenterTests.swift
//// Layover
////
//// Created by 김인환 on 1/6/24.
//// Copyright (c) 2024 CodeBomber. All rights reserved.
////
//// This file was generated by the Clean Swift Xcode Templates so
//// you can apply clean architecture to your iOS and Mac projects,
//// see http://clean-swift.com
////
//
//@testable import Layover
//import XCTest
// SignUpPresenterTests.swift
// Layover
//
//class SignUpPresenterTests: XCTestCase {
// // MARK: Subject under test
// Created by 김인환 on 1/6/24.
// Copyright (c) 2024 CodeBomber. All rights reserved.
//
// var sut: SignUpPresenter!
// This file was generated by the Clean Swift Xcode Templates so
// you can apply clean architecture to your iOS and Mac projects,
// see http://clean-swift.com
//
// // MARK: - Test lifecycle
//
// override func setUp() {
// super.setUp()
// setupSignUpPresenter()
// }
//
// override func tearDown() {
// super.tearDown()
// }
//
// // MARK: - Test setup
//
// func setupSignUpPresenter() {
// sut = SignUpPresenter()
// }
//
// // MARK: - Test doubles
//
// class SignUpDisplayLogicSpy: SignUpDisplayLogic {
// var displaySomethingCalled = false
//
// func displaySomething(viewModel: SignUp.Something.ViewModel) {
// displaySomethingCalled = true
// }
// }
//
// // MARK: - Tests
//
// func testPresentSomething() {
// // Given
// let spy = SignUpDisplayLogicSpy()
// sut.viewController = spy
// let response = SignUp.Something.Response()
//
// // When
// sut.presentSomething(response: response)
//
// // Then
// XCTAssertTrue(spy.displaySomethingCalled, "presentSomething(response:) should ask the view controller to display the result")
// }
//}

@testable import Layover
import XCTest

final class SignUpPresenterTests: XCTestCase {
// MARK: Subject under test

var sut: SignUpPresenter!

typealias Models = SignUpModels

// MARK: - Test lifecycle

override func setUp() {
super.setUp()
setupSignUpPresenter()
}

// MARK: - Test setup

func setupSignUpPresenter() {
sut = SignUpPresenter()
}

// MARK: - Test doubles

final class SignUpDisplayLogicSpy: SignUpDisplayLogic {
var displayNicknameValidationDidCalled = false
var displayNicknameValidationResponse: Models.ValidateNickname.ViewModel!
var displayNicknameDuplicationDidCalled = false
var displayNicknameDuplicationResponse: Models.CheckDuplication.ViewModel!
var navigateToMainDidCalled = false

func displayNicknameValidation(response: Models.ValidateNickname.ViewModel) {
displayNicknameValidationDidCalled = true
displayNicknameValidationResponse = response
}

func displayNicknameDuplication(response: Models.CheckDuplication.ViewModel) {
displayNicknameDuplicationDidCalled = true
displayNicknameDuplicationResponse = response
}

func navigateToMain() {
navigateToMainDidCalled = true
}
}

// MARK: - Tests

func test_presentNicknameValidation가_호출되고_전달되는_nicknameState가_valid면_ViewController의_displayNicknameValidation이_호출되고_올바른_값이_전달된다() {
// arrange
let spy = SignUpDisplayLogicSpy()
sut.viewController = spy
let nicknameState = NicknameState.valid

// act
sut.presentNicknameValidation(with: Models.ValidateNickname.Response(nicknameState: nicknameState))

// assert
XCTAssertTrue(spy.displayNicknameValidationDidCalled)
XCTAssertTrue(spy.displayNicknameValidationResponse.canCheckDuplication)
XCTAssertEqual(spy.displayNicknameValidationResponse.alertDescription, nicknameState.description)
}

func test_presentNicknameValidation가_호출되고_전달되는_nicknameState가_invalidCharacter면_ViewController의_displayNicknameValidation이_호출되고_올바른_값이_전달된다() {
// arrange
let spy = SignUpDisplayLogicSpy()
sut.viewController = spy
let nicknameState = NicknameState.invalidCharacter

// act
sut.presentNicknameValidation(with: Models.ValidateNickname.Response(nicknameState: nicknameState))

// assert
XCTAssertTrue(spy.displayNicknameValidationDidCalled)
XCTAssertFalse(spy.displayNicknameValidationResponse.canCheckDuplication)
XCTAssertEqual(spy.displayNicknameValidationResponse.alertDescription, nicknameState.description)
}

func test_presentNicknameValidation가_호출되고_전달되는_nicknameState가_lessThan2GreaterThan8면_ViewController의_displayNicknameValidation이_호출되고_올바른_값이_전달된다() {
// arrange
let spy = SignUpDisplayLogicSpy()
sut.viewController = spy
let nicknameState = NicknameState.lessThan2GreaterThan8

// act
sut.presentNicknameValidation(with: Models.ValidateNickname.Response(nicknameState: .lessThan2GreaterThan8))

// assert
XCTAssertTrue(spy.displayNicknameValidationDidCalled)
XCTAssertFalse(spy.displayNicknameValidationResponse.canCheckDuplication)
XCTAssertEqual(spy.displayNicknameValidationResponse.alertDescription, nicknameState.description)
}

func test_presentNicknameDuplication가_호출되면_ViewController의_displayNicknameDuplication이_호출되고_isValid_true값을_그대로_전달한다() {
// arrange
let spy = SignUpDisplayLogicSpy()
sut.viewController = spy

// act
sut.presentNicknameDuplication(with: Models.CheckDuplication.Response(isValid: true))

// assert
XCTAssertTrue(spy.displayNicknameDuplicationDidCalled)
XCTAssertTrue(spy.displayNicknameDuplicationResponse.canSignUp)
}

func test_presentNicknameDuplication가_호출되면_ViewController의_displayNicknameDuplication이_호출되고_전달받은_isValid_false값을_그대로_전달한다() {
// arrange
let spy = SignUpDisplayLogicSpy()
sut.viewController = spy

// act
sut.presentNicknameDuplication(with: Models.CheckDuplication.Response(isValid: false))

// assert
XCTAssertTrue(spy.displayNicknameDuplicationDidCalled)
XCTAssertFalse(spy.displayNicknameDuplicationResponse.canSignUp)
}

func test_presentSignUpSuccess가_호출되면_ViewController의_navigateToMain이_호출된다() {
// arrange
let spy = SignUpDisplayLogicSpy()
sut.viewController = spy

// act
sut.presentSignUpSuccess()

// assert
XCTAssertTrue(spy.navigateToMainDidCalled)
}
}

0 comments on commit 9468a9e

Please sign in to comment.