forked from brunophilipe/Mastonaut
-
Notifications
You must be signed in to change notification settings - Fork 0
/
NavigationStackTests.swift
133 lines (120 loc) · 3.99 KB
/
NavigationStackTests.swift
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
//
// NavigationStackTests.swift
// MastonautTests
//
// Created by Bruno Philipe on 06.10.19.
// Mastonaut - Mastodon Client for Mac
// Copyright © 2019 Bruno Philipe.
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
import XCTest
import CoreTootin
class NavigationStackTests: XCTestCase
{
private var navigationStack: NavigationStack<MockItem>!
override func setUp()
{
navigationStack = NavigationStack<MockItem>(currentItem: "1")
}
func testBasicSetup()
{
XCTAssertEqual(navigationStack.currentItem, "1")
}
func testPushingNewItems()
{
navigationStack.set(currentItem: "2")
XCTAssertEqual(navigationStack.currentItem, "2")
navigationStack.set(currentItem: "3")
XCTAssertEqual(navigationStack.currentItem, "3")
navigationStack.set(currentItem: "4")
XCTAssertEqual(navigationStack.currentItem, "4")
navigationStack.set(currentItem: "5")
XCTAssertEqual(navigationStack.currentItem, "5")
XCTAssertTrue(navigationStack.canGoBackward)
}
func testBackwardNavigation()
{
navigationStack.set(currentItem: "2")
navigationStack.set(currentItem: "3")
navigationStack.set(currentItem: "4")
navigationStack.set(currentItem: "5")
XCTAssertEqual(navigationStack.currentItem, "5")
XCTAssertEqual(navigationStack.goBack(), "4")
XCTAssertEqual(navigationStack.currentItem, "4")
XCTAssertEqual(navigationStack.goBack(), "3")
XCTAssertEqual(navigationStack.currentItem, "3")
XCTAssertEqual(navigationStack.goBack(), "2")
XCTAssertEqual(navigationStack.currentItem, "2")
XCTAssertEqual(navigationStack.goBack(), "1")
XCTAssertEqual(navigationStack.currentItem, "1")
XCTAssertFalse(navigationStack.canGoBackward)
}
func testForwardNavigation()
{
navigationStack.set(currentItem: "2")
navigationStack.set(currentItem: "3")
navigationStack.set(currentItem: "4")
navigationStack.set(currentItem: "5")
_ = navigationStack.goBack()
_ = navigationStack.goBack()
_ = navigationStack.goBack()
_ = navigationStack.goBack()
XCTAssertTrue(navigationStack.canGoForward)
XCTAssertEqual(navigationStack.goForward(), "2")
XCTAssertEqual(navigationStack.currentItem, "2")
XCTAssertEqual(navigationStack.goForward(), "3")
XCTAssertEqual(navigationStack.currentItem, "3")
XCTAssertEqual(navigationStack.goForward(), "4")
XCTAssertEqual(navigationStack.currentItem, "4")
XCTAssertEqual(navigationStack.goForward(), "5")
XCTAssertEqual(navigationStack.currentItem, "5")
}
func testForwardAndBackwardNavigation()
{
navigationStack.set(currentItem: "2")
navigationStack.set(currentItem: "3")
navigationStack.set(currentItem: "4")
navigationStack.set(currentItem: "5")
XCTAssertTrue(navigationStack.canGoBackward)
_ = navigationStack.goBack()
XCTAssertTrue(navigationStack.canGoForward)
navigationStack.set(currentItem: "4")
XCTAssertFalse(navigationStack.canGoForward)
navigationStack.set(currentItem: "6")
XCTAssertFalse(navigationStack.canGoForward)
XCTAssertTrue(navigationStack.canGoBackward)
_ = navigationStack.goBack()
XCTAssertTrue(navigationStack.canGoForward)
XCTAssertEqual(navigationStack.currentItem, "4")
_ = navigationStack.goForward()
XCTAssertFalse(navigationStack.canGoForward)
XCTAssertEqual(navigationStack.currentItem, "6")
}
}
private struct MockItem: RawRepresentable, ExpressibleByStringLiteral, Equatable
{
typealias RawValue = String
typealias StringLiteralType = String
let value: String
var rawValue: String
{
return value
}
init?(rawValue: Self.RawValue)
{
self.value = rawValue
}
init(stringLiteral value: Self.StringLiteralType)
{
self.value = value
}
}