From 9468a9ed1d183f22ce020c579dcefee19e72ca63 Mon Sep 17 00:00:00 2001 From: loinsir Date: Thu, 11 Jan 2024 02:08:35 +0900 Subject: [PATCH] =?UTF-8?q?:white=5Fcheck=5Fmark:=20SignUpPresenterTests?= =?UTF-8?q?=20=EC=9E=91=EC=84=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Scenes/SignUpScene/SignUpPresenter.swift | 2 +- .../Layover/Scenes/SignUpViewController.swift | 4 +- .../Scenes/SignUp/SignUpPresenterTests.swift | 198 +++++++++++++----- 3 files changed, 143 insertions(+), 61 deletions(-) diff --git a/iOS/Layover/Layover/Scenes/SignUpScene/SignUpPresenter.swift b/iOS/Layover/Layover/Scenes/SignUpScene/SignUpPresenter.swift index 64a0c61..0cc3278 100644 --- a/iOS/Layover/Layover/Scenes/SignUpScene/SignUpPresenter.swift +++ b/iOS/Layover/Layover/Scenes/SignUpScene/SignUpPresenter.swift @@ -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() { diff --git a/iOS/Layover/Layover/Scenes/SignUpViewController.swift b/iOS/Layover/Layover/Scenes/SignUpViewController.swift index dab52af..bbaffa9 100644 --- a/iOS/Layover/Layover/Scenes/SignUpViewController.swift +++ b/iOS/Layover/Layover/Scenes/SignUpViewController.swift @@ -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() } @@ -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 diff --git a/iOS/Layover/LayoverTests/Scenes/SignUp/SignUpPresenterTests.swift b/iOS/Layover/LayoverTests/Scenes/SignUp/SignUpPresenterTests.swift index 6f6e876..dd92fb6 100644 --- a/iOS/Layover/LayoverTests/Scenes/SignUp/SignUpPresenterTests.swift +++ b/iOS/Layover/LayoverTests/Scenes/SignUp/SignUpPresenterTests.swift @@ -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) + } +}