Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

🔀 :: (#458) ArtistReactor Unit Test 작성 #466

Merged
merged 2 commits into from
Mar 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions Projects/Domains/ArtistDomain/Project.swift
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@ let project = Project.module(
.domain(target: .ArtistDomain, type: .interface)
]
),
.testing(
module: .domain(.ArtistDomain),
dependencies: [.domain(target: .ArtistDomain, type: .interface)]
),
.tests(
module: .domain(.ArtistDomain),
dependencies: [.domain(target: .ArtistDomain)]
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import ArtistDomainInterface
import Foundation
import RxSwift

public final class FetchArtistListUseCaseSpy: FetchArtistListUseCase {
public private(set) var callCount = 0
public var handler: (() -> Single<[ArtistListEntity]>) = { .never() }
public func execute() -> Single<[ArtistListEntity]> {
callCount += 1
return handler()
}
}
6 changes: 5 additions & 1 deletion Projects/Features/ArtistFeature/Project.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@ let project = Project.module(
.domain(target: .ArtistDomain, type: .interface)
]
)
)
),
.tests(module: .feature(.ArtistFeature), dependencies: [
.feature(target: .ArtistFeature),
.domain(target: .ArtistDomain, type: .testing)
])
]
)
95 changes: 95 additions & 0 deletions Projects/Features/ArtistFeature/Tests/ArtistReactorTests.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
import ArtistDomainInterface
@testable import ArtistDomainTesting
@testable import ArtistFeature
import XCTest

final class ArtistReactorTests: XCTestCase {
var fetchArtistListUseCase: FetchArtistListUseCaseSpy!
var sut: ArtistReactor!

override func setUp() {
super.setUp()
fetchArtistListUseCase = .init()
sut = ArtistReactor(fetchArtistListUseCase: fetchArtistListUseCase)
}

override func tearDown() {
super.tearDown()
fetchArtistListUseCase = nil
sut = nil
}

func test_when_viewDidLoad_action_and_artist_count_is_1_then_append_hidden_item() {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

확실히 많이 기네요 ㅎㅎ....
아니면 테스트 함수만큼은 한글 네이밍을 해보는 건 어떨까요?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

테스트에 필요하다고 생각하는 라이브러리들 고민한번 해주시고 다음 테스트 작성 때 저도 따라 가겠습니다.

// Given
let dummyArtistList = [makeTwoDummyArtistList().first!]
fetchArtistListUseCase.handler = {
return .just(dummyArtistList)
}

// When
sut.action.onNext(.viewDidLoad)

// Then
XCTAssertEqual(fetchArtistListUseCase.callCount, 1)
XCTAssertEqual(sut.currentState.artistList[0], dummyArtistList.first)
XCTAssertEqual(sut.currentState.artistList[1].artistId, "")
XCTAssertEqual(sut.currentState.artistList[1].isHiddenItem, true)
}

func test_when_viewDidLoad_action_and_artist_count_greater_than_2_then_swap_index_0_and_1() {
// Given
let dummyArtistList = makeTwoDummyArtistList()
fetchArtistListUseCase.handler = {
return .just(dummyArtistList)
}
let expectedArtistList = {
var list = dummyArtistList
list.swapAt(0, 1)
return list
}()

// When
sut.action.onNext(.viewDidLoad)

// Then
XCTAssertEqual(fetchArtistListUseCase.callCount, 1)
XCTAssertEqual(sut.currentState.artistList, expectedArtistList)
}

private func makeTwoDummyArtistList() -> [ArtistListEntity] {
[
ArtistListEntity(
artistId: "1",
name: "name",
short: "short",
group: "group",
title: "title",
description: "description",
color: [["ffffff"]],
youtube: "https://youtube.com",
twitch: "twitch",
instagram: "insta",
imageRoundVersion: 1,
imageSquareVersion: 1,
graduated: false,
isHiddenItem: false
),
ArtistListEntity(
artistId: "2",
name: "nam2",
short: "short2",
group: "group2",
title: "title2",
description: "description2",
color: [["ffffff"]],
youtube: "https://youtube.com",
twitch: "twitch",
instagram: "insta",
imageRoundVersion: 1,
imageSquareVersion: 1,
graduated: false,
isHiddenItem: false
)
]
}
}
15 changes: 0 additions & 15 deletions Projects/Features/ArtistFeature/Tests/TargetTests.swift

This file was deleted.

Loading