-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
143 additions
and
61 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
198 changes: 140 additions & 58 deletions
198
iOS/Layover/LayoverTests/Scenes/SignUp/SignUpPresenterTests.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
} | ||
} |