forked from mozilla-mobile/firefox-ios
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathLibraryPanelViewStateTests.swift
165 lines (124 loc) · 7.96 KB
/
LibraryPanelViewStateTests.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
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
import XCTest
@testable import Client
class LibraryPanelViewStateTests: XCTestCase {
var panelState: LibraryPanelViewState?
override func setUp() {
panelState = LibraryPanelViewState()
}
override func tearDown() {
panelState = nil
}
//MARK: - Single panel interaction tests
func testStateMachineInitializesWithProperState() {
let actualState = panelState?.currentState
let expectedState: LibraryPanelMainState = .bookmarks(state: .mainView)
XCTAssertEqual(actualState, expectedState, "The library panel view is not initializing correctly.")
}
func testStateChangingToSameState() {
panelState?.currentState = .bookmarks(state: .mainView)
let actualState = panelState?.currentState
let expectedState: LibraryPanelMainState = .bookmarks(state: .mainView)
XCTAssertEqual(actualState, expectedState, "The library panel view changing from one state to the same state is not working!")
}
func testStateOnBookmarkPanelGoesIntoFolderState() {
panelState?.currentState = .bookmarks(state: .inFolder)
let actualState = panelState?.currentState
let expectedState: LibraryPanelMainState = .bookmarks(state: .inFolder)
XCTAssertEqual(actualState, expectedState, "The library panel view did not correctly enter the .inFolder state for bookmarks")
}
func testStateOnBookmarkPanelGoesIntoEditFolderState() {
panelState?.currentState = .bookmarks(state: .inFolder)
panelState?.currentState = .bookmarks(state: .inFolderEditMode)
let actualState = panelState?.currentState
let expectedState: LibraryPanelMainState = .bookmarks(state: .inFolderEditMode)
XCTAssertEqual(actualState, expectedState, "The library panel view did not correctly enter the .inFolderEditMode state for bookmarks")
}
func testStateOnBookmarkPanelGoesIntoItemEditState() {
panelState?.currentState = .bookmarks(state: .inFolder)
panelState?.currentState = .bookmarks(state: .inFolderEditMode)
panelState?.currentState = .bookmarks(state: .itemEditMode)
let actualState = panelState?.currentState
let expectedState: LibraryPanelMainState = .bookmarks(state: .itemEditMode)
XCTAssertEqual(actualState, expectedState, "The library panel view did not correctly enter the .inFolderEditMode state for bookmarks")
}
func testStateOnBookmarkPanelGoesBackToFolderEditModeFromItemEditState() {
panelState?.currentState = .bookmarks(state: .inFolder)
panelState?.currentState = .bookmarks(state: .inFolderEditMode)
panelState?.currentState = .bookmarks(state: .itemEditMode)
panelState?.currentState = .bookmarks(state: .inFolderEditMode)
let actualState = panelState?.currentState
let expectedState: LibraryPanelMainState = .bookmarks(state: .inFolderEditMode)
XCTAssertEqual(actualState, expectedState, "The library panel view did not correctly enter the .inFolderEditMode state for bookmarks from the .itemEditMode state")
}
func testStateOnBookmarkPanelFollowStateProgressionMovingIntoStates() {
panelState?.currentState = .bookmarks(state: .inFolderEditMode)
var actualState = panelState?.currentState
var wrongState: LibraryPanelMainState = .bookmarks(state: .inFolderEditMode)
let expectedState: LibraryPanelMainState = .bookmarks(state: .mainView)
XCTAssertEqual(actualState, expectedState, "The library panel view did not correctly enter the .inFolderEditMode state for bookmarks")
XCTAssertNotEqual(actualState, wrongState, "Attempting to move to the wrong state did not fail!")
panelState?.currentState = .bookmarks(state: .itemEditMode)
actualState = panelState?.currentState
wrongState = .bookmarks(state: .itemEditMode)
XCTAssertEqual(actualState, expectedState, "The library panel view did not correctly enter the .inFolderEditMode state for bookmarks")
XCTAssertNotEqual(actualState, wrongState, "Attempting to move to the wrong state did not fail!")
}
func testStateOnBookmarkPanelFollowsStateProgressionMovingOutOfStates() {
// Go to last state
panelState?.currentState = .bookmarks(state: .inFolder)
panelState?.currentState = .bookmarks(state: .inFolderEditMode)
panelState?.currentState = .bookmarks(state: .itemEditMode)
// attempt to climb backwards
panelState?.currentState = .bookmarks(state: .inFolder)
var actualState = panelState?.currentState
var wrongState: LibraryPanelMainState = .bookmarks(state: .inFolder)
let expectedState: LibraryPanelMainState = .bookmarks(state: .itemEditMode)
XCTAssertEqual(actualState, expectedState, "The library panel view did not correctly enter the .inFolderEditMode state for bookmarks")
XCTAssertNotEqual(actualState, wrongState, "Attempting to move to the wrong state did not fail!")
panelState?.currentState = .bookmarks(state: .mainView)
actualState = panelState?.currentState
wrongState = .bookmarks(state: .mainView)
XCTAssertEqual(actualState, expectedState, "The library panel view did not correctly enter the .inFolderEditMode state for bookmarks")
XCTAssertNotEqual(actualState, wrongState, "Attempting to move to the wrong state did not fail!")
}
// MARK: - Multi-panel tests
func testStateForBookmarkMainViewToOtherPanelMainView() {
panelState?.currentState = .history(state: .mainView)
let actualState = panelState?.currentState
let expectedState: LibraryPanelMainState = .history(state: .mainView)
XCTAssertEqual(actualState, expectedState, "The library panel view did not correctly enter the .history(.mainView) state for the History Panel")
}
func testStateForBookmarkMainViewToOtherPanelMainViewAndBack() {
panelState?.currentState = .history(state: .mainView)
panelState?.currentState = .bookmarks(state: .mainView)
let actualState = panelState?.currentState
let expectedState: LibraryPanelMainState = .bookmarks(state: .mainView)
XCTAssertEqual(actualState, expectedState, "The library panel view did not correctly return to the .bookmarks(.mainView) state")
}
func testBookmarkViewInFolderModeSwitchingToOtherPanelAndReturningToCorrectBookmarksState() {
panelState?.currentState = .bookmarks(state: .inFolder)
panelState?.currentState = .history(state: .mainView)
panelState?.currentState = .bookmarks(state: .mainView)
let actualState = panelState?.currentState
let expectedState: LibraryPanelMainState = .bookmarks(state: .inFolder)
XCTAssertEqual(actualState, expectedState, "The library panel view did not correctly return to the .bookmarks(.inFolder) state")
}
func testChangingDifferentPanelsAndSavingStates() {
panelState?.currentState = .bookmarks(state: .inFolder)
panelState?.currentState = .bookmarks(state: .inFolderEditMode)
panelState?.currentState = .history(state: .mainView)
panelState?.currentState = .history(state: .inFolder)
panelState?.currentState = .downloads
panelState?.currentState = .bookmarks(state: .mainView)
var actualState = panelState?.currentState
var expectedState: LibraryPanelMainState = .bookmarks(state: .inFolderEditMode)
XCTAssertEqual(actualState, expectedState, "The library panel view did not correctly return to the .bookmarks(.inFolderEditMode) state")
panelState?.currentState = .history(state: .mainView)
actualState = panelState?.currentState
expectedState = .history(state: .inFolder)
XCTAssertEqual(actualState, expectedState, "The library panel view did not correctly return to the .history(.inFolder) state")
}
}