-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Test: Add TimeTableViewModel unit tests and fake trip response builder (
#514) ### TL;DR Added test coverage for TimeTableViewModel and implemented a fake trip response builder ### What changed? - Created `FakeTripResponseBuilder` to generate test data for trip responses - Added success/failure toggle to `FakeTripPlanningService` - Implemented unit tests for TimeTableViewModel covering: - Initial state verification - Success response handling - Error response handling - Added `@VisibleForTesting` annotation to `fetchTrip()` method - Added debug logging statements in TimeTableViewModel ### How to test? 1. Run the TimeTableViewModel test suite 2. Verify tests pass for: - Initial state observation - Loading time table with successful API response - Loading time table with error API response ### Why make this change? To improve test coverage and ensure proper handling of both successful and failed trip planning scenarios in the TimeTableViewModel. The addition of the FakeTripResponseBuilder provides consistent test data and makes tests more maintainable.
- Loading branch information
1 parent
f382e4e
commit e1beff2
Showing
4 changed files
with
222 additions
and
6 deletions.
There are no files selected for viewing
28 changes: 26 additions & 2 deletions
28
core/test/src/commonTest/kotlin/xyz/ksharma/core/test/fakes/FakeTripPlanningService.kt
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
45 changes: 45 additions & 0 deletions
45
core/test/src/commonTest/kotlin/xyz/ksharma/core/test/fakes/FakeTripResponseBuilder.kt
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,45 @@ | ||
package xyz.ksharma.core.test.fakes | ||
|
||
import xyz.ksharma.krail.trip.planner.network.api.model.StopType | ||
import xyz.ksharma.krail.trip.planner.network.api.model.TripResponse | ||
import xyz.ksharma.krail.trip.planner.network.api.model.TripResponse.StopSequence | ||
|
||
object FakeTripResponseBuilder { | ||
|
||
fun buildOriginStopSequence() = StopSequence( | ||
arrivalTimePlanned = "2024-09-24T19:00:00Z", | ||
arrivalTimeEstimated = "2024-09-24T19:10:00Z", | ||
departureTimePlanned = "2024-09-24T19:10:00Z", | ||
departureTimeEstimated = "2024-09-24T19:10:00Z", | ||
name = "Origin Stop", | ||
disassembledName = "Origin Name", | ||
id = "Origin_stop_id", | ||
type = StopType.STOP.type, | ||
) | ||
|
||
fun buildDestinationStopSequence() = StopSequence( | ||
arrivalTimePlanned = "2024-09-24T20:00:00Z", | ||
arrivalTimeEstimated = "2024-09-24T20:10:00Z", | ||
departureTimePlanned = "2024-09-24T20:10:00Z", | ||
departureTimeEstimated = "2024-09-24T20:10:00Z", | ||
name = "Destination Stop", | ||
disassembledName = "Destination Name", | ||
id = "Destination_stop_id", | ||
type = StopType.STOP.type, | ||
) | ||
|
||
fun buildTransportation() = TripResponse.Transportation( | ||
disassembledName = "Transportation Name", | ||
product = TripResponse.Product( | ||
productClass = 1, | ||
name = "Train", | ||
), | ||
destination = TripResponse.OperatorClass( | ||
name = "Destination Operator", | ||
id = "Destination Operator Id", | ||
), | ||
name = "Transportation Name", | ||
id = "Transportation Id", | ||
description = "Transportation Description", | ||
) | ||
} |
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
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