From 166e75680d655f153bedc13d136f63c308cff18c Mon Sep 17 00:00:00 2001 From: chopmozzi <44396392+chopmozzi@users.noreply.github.com> Date: Tue, 9 Jan 2024 00:39:21 +0900 Subject: [PATCH] =?UTF-8?q?:white=5Fcheck=5Fmark:=20PlaybackInteractor=20T?= =?UTF-8?q?est=201=EC=B0=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- iOS/Layover/Layover.xcodeproj/project.pbxproj | 4 + .../Scenes/Playback/PlaybackInteractor.swift | 2 +- .../Workers/Mocks/MockPlaybackWorker.swift | 13 +- .../Workers/PlaybackInteractorTests.swift | 652 ++++++++++++++++++ 4 files changed, 666 insertions(+), 5 deletions(-) create mode 100644 iOS/Layover/LayoverTests/Mocks/Workers/PlaybackInteractorTests.swift diff --git a/iOS/Layover/Layover.xcodeproj/project.pbxproj b/iOS/Layover/Layover.xcodeproj/project.pbxproj index d647afc..e31f751 100644 --- a/iOS/Layover/Layover.xcodeproj/project.pbxproj +++ b/iOS/Layover/Layover.xcodeproj/project.pbxproj @@ -146,6 +146,7 @@ 835A61A62B0B4DDD002F22A5 /* Dashboard-Regular.ttf in Resources */ = {isa = PBXBuildFile; fileRef = 835A61A52B0B4DDD002F22A5 /* Dashboard-Regular.ttf */; }; 835A61A92B0B5A31002F22A5 /* LoginConfigurator.swift in Sources */ = {isa = PBXBuildFile; fileRef = 835A61A82B0B5A31002F22A5 /* LoginConfigurator.swift */; }; 8363A32D2B4C1CBB00772DDF /* PlaybackPresenterTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8363A32C2B4C1CBA00772DDF /* PlaybackPresenterTests.swift */; }; + 8363A32F2B4C329100772DDF /* PlaybackInteractorTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8363A32E2B4C329100772DDF /* PlaybackInteractorTests.swift */; }; 836C33872B15A29600ECAFB0 /* Toast.swift in Sources */ = {isa = PBXBuildFile; fileRef = 836C33862B15A29600ECAFB0 /* Toast.swift */; }; 836C338B2B15D22C00ECAFB0 /* PlaybackConfigurator.swift in Sources */ = {isa = PBXBuildFile; fileRef = 836C338A2B15D22C00ECAFB0 /* PlaybackConfigurator.swift */; }; 836C33912B17629400ECAFB0 /* MapRouter.swift in Sources */ = {isa = PBXBuildFile; fileRef = 836C33902B17629400ECAFB0 /* MapRouter.swift */; }; @@ -404,6 +405,7 @@ 835A61A82B0B5A31002F22A5 /* LoginConfigurator.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LoginConfigurator.swift; sourceTree = ""; }; 835A61AA2B0B85FD002F22A5 /* en */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = en; path = en.lproj/LaunchScreen.strings; sourceTree = ""; }; 8363A32C2B4C1CBA00772DDF /* PlaybackPresenterTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; name = PlaybackPresenterTests.swift; path = LayoverTests/Mocks/Workers/PlaybackPresenterTests.swift; sourceTree = SOURCE_ROOT; }; + 8363A32E2B4C329100772DDF /* PlaybackInteractorTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; name = PlaybackInteractorTests.swift; path = LayoverTests/Mocks/Workers/PlaybackInteractorTests.swift; sourceTree = SOURCE_ROOT; }; 836C33862B15A29600ECAFB0 /* Toast.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Toast.swift; sourceTree = ""; }; 836C338A2B15D22C00ECAFB0 /* PlaybackConfigurator.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PlaybackConfigurator.swift; sourceTree = ""; }; 836C33902B17629400ECAFB0 /* MapRouter.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MapRouter.swift; sourceTree = ""; }; @@ -876,6 +878,7 @@ isa = PBXGroup; children = ( 8363A32C2B4C1CBA00772DDF /* PlaybackPresenterTests.swift */, + 8363A32E2B4C329100772DDF /* PlaybackInteractorTests.swift */, ); path = Playback; sourceTree = ""; @@ -1612,6 +1615,7 @@ 19AE481A2B28C2B700DD4612 /* SettingPresenterTests.swift in Sources */, 19AE48172B28C2B700DD4612 /* SettingViewControllerTests.swift in Sources */, 194C21C32B1DEE6B00C62645 /* HomeViewControllerTests.swift in Sources */, + 8363A32F2B4C329100772DDF /* PlaybackInteractorTests.swift in Sources */, 192513692B26F7CE001533FA /* TagPlayListInteractorTests.swift in Sources */, 19AE48232B29D03D00DD4612 /* EditProfileInteractorTests.swift in Sources */, 194C21CC2B1DF39200C62645 /* MockHomeWorker.swift in Sources */, diff --git a/iOS/Layover/Layover/Scenes/Playback/PlaybackInteractor.swift b/iOS/Layover/Layover/Scenes/Playback/PlaybackInteractor.swift index 8d9ff6d..ef93b5a 100644 --- a/iOS/Layover/Layover/Scenes/Playback/PlaybackInteractor.swift +++ b/iOS/Layover/Layover/Scenes/Playback/PlaybackInteractor.swift @@ -77,7 +77,7 @@ final class PlaybackInteractor: PlaybackBusinessLogic, PlaybackDataStore { private var currentPage: Int = 1 - private var playbackVideoInfos: [Models.PlaybackInfo] = [] + var playbackVideoInfos: [Models.PlaybackInfo] = [] // MARK: - UseCase Load Video List diff --git a/iOS/Layover/Layover/Workers/Mocks/MockPlaybackWorker.swift b/iOS/Layover/Layover/Workers/Mocks/MockPlaybackWorker.swift index 0a418b5..58d4dd4 100644 --- a/iOS/Layover/Layover/Workers/Mocks/MockPlaybackWorker.swift +++ b/iOS/Layover/Layover/Workers/Mocks/MockPlaybackWorker.swift @@ -27,10 +27,15 @@ final class MockPlaybackWorker: PlaybackWorkerProtocol { } func makeInfiniteScroll(posts: [Post]) -> [Post] { - guard let tempLastVideo: Post = posts.last, - let tempFirstVideo: Post = posts.first - else { return posts } - var tempVideos: [Post] = posts + var tempVideos: [Post] = [] + for post in posts { + if post.board.videoURL != nil, post.board.status == .complete { + tempVideos.append(post) + } + } + guard let tempLastVideo: Post = tempVideos.last, + let tempFirstVideo: Post = tempVideos.first + else { return tempVideos } tempVideos.insert(tempLastVideo, at: 0) tempVideos.append(tempFirstVideo) return tempVideos diff --git a/iOS/Layover/LayoverTests/Mocks/Workers/PlaybackInteractorTests.swift b/iOS/Layover/LayoverTests/Mocks/Workers/PlaybackInteractorTests.swift new file mode 100644 index 0000000..1483b34 --- /dev/null +++ b/iOS/Layover/LayoverTests/Mocks/Workers/PlaybackInteractorTests.swift @@ -0,0 +1,652 @@ +// +// PlaybackInteractorTests.swift +// LayoverTests +// +// Created by 황지웅 on 12/12/23. +// Copyright © 2023 CodeBomber. All rights reserved. +// + +@testable import Layover +import XCTest + +final class PlaybackInteractorTests: XCTestCase { + // MARK: Subject under test + + var sut: PlaybackInteractor! + + // MARK: Properties + + typealias Models = PlaybackModels + + // MARK: - Test lifecycle + + override func setUp() { + super.setUp() + setupPlaybackInteracotr() + } + + override func tearDown() { + super.tearDown() + } + + // MARK: - Test setup + + func setupPlaybackInteracotr() { + sut = PlaybackInteractor() + sut.worker = MockPlaybackWorker() + } + + // MARK: - Test doubles + + final class PlaybackPresentationLogicSpy: PlaybackPresentationLogic { + var presentVideoListDidCalled = false + var presentVideoListResponse: Models.LoadPlaybackVideoList.Response! + + var presentLoadFetchVideosDidCalled = false + var presentLoadFetchVideosResponse: Models.LoadPlaybackVideoList.Response! + + var presentSetInitialPlaybackCellDidCalled = false + var presentSetInitialPlaybackCellResponse: Models.SetInitialPlaybackCell.Response! + + var presentMoveInitialPlaybackCellDidCalled = false + var presentMoveInitialPlaybackCellResponse: Models.SetInitialPlaybackCell.Response! + + var presentMoveCellNextDidCalled = false + var presentMoveCellNextResponse: Models.DisplayPlaybackVideo.Response! + + var presentPlayInitialPlaybackCellDidCalled = false + var presentPlayInitialPlaybackCellResponse: Models.DisplayPlaybackVideo.Response! + + var presentShowPlayerSliderDidCalled = false + var presentShowPlayerSliderResponse: Models.DisplayPlaybackVideo.Response! + + var presentTeleportCellDidCalled = false + var presentTeleportCellResponse: Models.DisplayPlaybackVideo.Response! + + var presentLeavePlaybackViewDidCalled = false + var presentLeavePlaybackViewResponse: Models.DisplayPlaybackVideo.Response! + + var presentResetPlaybackCellDidCalled = false + var presentResetPlaybackCellResponse: Models.DisplayPlaybackVideo.Response! + + var presentConfigureCellDidCalled = false + var presentConfigureCellResponse: Models.ConfigurePlaybackCell.Response! + + var presentSetSeemoreButtonDidCalled = false + var presentSetSeemoreButtonResponse: Models.SetSeemoreButton.Response! + + var presentDeleteVideoDidCalled = false + var presentDeleteVideoResponse: Models.DeletePlaybackVideo.Response! + + var presentProfileDidCalled = false + + var presentTagPlayDidCalled = false + + var presentLoadProfileImageAndLocationDidCalled = false + var presentLoadProfileImageAndLocationResponse: Models.LoadProfileImageAndLocation.Response! + + var presentSeekVideoDidCalled = false + var presentSeekVideoResponse: Models.SeekVideo.Response! + + var presentReportVideoDidCalled = false + + func presentVideoList(with response: Layover.PlaybackModels.LoadPlaybackVideoList.Response) { + presentVideoListDidCalled = true + presentVideoListResponse = response + } + + func presentLoadFetchVideos(with response: Layover.PlaybackModels.LoadPlaybackVideoList.Response) { + presentLoadFetchVideosDidCalled = true + presentLoadFetchVideosResponse = response + } + + func presentSetInitialPlaybackCell(with response: Layover.PlaybackModels.SetInitialPlaybackCell.Response) { + presentSetInitialPlaybackCellDidCalled = true + presentSetInitialPlaybackCellResponse = response + } + + func presentMoveInitialPlaybackCell(with response: Layover.PlaybackModels.SetInitialPlaybackCell.Response) { + presentMoveInitialPlaybackCellDidCalled = true + presentMoveInitialPlaybackCellResponse = response + } + + func presentMoveCellNext(with response: Layover.PlaybackModels.DisplayPlaybackVideo.Response) { + presentMoveCellNextDidCalled = true + presentMoveCellNextResponse = response + } + + func presentPlayInitialPlaybackCell(with response: Layover.PlaybackModels.DisplayPlaybackVideo.Response) { + presentPlayInitialPlaybackCellDidCalled = true + presentPlayInitialPlaybackCellResponse = response + } + + func presentShowPlayerSlider(with response: Layover.PlaybackModels.DisplayPlaybackVideo.Response) { + presentShowPlayerSliderDidCalled = true + presentShowPlayerSliderResponse = response + } + + func presentTeleportCell(with response: Layover.PlaybackModels.DisplayPlaybackVideo.Response) { + presentTeleportCellDidCalled = true + presentTeleportCellResponse = response + } + + func presentLeavePlaybackView(with response: Layover.PlaybackModels.DisplayPlaybackVideo.Response) { + presentLeavePlaybackViewDidCalled = true + presentLeavePlaybackViewResponse = response + } + + func presentResetPlaybackCell(with response: Layover.PlaybackModels.DisplayPlaybackVideo.Response) { + presentResetPlaybackCellDidCalled = true + presentResetPlaybackCellResponse = response + } + + func presentConfigureCell(with response: Layover.PlaybackModels.ConfigurePlaybackCell.Response) { + presentConfigureCellDidCalled = true + presentConfigureCellResponse = response + } + + func presentSetSeemoreButton(with response: Layover.PlaybackModels.SetSeemoreButton.Response) { + presentSetSeemoreButtonDidCalled = true + presentSetSeemoreButtonResponse = response + } + + func presentDeleteVideo(with response: Layover.PlaybackModels.DeletePlaybackVideo.Response) { + presentDeleteVideoDidCalled = true + presentDeleteVideoResponse = response + } + + func presentProfile() { + presentProfileDidCalled = true + } + + func presentTagPlay() { + presentTagPlayDidCalled = true + } + + func presentLoadProfileImageAndLocation(with response: Layover.PlaybackModels.LoadProfileImageAndLocation.Response) { + presentLoadProfileImageAndLocationDidCalled = true + presentLoadProfileImageAndLocationResponse = response + } + + func presentSeekVideo(with response: Layover.PlaybackModels.SeekVideo.Response) { + presentSeekVideoDidCalled = true + presentSeekVideoResponse = response + } + + func presentReportVideo() { + presentReportVideoDidCalled = true + } + } + + // MARK: - Tests + + func test_parentView가_map일_때_displayVideoList를_호출하면_presentVideoList를_호출하고_올바른_데이터를_전달한다() async { + // Arrange + let spy = PlaybackPresentationLogicSpy() + sut.presenter = spy + sut.parentView = .map + sut.posts = [Seeds.Posts.post1, Seeds.Posts.post2, Seeds.Posts.videoURLNilPost] + + // Act + await sut.displayVideoList() + + // Assert + XCTAssertTrue(spy.presentVideoListDidCalled, "displayVideoList는 presentVideoList를 호출하지 않았습니다") + // map이므로 2 + 더미셀 2 = 4 + // videoURL이 nil이면 거름 + print(spy.presentVideoListResponse.videos) + XCTAssertEqual(spy.presentVideoListResponse.videos.count, 4) + XCTAssertEqual(spy.presentVideoListResponse.videos[0].displayedPost, spy.presentVideoListResponse.videos[2].displayedPost) + XCTAssertEqual(spy.presentVideoListResponse.videos[1].displayedPost, spy.presentVideoListResponse.videos[1].displayedPost) + XCTAssertEqual(spy.presentVideoListResponse.videos.first!.displayedPost, Seeds.PlaybackVideos.videos.last!.displayedPost) + XCTAssertEqual(spy.presentVideoListResponse.videos.last!.displayedPost, Seeds.PlaybackVideos.videos.first!.displayedPost) + } + + func test_displayVideoList를_호출하면_presentVideoList를_호출하고_올바른_데이터를_전달한다_parentView가_map이_아닐때() async { + // Arrange + let spy = PlaybackPresentationLogicSpy() + sut.presenter = spy + sut.parentView = .home + sut.posts = [Seeds.Posts.post1, Seeds.Posts.post2, Seeds.Posts.videoURLNilPost] + + // Act + await sut.displayVideoList() + + // Assert + XCTAssertTrue(spy.presentVideoListDidCalled, "displayVideoList는 presentVideoList를 호출하지 않았습니다") + // map이므로 2 + 더미셀 2 = 4 + // videoURL이 nil이면 거름 + XCTAssertEqual(spy.presentVideoListResponse.videos.count, 2) + XCTAssertEqual(spy.presentVideoListResponse.videos.first!.displayedPost, Seeds.PlaybackVideos.videos.first!.displayedPost) + XCTAssertEqual(spy.presentVideoListResponse.videos.last!.displayedPost, Seeds.PlaybackVideos.videos.last!.displayedPost) + } + + func test_moveInitialPlaybackCell을_호출하면_presentMoveInitialPlaybackCell을_호출하고_올바른_데이터를_전달한다_parentView가_map일_때() { + // Arrange + let spy = PlaybackPresentationLogicSpy() + sut.parentView = .map + sut.index = 2 + sut.presenter = spy + + // Act + sut.moveInitialPlaybackCell() + + // Assert + XCTAssertTrue(spy.presentMoveInitialPlaybackCellDidCalled, "moveInitialPlaybackCell은 moveInitialPlaybackCell을 호출하지 않았습니다") + XCTAssertEqual(spy.presentMoveInitialPlaybackCellResponse.indexPathRow, 3) + } + + func test_moveInitialPlaybackCell을_호출하면_presentMoveInitialPlaybackCell을_호출하고_올바른_데이터를_전달한다_parentView가_map이_아닐때() { + // Arrange + let spy = PlaybackPresentationLogicSpy() + sut.parentView = .home + sut.index = 2 + sut.presenter = spy + + // Act + sut.moveInitialPlaybackCell() + + // Assert + XCTAssertTrue(spy.presentMoveInitialPlaybackCellDidCalled, "moveInitialPlaybackCell은 moveInitialPlaybackCell을 호출하지 않았습니다") + XCTAssertEqual(spy.presentMoveInitialPlaybackCellResponse.indexPathRow, 2) + } + + func test_setInitialPlaybackCell을_호출하면_presentSetInitialPlaybackCell을_호출하고_올바른_데이터를_전달한다_parentView가_map일_때() { + // Arraynge + let spy = PlaybackPresentationLogicSpy() + sut.parentView = .map + sut.index = 2 + sut.presenter = spy + + // Act + sut.setInitialPlaybackCell() + + // Assert + XCTAssertTrue(spy.presentSetInitialPlaybackCellDidCalled, "setInitialPlaybackCell은 presentSetInitialPlaybackCell을 호출하지 않았습니다.") + XCTAssertEqual(spy.presentSetInitialPlaybackCellResponse.indexPathRow, 3) + } + + func test_setInitialPlaybackCell을_호출하면_presentSetInitialPlaybackCell을_호출하고_올바른_데이터를_전달한다_parentView가_map이_아닐때() { + // Arraynge + let spy = PlaybackPresentationLogicSpy() + sut.parentView = .map + sut.index = 2 + sut.presenter = spy + + // Act + sut.setInitialPlaybackCell() + + // Assert + XCTAssertTrue(spy.presentSetInitialPlaybackCellDidCalled, "setInitialPlaybackCell은 presentSetInitialPlaybackCell을 호출하지 않았습니다") + XCTAssertEqual(spy.presentSetInitialPlaybackCellResponse.indexPathRow, 3) + } + + func test_playInitialPlaybackCell을_호출하면_presentPlayInitialPlaybackCell을_호출하고_올바른_데이터를_전달한다() { + // Arrange + let spy = PlaybackPresentationLogicSpy() + let request: Models.DisplayPlaybackVideo.Request = Models.DisplayPlaybackVideo.Request(indexPathRow: nil, currentCell: Seeds.PlaybackVideo.currentCell) + sut.presenter = spy + // Act + sut.playInitialPlaybackCell(with: request) + + // Assert + XCTAssertTrue(spy.presentPlayInitialPlaybackCellDidCalled, "playInitialPlaybackCell은 presentInitialPlaybackCell을 호출하지 않았습니다") + XCTAssertEqual(spy.presentPlayInitialPlaybackCellResponse.previousCell, nil) + XCTAssertEqual(spy.presentPlayInitialPlaybackCellResponse.currentCell, sut.previousCell) + XCTAssertEqual(spy.presentPlayInitialPlaybackCellResponse.currentCell, Seeds.PlaybackVideo.currentCell) + } + + func test_playVideo를_호출할_때_이전Cell과_현재Cell이_동일하면_presentShowPlayerSlider를_호출한다() { + // Arrange + let spy = PlaybackPresentationLogicSpy() + sut.posts = [Seeds.Posts.post1, Seeds.Posts.post2, Seeds.Posts.videoURLNilPost] + sut.previousCell = Seeds.PlaybackVideo.currentCell + let request: Models.DisplayPlaybackVideo.Request = Models.DisplayPlaybackVideo.Request(indexPathRow: nil, currentCell: Seeds.PlaybackVideo.currentCell) + sut.presenter = spy + // Act + sut.playVideo(with: request) + + // Assert + XCTAssertTrue(spy.presentShowPlayerSliderDidCalled, "playVideo는 presentShowPlayerSlider를 호출하지 않았습니다") + XCTAssertEqual(spy.presentShowPlayerSliderResponse.currentCell, request.currentCell) + } + +// func test_playVideo를_호출하면_presentMoveCellNext를_호출한다_parentView가_map이고_index가_마지막을_가리킬_떄() { +// // Arrange +// let spy = PlaybackPresentationLogicSpy() +// sut.parentView = .map +// sut.posts = [Seeds.Posts.post1, Seeds.Posts.post2] +// sut.previousCell = Seeds.PlaybackVideo.previousCell +// let request: Models.DisplayPlaybackVideo.Request = Models.DisplayPlaybackVideo.Request(indexPathRow: 1, currentCell: Seeds.PlaybackVideo.currentCell) +// sut.presenter = spy +// // act +// sut.playVideo(with: request) +// +// // Assert +// XCTAssertTrue(spy.presentTeleportCellDidCalled, "playVideo는 presentTeleportCell를 호출하지 않았습니다") +// XCTAssertEqual(sut.previousCell, Seeds.PlaybackVideo.previousCell) +// XCTAssertEqual(spy.presentTeleportCellResponse.previousCell, Seeds.PlaybackVideo.previousCell) +// XCTAssertEqual(spy.presentTeleportCellResponse.indexPathRow, 1) +// XCTAssertTrue(((sut.isTeleport) != nil)) +// } + +// func test_playVideo를_호출하면_presentMoveCellNext를_호출한다_parentView가_map이고_index가_처음을_가리킬_떄() { +// // Arrange +// let spy = PlaybackPresentationLogicSpy() +// sut.parentView = .map +// sut.posts = [Seeds.Posts.post1, Seeds.Posts.post2] +// sut.previousCell = Seeds.PlaybackVideo.previousCell +// let request: Models.DisplayPlaybackVideo.Request = Models.DisplayPlaybackVideo.Request(indexPathRow: 1, currentCell: Seeds.PlaybackVideo.currentCell) +// sut.presenter = spy +// // act +// sut.playVideo(with: request) +// +// // Assert +// XCTAssertTrue(spy.presentTeleportCellDidCalled, "playVideo는 presentTeleportCell를 호출하지 않았습니다") +// XCTAssertEqual(spy.presentTeleportCellResponse.previousCell, Seeds.PlaybackVideo.previousCell) +// XCTAssertEqual(spy.presentTeleportCellResponse.currentCell, nil) +// XCTAssertEqual(spy.presentTeleportCellResponse.indexPathRow, 0) +// XCTAssertTrue(((sut.isTeleport) != nil)) +// } + + func test_playVideo를_호출하면_presentMoveCellNext를_호출한다_parentView가_map이고_텔레포트가_필요없는_상황일_때() { + // Arrange + let spy = PlaybackPresentationLogicSpy() + sut.parentView = .map + sut.previousCell = Seeds.PlaybackVideo.previousCell + sut.posts = [Seeds.Posts.post1, Seeds.Posts.post2, Seeds.Posts.thumbnailImageNilPost] + sut.previousCell = Seeds.PlaybackVideo.previousCell + let request: Models.DisplayPlaybackVideo.Request = Models.DisplayPlaybackVideo.Request(indexPathRow: 1, currentCell: Seeds.PlaybackVideo.currentCell) + sut.presenter = spy + + // act + sut.playVideo(with: request) + + // Assert + XCTAssertTrue(spy.presentMoveCellNextDidCalled, "playVideo는 presentMoveCellNext를 호출하지 않았습니다") + XCTAssertEqual(sut.previousCell, Seeds.PlaybackVideo.currentCell) + XCTAssertEqual(spy.presentMoveCellNextResponse.previousCell, Seeds.PlaybackVideo.previousCell) + XCTAssertEqual(spy.presentMoveCellNextResponse.currentCell, Seeds.PlaybackVideo.currentCell) + XCTAssertEqual(spy.presentMoveCellNextResponse.indexPathRow, nil) + if let isTeleport = sut.isTeleport { + XCTAssertFalse(isTeleport) + } else { + XCTFail() + } + } + + func test_playTeleportVideo를_호출하면_presentMoveCellNext를_호출한다_무한스크롤상황일_때() { + // Arrange + let spy = PlaybackPresentationLogicSpy() + sut.posts = [Seeds.Posts.post1, Seeds.Posts.post2, Seeds.Posts.thumbnailImageNilPost] + sut.isTeleport = true + sut.previousCell = Seeds.PlaybackVideo.previousCell + let request: Models.DisplayPlaybackVideo.Request = Models.DisplayPlaybackVideo.Request(indexPathRow: 1, currentCell: Seeds.PlaybackVideo.currentCell) + sut.presenter = spy + + // act + sut.playTeleportVideo(with: request) + + // Assert + XCTAssertTrue(spy.presentMoveCellNextDidCalled, "playTeleportvideo는 presentMoveCellNext를 호출하지 않았습니다") + XCTAssertEqual(spy.presentMoveCellNextResponse.previousCell, Seeds.PlaybackVideo.previousCell) + XCTAssertEqual(spy.presentMoveCellNextResponse.currentCell, Seeds.PlaybackVideo.currentCell) + XCTAssertEqual(sut.previousCell, Seeds.PlaybackVideo.currentCell) + if let isTeleport = sut.isTeleport { + XCTAssertFalse(isTeleport) + } else { + XCTFail() + } + } + + func test_playTeleportVideo를_호출하면_presentMoveCellNext를_호출한다_셀이_삭제되는_상황일_때() { + // Arrange + let spy = PlaybackPresentationLogicSpy() + sut.posts = [Seeds.Posts.post1, Seeds.Posts.post2, Seeds.Posts.thumbnailImageNilPost] + sut.isTeleport = true + sut.previousCell = Seeds.PlaybackVideo.previousCell + let request: Models.DisplayPlaybackVideo.Request = Models.DisplayPlaybackVideo.Request(indexPathRow: 1, currentCell: Seeds.PlaybackVideo.currentCell) + sut.presenter = spy + // act + sut.playTeleportVideo(with: request) + + // Assert + XCTAssertTrue(spy.presentMoveCellNextDidCalled, "playTeleportvideo는 presentMoveCellNext를 호출하지 않았습니다") + XCTAssertEqual(spy.presentMoveCellNextResponse.previousCell, Seeds.PlaybackVideo.previousCell) + XCTAssertEqual(spy.presentMoveCellNextResponse.currentCell, Seeds.PlaybackVideo.currentCell) + XCTAssertEqual(sut.previousCell, Seeds.PlaybackVideo.currentCell) + XCTAssertFalse(((sut.isDelete) != nil)) + } + + func test_resumePlaybackView를_호출할때_previousCell이_존재하면_presentPlayInitialPlaybackCell을_호출한다() { + // Arrange + let spy = PlaybackPresentationLogicSpy() + sut.previousCell = Seeds.PlaybackVideo.previousCell + sut.presenter = spy + + // act + sut.resumePlaybackView() + + // Assert + XCTAssertTrue(spy.presentPlayInitialPlaybackCellDidCalled, "resumPlaybackView가 presentPlayInitialPlaybackCell을 호출하지 않았습니다") + XCTAssertEqual(spy.presentPlayInitialPlaybackCellResponse.currentCell, Seeds.PlaybackVideo.previousCell) + XCTAssertEqual(spy.presentPlayInitialPlaybackCellResponse.previousCell, nil) + } + + func test_resumePlaybackView를_호출할때_previousCell이_존재하면_presentSetInitialPlaybackCell을_호출한다() { + // Arrange + let spy = PlaybackPresentationLogicSpy() + sut.index = 2 + sut.presenter = spy + + // act + sut.resumePlaybackView() + + // Assert + XCTAssertTrue(spy.presentSetInitialPlaybackCellDidCalled, "resumPlaybackView가 presentSetInitialPlaybackCell을 호출하지 않았습니다") + XCTAssertEqual(spy.presentSetInitialPlaybackCellResponse.indexPathRow, 2) + } + + func test_leavePlaybackView를_호출할때_presentLeavePlaybackView를_호출한다() { + // Arrange + let spy = PlaybackPresentationLogicSpy() + sut.previousCell = Seeds.PlaybackVideo.previousCell + sut.presenter = spy + // act + sut.leavePlaybackView() + + // Assert + XCTAssertTrue(spy.presentLeavePlaybackViewDidCalled, "leavePlaybackView가 presentLeavePlaybackView를 호출하지 않았습니다") + XCTAssertEqual(spy.presentLeavePlaybackViewResponse.previousCell, Seeds.PlaybackVideo.previousCell) + } + + func test_resetVideo를_호출할때_presentResetPlaybackCell을_호출한다() { + // Arrange + let spy = PlaybackPresentationLogicSpy() + sut.previousCell = Seeds.PlaybackVideo.previousCell + sut.presenter = spy + // act + sut.resetVideo() + + // Assert + XCTAssertTrue(spy.presentResetPlaybackCellDidCalled, "resetVideo가 presentResetPlaybackCell을 호출하지 않았습니다") + XCTAssertEqual(spy.presentResetPlaybackCellResponse.previousCell, nil) + XCTAssertEqual(spy.presentResetPlaybackCellResponse.currentCell, Seeds.PlaybackVideo.previousCell) + } + + func test_careVideoLoading을_호출할때_presentMoveCellNext를_호출하지않는다_previousCell이_존재할때() { + // Arrange + let spy = PlaybackPresentationLogicSpy() + sut.previousCell = Seeds.PlaybackVideo.previousCell + let request: Models.DisplayPlaybackVideo.Request = Models.DisplayPlaybackVideo.Request(indexPathRow: nil, currentCell: nil) + // act + sut.careVideoLoading(with: request) + + // Assert + XCTAssertFalse(spy.presentMoveCellNextDidCalled, "careVideoLoading은 presentMoveCellNext를 호출하지 않았습니다") + } + + func test_careVideoLoading을_호출할때_presentMoveCellNext를_호출하지않는다_previousCell이_존재하지않을때() { + // Arrange + let spy = PlaybackPresentationLogicSpy() + sut.previousCell = nil + sut.presenter = spy + let request: Models.DisplayPlaybackVideo.Request = Models.DisplayPlaybackVideo.Request(indexPathRow: nil, currentCell: Seeds.PlaybackVideo.currentCell) + // act + sut.careVideoLoading(with: request) + + // Assert + XCTAssertTrue(spy.presentMoveCellNextDidCalled, "careVideoLoading은 presentMoveCellNext를 호출하지 않았습니다") + XCTAssertEqual(spy.presentMoveCellNextResponse.previousCell, nil) + XCTAssertEqual(spy.presentMoveCellNextResponse.currentCell, Seeds.PlaybackVideo.currentCell) + } + + func test_configurePlaybackCell을_호출할때_presentConfigureCell을_호출한다_map일때() { + // Arrange + let spy = PlaybackPresentationLogicSpy() + sut.posts = [Seeds.Posts.post1, Seeds.Posts.post2, Seeds.Posts.thumbnailImageNilPost] + sut.parentView = .map + sut.presenter = spy + + // act + sut.configurePlaybackCell() + + // Assert + XCTAssertTrue(spy.presentConfigureCellDidCalled, "configurePlaybackCell은 presentConfigureCell을 호출하지 않았습니다") + XCTAssertEqual(spy.presentConfigureCellResponse.teleportIndex, 4) + } + + func test_configurePlaybackCell을_호출할때_presentConfigureCell을_호출한다_map이_아닐때() { + // Arrange + let spy = PlaybackPresentationLogicSpy() + sut.posts = [Seeds.Posts.post1, Seeds.Posts.post2, Seeds.Posts.thumbnailImageNilPost] + sut.parentView = .home + sut.presenter = spy + + // act + sut.configurePlaybackCell() + + // Assert + XCTAssertTrue(spy.presentConfigureCellDidCalled, "configurePlaybackCell은 presentConfigureCell을 호출하지 않았습니다") + } + + func test_setSeemoreButton을_호출할때_presentSetSeemoreButton을_호출하고_올바른_데이터를_전달한다_본인일경우() { + // Arrange + let spy = PlaybackPresentationLogicSpy() + sut.previousCell = Seeds.PlaybackVideo.previousCell + sut.playbackVideoInfos = [Models.PlaybackInfo(memberID: -1, boardID: -1)] + sut.presenter = spy + + // act + sut.setSeeMoreButton(with: Models.SetSeemoreButton.Request(indexPathRow: 0)) + + // Assert + XCTAssertTrue(spy.presentSetSeemoreButtonDidCalled, "") + XCTAssertEqual(spy.presentSetSeemoreButtonResponse.buttonType, .delete) + } + + func test_본인이아닐경우_setSeemoreButton을_호출할때_presentSetSeemoreButton을_호출하고_올바른_데이터를_전달한다() { + // Arrange + let spy = PlaybackPresentationLogicSpy() + sut.previousCell = Seeds.PlaybackVideo.previousCell + sut.playbackVideoInfos = [Models.PlaybackInfo(memberID: 1, boardID: -1)] + sut.presenter = spy + + // act + sut.setSeeMoreButton(with: Models.SetSeemoreButton.Request(indexPathRow: 0)) + + // Assert + XCTAssertTrue(spy.presentSetSeemoreButtonDidCalled, "") + XCTAssertEqual(spy.presentSetSeemoreButtonResponse.buttonType, .report) + } + + func test_moveToProfile을_호출할때_presentProfile이_호출된다() { + // Arrange + let spy = PlaybackPresentationLogicSpy() + let request: Models.MoveToRelativeView.Request = Models.MoveToRelativeView.Request(indexPathRow: 0, selectedTag: "테스트") + sut.playbackVideoInfos = [Models.PlaybackInfo(memberID: 1, boardID: -1)] + sut.presenter = spy + + // act + sut.moveToProfile(with: request) + + // Assert + XCTAssertTrue(spy.presentProfileDidCalled, "moveToProfile이 presentProfileDidCalled를 호출하지 않았습니다") + XCTAssertEqual(sut.memberID, 1) + } + + func test_moveToTagPlay를_호출할때_presentTagPlay가_호출된다() { + // Arrange + let spy = PlaybackPresentationLogicSpy() + let request: Models.MoveToRelativeView.Request = Models.MoveToRelativeView.Request(indexPathRow: 0, selectedTag: "테스트") + sut.playbackVideoInfos = [Models.PlaybackInfo(memberID: 1, boardID: -1)] + sut.presenter = spy + + // act + sut.moveToTagPlay(with: request) + + // Assert + XCTAssertTrue(spy.presentTagPlayDidCalled, "moveToTagPlay이 presentTagPlay를 호출하지 않았습니다") + XCTAssertEqual(sut.selectedTag, "테스트") + } + +// func test_fetchPosts를_호출하면_presentLoadFetchVideosResponse를_호출한다_Home() async { +// // Arrange +// let spy = PlaybackPresentationLogicSpy() +// sut.parentView = .home +// sut.posts = [Seeds.Posts.post1, Seeds.Posts.post2] +// sut.presenter = spy +// sut.isFetchReqeust = false +// sut.currentPage = 1 +// +// // act +// let result = await sut.fetchPosts().value +// +// // Assert +// XCTAssertTrue(spy.presentLoadFetchVideosDidCalled, "fetchPosts가 presentLoadFetchVideos를 호출하지 않았습니다") +// XCTAssertTrue(result, "fetchPost에 실패했습니다.") +// XCTAssertEqual(spy.presentLoadFetchVideosResponse.videos.count, 1) +// XCTAssertEqual(sut.posts?.count, 3) +// } +// +// func test_fetchPosts를_호출하면_presentLoadFetchVideos를_호출한다_tag() async throws { +// // Arrange +// let spy = PlaybackPresentationLogicSpy() +// sut.parentView = .tag +// sut.posts = [Seeds.Posts.post1, Seeds.Posts.post2, Seeds.Posts.post1, Seeds.Posts.post2, Seeds.Posts.post1, Seeds.Posts.post2, Seeds.Posts.post1, Seeds.Posts.post2, Seeds.Posts.post1, Seeds.Posts.post2, Seeds.Posts.post1, Seeds.Posts.post2, Seeds.Posts.post1, Seeds.Posts.post2, Seeds.Posts.post1, Seeds.Posts.post2, Seeds.Posts.post1, Seeds.Posts.post2, Seeds.Posts.post1, Seeds.Posts.post2] +// sut.selectedTag = "테스트" +// sut.presenter = spy +// sut.isFetchReqeust = false +// sut.currentPage = 1 +// +// // act +// let result = await sut.fetchPosts().value +// try await Task.sleep(nanoseconds: 3_000_000_000) +// +// // Assert +// XCTAssertTrue(spy.presentLoadFetchVideosDidCalled, "fetchPosts가 presentLoadFetchVideos를 호출하지 않았습니다") +// XCTAssertTrue(result, "fetchPost에 실패했습니다.") +// XCTAssertEqual(spy.presentLoadFetchVideosResponse.videos.count, 1) +// XCTAssertEqual(sut.posts?.count, 21) +// } +// +// func test_fetchPosts를_호출하면_presentLoadFetchVideos를_호출한다_Profile() async throws { +// // Arrange +// let spy = PlaybackPresentationLogicSpy() +// sut.parentView = .otherProfile +// sut.posts = [Seeds.Posts.post1, Seeds.Posts.post2, Seeds.Posts.post1, Seeds.Posts.post2, Seeds.Posts.post1, Seeds.Posts.post2, Seeds.Posts.post1, Seeds.Posts.post2, Seeds.Posts.post1, Seeds.Posts.post2, Seeds.Posts.post1, Seeds.Posts.post2, Seeds.Posts.post1, Seeds.Posts.post2, Seeds.Posts.post1, Seeds.Posts.post2, Seeds.Posts.post1, Seeds.Posts.post2, Seeds.Posts.post1, Seeds.Posts.post2] +// sut.presenter = spy +// sut.memberID = -1 +// sut.isFetchReqeust = false +// sut.currentPage = 1 +// +// // act +// let result = await sut.fetchPosts().value +// +// // Assert +// XCTAssertTrue(spy.presentLoadFetchVideosDidCalled, "fetchPosts가 presentLoadFetchVideos를 호출하지 않았습니다") +// XCTAssertTrue(result, "fetchPost에 실패했습니다.") +// XCTAssertEqual(spy.presentLoadFetchVideosResponse.videos.count, 1) +// XCTAssertEqual(sut.posts?.count, 21) +// } +}