Skip to content

Commit

Permalink
✅ EditProfilePresenterTests추가
Browse files Browse the repository at this point in the history
  • Loading branch information
loinsir committed Dec 13, 2023
1 parent c7598d5 commit 3893280
Showing 1 changed file with 158 additions and 58 deletions.
Original file line number Diff line number Diff line change
@@ -1,62 +1,162 @@
////
//// EditProfilePresenterTests.swift
//// Layover
////
//// Created by 김인환 on 12/13/23.
//// Copyright (c) 2023 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
// EditProfilePresenterTests.swift
// Layover
//
//class EditProfilePresenterTests: XCTestCase {
// // MARK: Subject under test
// Created by 김인환 on 12/13/23.
// Copyright (c) 2023 CodeBomber. All rights reserved.
//
// var sut: EditProfilePresenter!
// 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()
// setupEditProfilePresenter()
// }
//
// override func tearDown() {
// super.tearDown()
// }
//
// // MARK: - Test setup
//
// func setupEditProfilePresenter() {
// sut = EditProfilePresenter()
// }
//
// // MARK: - Test doubles
//
// class EditProfileDisplayLogicSpy: EditProfileDisplayLogic {
// var displaySomethingCalled = false
//
// func displaySomething(viewModel: EditProfile.Something.ViewModel) {
// displaySomethingCalled = true
// }
// }
//
// // MARK: - Tests
//
// func testPresentSomething() {
// // Given
// let spy = EditProfileDisplayLogicSpy()
// sut.viewController = spy
// let response = EditProfile.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 EditProfilePresenterTests: XCTestCase {
// MARK: Subject under test

var sut: EditProfilePresenter!

typealias Models = EditProfileModels

// MARK: - Test lifecycle

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

override func tearDown() {
super.tearDown()
}

// MARK: - Test setup

func setupEditProfilePresenter() {
sut = EditProfilePresenter()
}

// MARK: - Test doubles

final class EditProfileDisplayLogicSpy: EditProfileDisplayLogic {
var displayProfileCalled = false
var displayProfileViewModel: Models.SetProfile.ViewModel!
var displayProfileEditCompletedCalled = false
var displayProfileEditCompletedViewModel: Models.EditProfile.ViewModel!
var displayChangedProfileStateCalled = false
var displayChangedProfileStateViewModel: Models.ChangeProfile.ViewModel!
var displayNicknameDuplicationCalled = false
var displayNicknameDuplicationViewModel: Models.CheckNicknameDuplication.ViewModel!

func displayProfile(with viewModel: Models.SetProfile.ViewModel) {
displayProfileCalled = true
displayProfileViewModel = viewModel
}

func displayProfileEditCompleted(with viewModel: Models.EditProfile.ViewModel) {
displayProfileEditCompletedCalled = true
displayProfileEditCompletedViewModel = viewModel
}

func displayChangedProfileState(with viewModel: Models.ChangeProfile.ViewModel) {
displayChangedProfileStateCalled = true
displayChangedProfileStateViewModel = viewModel
}

func displayNicknameDuplication(with viewModel: Models.CheckNicknameDuplication.ViewModel) {
displayNicknameDuplicationCalled = true
displayNicknameDuplicationViewModel = viewModel

}
}

// MARK: - Tests

func test_presentProfile을_실행하면_viewController의_displayProfile가_호출되고_올바른_값을_전달한다() {
// arrange
let spy = EditProfileDisplayLogicSpy()
sut.viewController = spy
let nickname = "안유진"
let introduce = "아이브의 리더"
let profileImageData = Seeds.sampleImageData
let response = Models.SetProfile.Response(nickname: nickname,
introduce: introduce,
profileImageData: profileImageData)

// act
sut.presentProfile(with: response)

// assert
XCTAssertTrue(spy.displayProfileCalled, "presentProfile을 실행해서 displayProfile이 호출되지 못했다")
XCTAssertEqual(spy.displayProfileViewModel.nickname, nickname, "presentProfile을 실행해서 올바른 nickname이 전달되지 못했다.")
XCTAssertEqual(spy.displayProfileViewModel.introduce, introduce, "presentProfile을 실행해서 올바른 introduce가 전달되지 못했다.")
XCTAssertEqual(spy.displayProfileViewModel.profileImageData, profileImageData, "presentProfile을 실행해서 올바른 profileImageData가 전달되지 못했다.")
}

func test_presentProfile을_실행하면_viewController의_displayProfileEditCompleted가_호출되고_isSuccess값이_true이면_toastMessage로_프로필이_수정되었습니다_를_전달한다() {
// arrange
let spy = EditProfileDisplayLogicSpy()
sut.viewController = spy
let response = Models.EditProfile.Response(isSuccess: true)

// act
sut.presentProfile(with: response)

// assert
XCTAssertTrue(spy.displayProfileEditCompletedCalled, "presentProfileEditCompleted을 실행해서 displayProfileEditCompleted이 호출되지 못했다")
XCTAssertEqual(spy.displayProfileEditCompletedViewModel.toastMessage, "프로필이 수정되었습니다.", "presentProfileEditCompleted을 실행해서 올바른 toastMessage가 전달되지 못했다.")
}

func test_presentProfile을_실행하면_viewController의_displayProfileEditCompleted가_호출되고_isSuccess값이_false면_toastMessage로_프로필_수정에_실패했습니다_를_전달한다() {
// arrange
let spy = EditProfileDisplayLogicSpy()
sut.viewController = spy
let response = Models.EditProfile.Response(isSuccess: false)

// act
sut.presentProfile(with: response)

// assert
XCTAssertTrue(spy.displayProfileEditCompletedCalled, "presentProfileEditCompleted을 실행해서 displayProfileEditCompleted이 호출되지 못했다")
XCTAssertEqual(spy.displayProfileEditCompletedViewModel.toastMessage, "프로필 수정에 실패했습니다.", "presentProfileEditCompleted을 실행해서 올바른 toastMessage가 전달되지 못했다.")
}

func test_presentProfileState를_실행하면_viewController의_displayChangedProfileState가_호출되고_올바른_값을_전달한다() {
// arrange
let spy = EditProfileDisplayLogicSpy()
sut.viewController = spy
let response = Models.ChangeProfile.Response(nicknameState: .lessThan2GreaterThan8,
nicknameAlertDescription: "닉네임 알림",
introduceAlertDescription: "소개글 알림",
canCheckNicknameDuplication: true,
canEditProfile: true)

// act
sut.presentProfileState(with: response)

// assert
XCTAssertTrue(spy.displayChangedProfileStateCalled, "presentProfileState을 실행해서 displayChangedProfileState이 호출되지 못했다")
XCTAssertEqual(spy.displayChangedProfileStateViewModel.nicknameState, .lessThan2GreaterThan8, "presentProfileState을 실행해서 올바른 nicknameState가 전달되지 못했다.")
XCTAssertEqual(spy.displayChangedProfileStateViewModel.nicknameAlertDescription, "닉네임 알림", "presentProfileState을 실행해서 올바른 nicknameAlertDescription가 전달되지 못했다.")
XCTAssertEqual(spy.displayChangedProfileStateViewModel.introduceAlertDescription, "소개글 알림", "presentProfileState을 실행해서 올바른 introduceAlertDescription가 전달되지 못했다.")
XCTAssertEqual(spy.displayChangedProfileStateViewModel.canCheckNicknameDuplication, true, "presentProfileState을 실행해서 올바른 canCheckNicknameDuplication가 전달되지 못했다.")
XCTAssertEqual(spy.displayChangedProfileStateViewModel.canEditProfile, true, "presentProfileState을 실행해서 올바른 canEditProfile이 전달되지 못했다.")
}

func test_presentNicknameDuplication을_실행하면_viewController의_displayNicknameDuplication이_호출되고_올바른_값을_전달한다() {
// arrange
let spy = EditProfileDisplayLogicSpy()
sut.viewController = spy
let response = Models.CheckNicknameDuplication.Response(isValid: true,
canEditProfile: true)

// act
sut.presentNicknameDuplication(with: response)

// assert
XCTAssertTrue(spy.displayNicknameDuplicationCalled, "presentNicknameDuplication을 실행해서 displayNicknameDuplication이 호출되지 못했다")
XCTAssertEqual(spy.displayNicknameDuplicationViewModel.isValidNickname, true, "presentNicknameDuplication을 실행해서 올바른 isValidNickname이 전달되지 못했다.")
XCTAssertEqual(spy.displayNicknameDuplicationViewModel.canEditProfile, true, "presentNicknameDuplication을 실행해서 올바른 canEditProfile이 전달되지 못했다.")
}
}

0 comments on commit 3893280

Please sign in to comment.