-
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
1 changed file
with
108 additions
and
83 deletions.
There are no files selected for viewing
191 changes: 108 additions & 83 deletions
191
iOS/Layover/LayoverTests/Scenes/Profile/ProfileViewControllerTests.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,84 +1,109 @@ | ||
//// | ||
//// ProfileViewControllerTests.swift | ||
//// Layover | ||
//// | ||
//// Created by 김인환 on 12/12/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 | ||
// | ||
//class ProfileViewControllerTests: XCTestCase { | ||
// // MARK: Subject under test | ||
// | ||
// var sut: ProfileViewController! | ||
// var window: UIWindow! | ||
// | ||
// // MARK: - Test lifecycle | ||
// | ||
// override func setUp() { | ||
// super.setUp() | ||
// window = UIWindow() | ||
// setupProfileViewController() | ||
// } | ||
// | ||
// override func tearDown() { | ||
// window = nil | ||
// super.tearDown() | ||
// } | ||
// | ||
// // MARK: - Test setup | ||
// | ||
// func setupProfileViewController() { | ||
// let bundle = Bundle.main | ||
// let storyboard = UIStoryboard(name: "Main", bundle: bundle) | ||
// sut = storyboard.instantiateViewController(withIdentifier: "ProfileViewController") as! ProfileViewController | ||
// } | ||
// | ||
// func loadView() { | ||
// window.addSubview(sut.view) | ||
// RunLoop.current.run(until: Date()) | ||
// } | ||
// | ||
// // MARK: - Test doubles | ||
// | ||
// class ProfileBusinessLogicSpy: ProfileBusinessLogic { | ||
// var doSomethingCalled = false | ||
// | ||
// func doSomething(request: Profile.Something.Request) | ||
// { | ||
// doSomethingCalled = true | ||
// } | ||
// } | ||
// | ||
// // MARK: - Tests | ||
// | ||
// func testShouldDoSomethingWhenViewIsLoaded() { | ||
// // Given | ||
// let spy = ProfileBusinessLogicSpy() | ||
// sut.interactor = spy | ||
// | ||
// // When | ||
// loadView() | ||
// | ||
// // Then | ||
// XCTAssertTrue(spy.doSomethingCalled, "viewDidLoad() should ask the interactor to do something") | ||
// } | ||
// | ||
// func testDisplaySomething() { | ||
// // Given | ||
// let viewModel = Profile.Something.ViewModel() | ||
// | ||
// // When | ||
// loadView() | ||
// sut.displaySomething(viewModel: viewModel) | ||
// | ||
// // Then | ||
// //XCTAssertEqual(sut.nameTextField.text, "", "displaySomething(viewModel:) should update the name text field") | ||
// } | ||
//} | ||
// ProfileViewControllerTests.swift | ||
// Layover | ||
// | ||
// Created by 김인환 on 12/12/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 | ||
|
||
final class ProfileViewControllerTests: XCTestCase { | ||
// MARK: Subject under test | ||
|
||
var sut: ProfileViewController! | ||
typealias Models = ProfileModels | ||
|
||
// MARK: - Test lifecycle | ||
|
||
override func setUp() { | ||
super.setUp() | ||
setupProfileViewController() | ||
} | ||
|
||
// MARK: - Test setup | ||
|
||
func setupProfileViewController() { | ||
sut = ProfileViewController(profileType: .own) | ||
} | ||
|
||
// MARK: - Test doubles | ||
|
||
final class ProfileBusinessLogicSpy: ProfileBusinessLogic { | ||
var fetchProfileCalled = false | ||
var fetchMorePostsCalled = false | ||
var showPostDetailCalled = false | ||
var showPostDetailRequest: Models.ShowPostDetail.Request! | ||
|
||
func fetchProfile(with request: Models.FetchProfile.Request) -> Task<Bool, Never> { | ||
fetchProfileCalled = true | ||
return Task { | ||
return true | ||
} | ||
} | ||
|
||
func fetchMorePosts(with request: Models.FetchMorePosts.Request) -> Task<Bool, Never> { | ||
fetchMorePostsCalled = true | ||
return Task { | ||
return true | ||
} | ||
} | ||
|
||
func showPostDetail(with request: Models.ShowPostDetail.Request) { | ||
showPostDetailCalled = true | ||
showPostDetailRequest = request | ||
} | ||
|
||
} | ||
|
||
// MARK: - Tests | ||
|
||
func test_viewWillAppear가_호출되면_fetchProfile이_호출된다() { | ||
// arrange | ||
let spy = ProfileBusinessLogicSpy() | ||
sut.interactor = spy | ||
|
||
// act | ||
sut.viewWillAppear(false) | ||
|
||
// assert | ||
XCTAssertTrue(spy.fetchProfileCalled, "viewWillAppear가 호출되어 fetchProfile이 호출했다") | ||
} | ||
|
||
func test_스크롤이_바닥에_닿아_scrollViewBeginDecelerating이_호출되면_fetchPosts가_호출된다() { | ||
// arrange | ||
let spy = ProfileBusinessLogicSpy() | ||
sut.interactor = spy | ||
let scrollView = UIScrollView(frame: .init(x: 0, y: 0, width: 100, height: 100)) | ||
scrollView.contentSize.height = 200 | ||
scrollView.contentOffset.y = 300 | ||
|
||
|
||
// act | ||
sut.scrollViewWillBeginDecelerating(scrollView) | ||
|
||
// assert | ||
XCTAssertTrue(spy.fetchMorePostsCalled, "스크롤이 바닥에 닿아 scrollViewBeginDecelerating이 호출되어 fetchPosts가 호출했다") | ||
} | ||
|
||
func test_스크롤이_바닥에_닿지_않고_scrollViewBeginDecelerating이_호출되면_fetchPosts가_호출된다() { | ||
// arrange | ||
let spy = ProfileBusinessLogicSpy() | ||
sut.interactor = spy | ||
let scrollView = UIScrollView(frame: .init(x: 0, y: 0, width: 100, height: 100)) | ||
scrollView.contentSize.height = 200 | ||
scrollView.contentOffset.y = 100 | ||
|
||
|
||
// act | ||
sut.scrollViewWillBeginDecelerating(scrollView) | ||
|
||
// assert | ||
XCTAssertFalse(spy.fetchMorePostsCalled, "스크롤이 바닥에 닿지 않고 scrollViewBeginDecelerating이 호출되어 fetchPosts가 호출되지 않았다") | ||
} | ||
} |