/
ReaderViewUITest.swift
136 lines (111 loc) · 5.23 KB
/
ReaderViewUITest.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
/* 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
class ReaderViewTest: BaseTestCase {
var navigator: Navigator!
var app: XCUIApplication!
override func setUp() {
super.setUp()
app = XCUIApplication()
navigator = createScreenGraph(app).navigator(self)
}
override func tearDown() {
super.tearDown()
}
func testLoadReaderContent() {
navigator.goto(BrowserTab)
app.buttons["Reader View"].tap()
// The settings of reader view are shown as well as the content of the web site
waitforExistence(app.buttons["Display Settings"])
XCTAssertTrue(app.webViews.staticTexts["The Book of Mozilla"].exists)
}
private func addContentToReaderView() {
navigator.goto(BrowserTab)
app.buttons["Reader View"].tap()
waitforExistence(app.buttons["Add to Reading List"])
app.buttons["Add to Reading List"].tap()
}
func testAddToReadingList() {
// Initially reading list is empty
navigator.goto(NewTabScreen)
waitforExistence(app.buttons["HomePanels.ReadingList"])
navigator.goto(HomePanel_ReadingList)
// Check the button is selected (is disabled and the rest bookmarks and so are enabled)
XCTAssertFalse(app.buttons["HomePanels.ReadingList"].isEnabled)
XCTAssertTrue(app.buttons["HomePanels.Bookmarks"].isEnabled)
let readingtableTable = app.tables["ReadingTable"]
waitforExistence(readingtableTable)
let list = app.tables["ReadingTable"].cells.count
XCTAssertEqual(list, 0, "There should not be any entry in the reading table")
navigator.nowAt(NewTabScreen)
// Add item to reading list and check that it appears
addContentToReaderView()
navigator.goto(NewTabScreen)
waitforExistence(app.buttons["HomePanels.ReadingList"])
navigator.goto(HomePanel_ReadingList)
// Check that there is one item
let savedToReadingList = app.tables["ReadingTable"].cells.staticTexts["The Book of Mozilla"]
XCTAssertTrue(savedToReadingList.exists)
waitforExistence(app.tables["ReadingTable"])
let listAfter = app.tables["ReadingTable"].cells.count
XCTAssertEqual(listAfter, 1, "There should not be any entry in the reading table")
}
func testMarkAsReadAndUreadFromReaderView() {
addContentToReaderView()
// Mark the content as read, so the mark as unread buttons appear
app.buttons["Mark as Read"].tap()
waitforExistence(app.buttons["Mark as Unread"])
// Mark the content as unread, so the mark as read button appear
app.buttons["Mark as Unread"].tap()
waitforExistence(app.buttons["Mark as Read"])
}
func testRemoveFromReadingView() {
addContentToReaderView()
// Once the content has been added, remove it
waitforExistence(app.buttons["Remove from Reading List"])
app.buttons["Remove from Reading List"].tap()
// Check that instead of the remove icon now it is shown the add to read list
waitforExistence(app.buttons["Add to Reading List"])
// Go to reader list view to check that there is not any item there
navigator.goto(NewTabScreen)
waitforExistence(app.buttons["HomePanels.ReadingList"])
navigator.goto(HomePanel_ReadingList)
let readingtableTable = app.tables["ReadingTable"]
waitforExistence(readingtableTable)
let list = app.tables["ReadingTable"].cells.count
XCTAssertEqual(list, 0, "There should not be any entry in the reading table")
}
func testMarkAsReadAndUnreadFromReadingList() {
addContentToReaderView()
navigator.goto(NewTabScreen)
waitforExistence(app.buttons["HomePanels.ReadingList"])
navigator.goto(HomePanel_ReadingList)
// Check that there is one item
let savedToReadingList = app.tables["ReadingTable"].cells.staticTexts["The Book of Mozilla"]
XCTAssertTrue(savedToReadingList.exists)
// Mark it as read/unread
savedToReadingList.swipeLeft()
waitforExistence(app.buttons["Mark as Read"])
app.buttons["Mark as Read"].tap()
savedToReadingList.swipeLeft()
waitforExistence(app.buttons["Mark as Unread"])
}
func testRemoveFromReadingList() {
addContentToReaderView()
navigator.goto(NewTabScreen)
waitforExistence(app.buttons["HomePanels.ReadingList"])
navigator.goto(HomePanel_ReadingList)
let savedToReadingList = app.tables["ReadingTable"].cells.staticTexts["The Book of Mozilla"]
savedToReadingList.swipeLeft()
waitforExistence(app.buttons["Remove"])
// Remove the item from reading list
app.buttons["Remove"].tap()
XCTAssertFalse(savedToReadingList.exists)
// Reader list view should be empty
let readingtableTable = app.tables["ReadingTable"]
waitforExistence(readingtableTable)
let list = app.tables["ReadingTable"].cells.count
XCTAssertEqual(list, 0, "There should not be any entry in the reading table")
}
}