Skip to content

Commit

Permalink
Adds tests for RoutableCollection utilities
Browse files Browse the repository at this point in the history
  • Loading branch information
johnpatrickmorgan committed Sep 30, 2022
1 parent c4f332f commit 8d1bc57
Show file tree
Hide file tree
Showing 2 changed files with 78 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
@testable import FlowStacks
import XCTest

final class FlowStacksTests: XCTestCase {
final class CalculateStepsTests: XCTestCase {
typealias RouterState = [Route<Int>]

func testPushOneAtATime() {
Expand Down
77 changes: 77 additions & 0 deletions Tests/FlowStacksTests/RoutableCollectionTests.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
@testable import FlowStacks
import XCTest

final class RoutableCollectionTests: XCTestCase {
typealias RouterState = [Route<Int>]

func testPopToCurrentNavigationRootPresented() {
var routes: RouterState = [
.root(1, embedInNavigationView: true),
.sheet(-1, embedInNavigationView: true),
.push(-2),
.push(-3),
.push(-4)
]

routes.popToCurrentNavigationRoot()

let expectedResult: RouterState = [
.root(1, embedInNavigationView: true),
.sheet(-1, embedInNavigationView: true)
]
XCTAssertEqual(routes, expectedResult)
}

func testPopToCurrentNavigationRootNotPresented() {
var routes: RouterState = [
.root(1, embedInNavigationView: true),
.push(-2),
.push(-3),
.push(-4)
]

routes.popToCurrentNavigationRoot()

let expectedResult: RouterState = [
.root(1, embedInNavigationView: true),
]
XCTAssertEqual(routes, expectedResult)
}

func testDismissAll() {
var routes: RouterState = [
.root(1, embedInNavigationView: true),
.push(-2),
.sheet(3, embedInNavigationView: true),
.sheet(4, embedInNavigationView: true),
.sheet(5, embedInNavigationView: true),
.sheet(6, embedInNavigationView: true),
.push(-4)
]

routes.dismissAll()

let expectedResult: RouterState = [
.root(1, embedInNavigationView: true),
.push(-2),
]
XCTAssertEqual(routes, expectedResult)
}

func testDismissAllNoOpWithOnlyPushes() {
var routes: RouterState = [
.root(1, embedInNavigationView: true),
.push(2),
.push(3)
]

routes.dismissAll()

let expectedResult: RouterState = [
.root(1, embedInNavigationView: true),
.push(2),
.push(3)
]
XCTAssertEqual(routes, expectedResult)
}
}

0 comments on commit 8d1bc57

Please sign in to comment.