diff --git a/LionHeart-iOS/LionHeart-iOS/Scenes/Challenge/ViewController/ChallengeViewController.swift b/LionHeart-iOS/LionHeart-iOS/Scenes/Challenge/ViewController/ChallengeViewController.swift index 3bdb12f..2a6a9a7 100644 --- a/LionHeart-iOS/LionHeart-iOS/Scenes/Challenge/ViewController/ChallengeViewController.swift +++ b/LionHeart-iOS/LionHeart-iOS/Scenes/Challenge/ViewController/ChallengeViewController.swift @@ -23,7 +23,7 @@ final class ChallengeViewController: UIViewController, ChallengeViewControllerab private let leftSeperateLine = LHUnderLine(lineColor: .background) private let rightSeperateLine = LHUnderLine(lineColor: .background) - private lazy var navigationBar = LHNavigationBarView(type: .challenge, viewController: self) + lazy var navigationBar = LHNavigationBarView(type: .challenge, viewController: self) let nicknameLabel = LHLabel(type: .body2R, color: .gray200) let challengeDayLabel = LHLabel(type: .head3, color: .white) let challengelevelLabel = LHLabel(type: .body4, color: .gray500) diff --git a/LionHeart-iOS/LionHeart-iOSTests/Challenge/Stubs/ChallengeViewModelStub.swift b/LionHeart-iOS/LionHeart-iOSTests/Challenge/Stubs/ChallengeViewModelStub.swift index 84cd1e7..564fde1 100644 --- a/LionHeart-iOS/LionHeart-iOSTests/Challenge/Stubs/ChallengeViewModelStub.swift +++ b/LionHeart-iOS/LionHeart-iOSTests/Challenge/Stubs/ChallengeViewModelStub.swift @@ -16,6 +16,7 @@ final class ChallengeViewModelStub: ChallengeViewModel { var navigationSubject = PassthroughSubject() private var cancelBag = Set() let errorSubject = PassthroughSubject() + var willPublishedData: ChallengeData? var inputData: ChallengeData! @@ -35,6 +36,7 @@ final class ChallengeViewModelStub: ChallengeViewModel { let viewWillAppearSubject = input.viewWillAppearSubject .flatMap { _ -> AnyPublisher in + self.willPublishedData = self.inputData return Just(self.inputData) .eraseToAnyPublisher() } diff --git a/LionHeart-iOS/LionHeart-iOSTests/Challenge/ViewControllerTests/ChallengeViewControllerTests.swift b/LionHeart-iOS/LionHeart-iOSTests/Challenge/ViewControllerTests/ChallengeViewControllerTests.swift index ff18f75..320948b 100644 --- a/LionHeart-iOS/LionHeart-iOSTests/Challenge/ViewControllerTests/ChallengeViewControllerTests.swift +++ b/LionHeart-iOS/LionHeart-iOSTests/Challenge/ViewControllerTests/ChallengeViewControllerTests.swift @@ -11,16 +11,31 @@ import Combine final class ChallengeViewControllerTests: XCTestCase { var viewModel: ChallengeViewModelStub! - + var cancelBag: Set! override func setUpWithError() throws { self.viewModel = ChallengeViewModelStub() + self.cancelBag = Set() } override func tearDownWithError() throws { self.viewModel = nil + self.cancelBag = nil + } + + func test_viewWillAppear의_시점이_viewModel에_잘_전달되었는지() { + //given + let inputData = ChallengeData(babyDaddyName: "튼튼이", howLongDay: 10, daddyLevel: "LEVEL_ONE", daddyAttendances: ["11/1", "11/2", "11/3"]) + self.viewModel.inputData = inputData + let viewController = ChallengeViewController(viewModel: self.viewModel) + + //when + viewController.loadViewIfNeeded() + viewController.viewWillAppear(false) + + XCTAssertEqual(self.viewModel.willPublishedData, inputData) } - func testExample() throws { + func test_ChallengeVC의_UserData가_UI에_잘_반영되었는지() throws { //given let inputData = ChallengeData(babyDaddyName: "튼튼이", howLongDay: 10, daddyLevel: "LEVEL_ONE", daddyAttendances: ["11/1", "11/2", "11/3"]) let viewController = ChallengeViewController(viewModel: self.viewModel) @@ -36,7 +51,7 @@ final class ChallengeViewControllerTests: XCTestCase { } - func test_Challenge현황판이_잘보이는지() { + func test_ChallengeVC의_CollectionView에_데이터가_잘들어갔는지() { //given let inputData = ChallengeData(babyDaddyName: "튼튼이", howLongDay: 10, daddyLevel: "LEVEL_ONE", daddyAttendances: ["11/1", "11/2", "11/3"]) let viewController = ChallengeViewController(viewModel: self.viewModel) @@ -68,4 +83,59 @@ final class ChallengeViewControllerTests: XCTestCase { XCTAssertEqual(cell3.countLabel.text, "\(0+3+1)") XCTAssertEqual(cell3.backgroundColor, .designSystem(.gray1000)) } + + func test_Navigation의_북마크버튼이_잘_동작하는지() { + //given + let viewController = ChallengeViewController(viewModel: self.viewModel) + viewController.loadViewIfNeeded() + + //when + let expectation = XCTestExpectation(description: "네비게이션왼쪽버튼이 눌렸을때") + var navigationType: ChallengeViewModelStub.FlowType? + viewModel.navigationSubject + .sink { type in + navigationType = type + expectation.fulfill() + } + .store(in: &cancelBag) + + viewController.navigationBar.rightFirstBarItem.sendActions(for: .touchUpInside) + + //then + wait(for: [expectation], timeout: 0.3) + XCTAssertEqual(navigationType, .bookmarkButtonTapped) + } + + func test_Navigation의_마이페이지버튼이_잘_동작하는지() { + //given + let viewController = ChallengeViewController(viewModel: self.viewModel) + viewController.loadViewIfNeeded() + + //when + let expectation = XCTestExpectation(description: "네비게이션오른쪽버튼이 눌렸을때") + var navigationType: ChallengeViewModelStub.FlowType? + viewModel.navigationSubject + .sink { type in + navigationType = type + expectation.fulfill() + } + .store(in: &cancelBag) + + viewController.navigationBar.rightSecondBarItem.sendActions(for: .touchUpInside) + + //then + wait(for: [expectation], timeout: 0.3) + XCTAssertEqual(navigationType, .myPageButtonTapped) + } + + func test_ChallengeVC의_CollectionView의_CellSize가_5분의1인지() { + //given + let viewController = ChallengeViewController(viewModel: self.viewModel) + viewController.loadViewIfNeeded() + + let collectionView = viewController.challengeDayCheckCollectionView.contentSize + + let cell0 = viewContro + + } }