Skip to content

Commit

Permalink
Update tests
Browse files Browse the repository at this point in the history
  • Loading branch information
kantacky committed Feb 20, 2024
1 parent ed1ae2e commit 4ad88fc
Showing 1 changed file with 58 additions and 16 deletions.
74 changes: 58 additions & 16 deletions YumemiTrainingTests/ForecastViewModelTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,12 @@
//

import XCTest
import Dependencies
@testable import YumemiTraining

@MainActor
final class ForecastViewModelTests: XCTestCase {

let viewModel: any ForecastViewModel = ForecastViewModelMock()

override func setUpWithError() throws {
try super.setUpWithError()
}
Expand All @@ -21,23 +20,66 @@ final class ForecastViewModelTests: XCTestCase {
try super.tearDownWithError()
}

func testReload() {
let expectedWeatherSunny: Weather = .sunny
let expectedWeatherCloudy: Weather = .cloudy
let expectedWeatherRainy: Weather = .rainy
func testReloadSunny() {
let now: Date = .now
let expected: Weather = .init(date: now, weatherCondition: .sunny, maxTemperature: 20, minTemperature: 0)

let viewModel: ForecastViewModel = withDependencies {
$0.date.now = now
$0.yumemiWeatherClient = .init(
fetchWeatherCondition: unimplemented(),
fetchThrowingWeatherCondition: unimplemented(),
fetchThrowingWeather: { _, date in
.init(date: date, weatherCondition: .sunny, maxTemperature: 20, minTemperature: 0)
}
)
} operation: {
.init()
}

viewModel.reload()
XCTAssertEqual(viewModel.weather, expected)
}

self.viewModel.reload()
XCTAssertEqual(self.viewModel.errorMessage, "There was an error fetching the weather.")
XCTAssertEqual(self.viewModel.weather, expectedWeatherSunny)
func testReloadCloudy() {
let now: Date = .now
let expected: Weather = .init(date: now, weatherCondition: .cloudy, maxTemperature: 15, minTemperature: -5)

let viewModel: ForecastViewModel = withDependencies {
$0.date.now = now
$0.yumemiWeatherClient = .init(
fetchWeatherCondition: unimplemented(),
fetchThrowingWeatherCondition: unimplemented(),
fetchThrowingWeather: { _, date in
.init(date: date, weatherCondition: .cloudy, maxTemperature: 15, minTemperature: -5)
}
)
} operation: {
.init()
}

viewModel.reload()
XCTAssertEqual(viewModel.weather, expected)
}

self.viewModel.dismissAlert()
XCTAssertEqual(self.viewModel.errorMessage, nil)
XCTAssertEqual(self.viewModel.weather, expectedWeatherCloudy)
func testReloadRainy() {
let now: Date = .now
let expected: Weather = .init(date: now, weatherCondition: .rainy, maxTemperature: 10, minTemperature: -10)

self.viewModel.reload()
XCTAssertEqual(self.viewModel.weather, expectedWeatherRainy)
let viewModel: ForecastViewModel = withDependencies {
$0.date.now = now
$0.yumemiWeatherClient = .init(
fetchWeatherCondition: unimplemented(),
fetchThrowingWeatherCondition: unimplemented(),
fetchThrowingWeather: { _, date in
.init(date: date, weatherCondition: .rainy, maxTemperature: 10, minTemperature: -10)
}
)
} operation: {
.init()
}

self.viewModel.reload()
XCTAssertEqual(self.viewModel.weather, expectedWeatherSunny)
viewModel.reload()
XCTAssertEqual(viewModel.weather, expected)
}
}

0 comments on commit 4ad88fc

Please sign in to comment.