-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'dev' into Test/MountainList-UnitTest
- Loading branch information
Showing
4 changed files
with
454 additions
and
0 deletions.
There are no files selected for viewing
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 |
---|---|---|
@@ -0,0 +1,74 @@ | ||
// | ||
// MapSceneTests.swift | ||
// MapSceneTests | ||
// | ||
// Created by shin jae ung on 2021/11/29. | ||
// | ||
|
||
import XCTest | ||
import Combine | ||
|
||
class MapSceneTests: XCTestCase { | ||
var viewModel: MapViewModel! | ||
var useCase: MapViewUseCase! | ||
var expectation: XCTestExpectation! | ||
var observers: [AnyCancellable] = [] | ||
|
||
class MockRepository: MapViewRepository { | ||
func fetchMountains(completion: @escaping (Result<[MountainEntity], Error>) -> Void) { | ||
let mountainDetail = MountainEntity.MountainDetail( | ||
mountainName: "Name", | ||
mountainRegion: "Region", | ||
mountainHeight: "100", | ||
mountainShortDescription: "Description" | ||
) | ||
let mountainEntity = MountainEntity(id: UUID(), mountain: mountainDetail, latitude: 37.3591, longitude: 127.1051) | ||
let mountainEntities = [mountainEntity] | ||
completion(.success(mountainEntities)) | ||
} | ||
|
||
func fetchMapOption(key: Settings, completion: @escaping (Result<Map, Error>) -> Void) { | ||
completion(.success(Map.infomation)) | ||
} | ||
} | ||
|
||
override func setUp() { | ||
super.setUp() | ||
self.useCase = MapViewUseCase(repository: MockRepository()) | ||
self.viewModel = MapViewModel(useCase: self.useCase) | ||
self.expectation = XCTestExpectation(description: "expectation") | ||
} | ||
|
||
override func tearDown() { | ||
self.viewModel = nil | ||
self.useCase = nil | ||
self.expectation = nil | ||
super.tearDown() | ||
} | ||
|
||
func test_ViewModel_configureBindings호출시_MountainEntity를_저장함() { | ||
self.viewModel.$mountains | ||
.dropFirst() | ||
.sink(receiveValue: { [weak self] mountains in | ||
XCTAssertNotNil(mountains, "reposiroty로 부터 [MountainEntity]가 nil로 반환됨") | ||
XCTAssertTrue(mountains!.count == 1) | ||
self?.expectation.fulfill() | ||
}) | ||
.store(in: &observers) | ||
self.viewModel.configureBindings() | ||
self.wait(for: [expectation], timeout: 1.0) | ||
} | ||
|
||
func test_ViewModel_viewWillAppear호출시_Map을_저장함() { | ||
self.viewModel.$map | ||
.dropFirst() | ||
.sink(receiveValue: { [weak self] map in | ||
XCTAssertNotNil(map, "reposiroty로 부터 Map이 nil로 반환됨") | ||
XCTAssertTrue(map == Map.infomation) | ||
self?.expectation.fulfill() | ||
}) | ||
.store(in: &observers) | ||
self.viewModel.viewWillAppear() | ||
self.wait(for: [expectation], timeout: 1.0) | ||
} | ||
} |
66 changes: 66 additions & 0 deletions
66
SanTa/MountainAddingSceneTests/MountainAddingSceneTests.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 |
---|---|---|
@@ -0,0 +1,66 @@ | ||
// | ||
// MountainAddingSceneTests.swift | ||
// MountainAddingSceneTests | ||
// | ||
// Created by shin jae ung on 2021/11/30. | ||
// | ||
|
||
import XCTest | ||
import Combine | ||
import CoreLocation | ||
|
||
class MountainAddingSceneTests: XCTestCase { | ||
var viewModel: MountainAddingViewModel! | ||
var useCase: MountainAddingViewUseCase! | ||
var expectation: XCTestExpectation! | ||
var coordinate: CLLocationCoordinate2D! | ||
var altitude: CLLocationDistance! | ||
var observers: [AnyCancellable] = [] | ||
|
||
class MockRepository: MountainAddingRepository { | ||
func save(_ mountainEntity: MountainEntity, completion: @escaping (Result<Void, Error>) -> Void) { | ||
completion(.success(Void())) | ||
} | ||
} | ||
|
||
override func setUp() { | ||
super.setUp() | ||
self.useCase = MountainAddingViewUseCase(repository: MockRepository()) | ||
self.viewModel = MountainAddingViewModel(useCase: useCase) | ||
self.expectation = XCTestExpectation(description: "expectation") | ||
self.coordinate = CLLocationCoordinate2D(latitude: 0, longitude: 0) | ||
self.altitude = 0 | ||
} | ||
|
||
override func tearDown() { | ||
self.viewModel = nil | ||
self.useCase = nil | ||
self.expectation = nil | ||
super.tearDown() | ||
} | ||
|
||
func test_ViewModel_updateUserLocation_호출시_위치를_저장함() { | ||
self.viewModel.$coordinate | ||
.dropFirst() | ||
.sink(receiveValue: { [weak self] coordinate in | ||
XCTAssertNotNil(coordinate, "updateUserLocation에서 coordinate가 올바르게 저장되지 않음") | ||
self?.expectation.fulfill() | ||
}) | ||
.store(in: &observers) | ||
self.viewModel.updateUserLocation(coordinate: self.coordinate, altitude: self.altitude) | ||
self.wait(for: [expectation], timeout: 1.0) | ||
} | ||
|
||
func test_ViewModel_addMountain_호출시_산을_추가함() { | ||
self.viewModel.updateUserLocation(coordinate: self.coordinate, altitude: self.altitude) | ||
self.viewModel.addMountainResult | ||
.sink(receiveValue: { [weak self] result in | ||
XCTAssertNotNil(result, "repository로 부터 AddingMountainResult가 nil로 반환됨") | ||
XCTAssertEqual(result, .success, "산이 추가되지 않음") | ||
self?.expectation.fulfill() | ||
}) | ||
.store(in: &self.observers) | ||
self.viewModel.addMountain(title: "산", description: "설명") | ||
self.wait(for: [expectation], timeout: 1.0) | ||
} | ||
} |
Oops, something went wrong.