Skip to content

Commit cc4fad1

Browse files
authored
Reader: Code Removal (#23704)
* Remove ReaderSiteStreamHeader * Remove ReaderTabView * Remove ReaderNavigationButton * Remove ReaderNavigationMenu * Remove WPScrollableViewController (Objective-C) * Remove ReaderTabViewController * Remove ReaderTabViewModel * Remove ReaderTagCardCell * Remove ReaderTagCardEmptyCell * Remove ReaderTagFooterView * Remove ReaderTagCardCellViewModel * Remove ReaderTagCell * Remove ReaderTopicChangeObserver * Remove EmptyFilterView * Remove FilterSheetViewController * Remove FilterProvider * Remove TabbedViewController * Remove ReaderManageScenePresenter * Fix build * Fix build * Remove ReaderSpacerView * Remove ReaderTopicsCardCell * Fix build * Simplify ReaderMenuStore * Remove ReaderTabItem * Remove selfHostedFollowing contentType * Remove ReaderContentViewController * Remove ReaderContent * Fix build * Remove ReaderTracker * Integrate new menu in ReaderDetailsVC * Remove ReaderMenuAction * Remove ReaderShowMenuAction * Remove ReaderPostCardCell * Remove ReaderPostCardCellViewModel * Remove .serif FF * Remove .readerReset FF * Remove unused WPStyleGuide+Reader * Fix build * Fix build * Remove NetworkStatusReceiver * Remove unused reportStreamLoadFailure * Remove unused scrollViewTranslationPublisher * Remove shouldDisplayNoTopicController * Remove ReaderStreamError * Remove isSidebarModeEnabled * Extract ReaderSelectInterestsConfiguration * Remove ReaderStreamViewController from Storyboard * Remove unused code from ReaderHelpers * Remove unused code from ReaderPost+Display * Update UI tests * Remove duplicated actions from ReaderPostMenu * Reimplement actionButtonPressed * Load Reader lazily * Fix tests
1 parent 9dd2324 commit cc4fad1

File tree

93 files changed

+401
-7433
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

93 files changed

+401
-7433
lines changed

Modules/Sources/UITestsFoundation/Screens/Navigation/MainNavigationComponent.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import XCTest
33
import UIKit
44

55
public protocol MainNavigationComponent {
6-
func goToReaderScreen() throws -> ReaderScreen
6+
func goToReaderScreen() throws
77
func goToNotificationsScreen() throws -> NotificationsScreen
88
func goToMeScreen() throws -> MeTabScreen
99
}

Modules/Sources/UITestsFoundation/Screens/Navigation/SidebarNavComponent.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ public class SidebarNavComponent: ScreenObject, MainNavigationComponent {
1212
try openSidebar().openMeScreen()
1313
}
1414

15-
public func goToReaderScreen() throws -> ReaderScreen {
15+
public func goToReaderScreen() throws {
1616
try openSidebar().openReaderScreen()
1717
}
1818

Modules/Sources/UITestsFoundation/Screens/Navigation/SidebarScreen.swift

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,9 @@ public class SidebarScreen: ScreenObject {
1414
return try MeTabScreen()
1515
}
1616

17-
public func openReaderScreen() throws -> ReaderScreen {
17+
public func openReaderScreen() {
1818
app.staticTexts["sidebar_reader"].firstMatch.tap()
1919
app.swipeLeft() // Close the sidebar
20-
return try ReaderScreen()
2120
}
2221

2322
public func openNotificationsScreen() throws -> NotificationsScreen {

Modules/Sources/UITestsFoundation/Screens/Navigation/TabNavComponent.swift

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -54,10 +54,8 @@ public class TabNavComponent: ScreenObject, MainNavigationComponent {
5454
return try BlockEditorScreen()
5555
}
5656

57-
@discardableResult
58-
public func goToReaderScreen() throws -> ReaderScreen {
57+
public func goToReaderScreen() throws {
5958
readerTabButton.tap()
60-
return try ReaderScreen()
6159
}
6260

6361
public func goToNotificationsScreen() throws -> NotificationsScreen {
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
import ScreenObject
2+
import XCTest
3+
4+
public final class ReaderMenuScreen: ScreenObject {
5+
public init(app: XCUIApplication = XCUIApplication()) throws {
6+
try super.init {
7+
$0.collectionViews["reader_sidebar"].firstMatch
8+
}
9+
}
10+
11+
public enum ReaderStream: String {
12+
case recent
13+
case discover
14+
case saved
15+
case likes
16+
17+
func menuButton(_ app: XCUIApplication) -> XCUIElement {
18+
app.staticTexts["reader_sidebar_\(rawValue)"].firstMatch
19+
}
20+
}
21+
22+
@discardableResult
23+
public func open(_ stream: ReaderStream) throws -> ReaderScreen {
24+
stream.menuButton(app).tap()
25+
return try ReaderScreen()
26+
}
27+
}

Modules/Sources/UITestsFoundation/Screens/ReaderScreen.swift

Lines changed: 13 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ import ScreenObject
22
import XCTest
33

44
public class ReaderScreen: ScreenObject {
5-
var readerNavigationMenuButton: XCUIElement { app.buttons["reader-navigation-button"] }
65
var backButton: XCUIElement { app.buttons["Back"] }
76
var dismissButton: XCUIElement { app.buttons["Dismiss"] }
87
var firstPostLikeButton: XCUIElement { app.buttons["reader-like-button"].firstMatch }
@@ -13,8 +12,6 @@ public class ReaderScreen: ScreenObject {
1312
var noResultsView: XCUIElement { app.staticTexts["no-results-label-stack-view"].firstMatch }
1413
var readerButton: XCUIElement { app.buttons["Reader"] }
1514
var readerTable: XCUIElement { app.tables["reader_table_view"] }
16-
var moreButton: XCUIElement { app.buttons["More"] }
17-
var savePostButton: XCUIElement { app.buttons["Save"] }
1815
var savedButton: XCUIElement { app.buttons["Saved"] }
1916
var tagCellButton: XCUIElement { app.cells["topics-card-cell-button"] }
2017
var visitButton: XCUIElement { app.buttons["Visit"] }
@@ -32,13 +29,13 @@ public class ReaderScreen: ScreenObject {
3229
}
3330

3431
public func openLastPostInSafari() throws -> ReaderScreen {
35-
try getLastPost().buttons["More"].tap()
36-
visitButton.tap()
32+
try getLastPost().buttons["reader-more-button"].firstMatch.tap()
33+
app.buttons["reader-view-post-in-safari"].firstMatch.tap()
3734
return self
3835
}
3936

4037
public func openLastPostComments() throws -> CommentsScreen {
41-
let commentButton = try getLastPost().buttons["Comment"]
38+
let commentButton = try getLastPost().buttons["reader-comment-button"]
4239
guard commentButton.waitForIsHittable() else {
4340
throw UIElementNotFoundError(message: "ReaderScreen.Post: Comments button not loaded")
4441
}
@@ -109,24 +106,7 @@ public class ReaderScreen: ScreenObject {
109106

110107
// MARK: Stream switching actions
111108

112-
public enum ReaderStream: String {
113-
case discover
114-
case subscriptions
115-
case saved
116-
case liked
117-
118-
var buttonIdentifier: String {
119-
"Reader Navigation Menu Item, \(rawValue.capitalized)"
120-
}
121-
122-
func menuButton(_ app: XCUIApplication) -> XCUIElement {
123-
if XCTestCase.isPad {
124-
return app.staticTexts["reader_sidebar_\(rawValue)"].firstMatch
125-
} else {
126-
return app.buttons[buttonIdentifier].firstMatch
127-
}
128-
}
129-
}
109+
public typealias ReaderStream = ReaderMenuScreen.ReaderStream
130110

131111
private func openNavigationMenu() {
132112
if XCTestCase.isPad {
@@ -135,7 +115,7 @@ public class ReaderScreen: ScreenObject {
135115
app.buttons["ToggleSidebar"].tap()
136116
}
137117
} else {
138-
readerNavigationMenuButton.tap()
118+
app.navigationBars.firstMatch.buttons.element(boundBy: 0).tap()
139119
}
140120
}
141121

@@ -147,7 +127,7 @@ public class ReaderScreen: ScreenObject {
147127
}
148128
}
149129

150-
public func switchToStream(_ stream: ReaderStream) -> Self {
130+
public func switchToStream(_ stream: ReaderStream) throws -> Self {
151131
openNavigationMenu()
152132
stream.menuButton(app).tap()
153133
closeNavigationMenu()
@@ -173,9 +153,9 @@ public class ReaderScreen: ScreenObject {
173153

174154
public func saveFirstPost() throws -> (ReaderScreen, String) {
175155
XCTAssertTrue(readerTable.isHittable)
176-
let postLabel = readerTable.cells.firstMatch.label
177-
moreButton.firstMatch.tap()
178-
savePostButton.firstMatch.tap()
156+
let cell = readerTable.cells.firstMatch
157+
let postLabel = cell.label
158+
cell.buttons["reader-bookmark-button"].firstMatch.tap()
179159

180160
// An alert about saved post is displayed the first time a post is saved
181161
if let alert = try? FancyAlertComponent() {
@@ -197,11 +177,9 @@ public class ReaderScreen: ScreenObject {
197177
return self
198178
}
199179

200-
public func verifyPostLikedOnFollowingTab(file: StaticString = #file, line: UInt = #line) -> Self {
201-
XCTAssertTrue(readerTable.cells.firstMatch.waitForExistence(timeout: 3), file: file, line: line)
202-
XCTAssertGreaterThan(readerTable.cells.count, 1, .postNotGreaterThanOneError, file: file, line: line)
203-
XCTAssertTrue(firstPostLikeButton.label.hasPrefix(.postLiked), file: file, line: line)
204-
180+
public func verifyFirstPostLiked(file: StaticString = #file, line: UInt = #line) -> Self {
181+
let cell = readerTable.cells.firstMatch
182+
XCTAssertEqual(cell.buttons["reader-like-button"].staticTexts.firstMatch.label, "35")
205183
return self
206184
}
207185

@@ -221,7 +199,7 @@ public class ReaderScreen: ScreenObject {
221199
public func verifyLikedPosts(state: String, file: StaticString = #file, line: UInt = #line) -> Self {
222200
if state == .withPosts {
223201
verifyNotEmptyPostList()
224-
XCTAssertTrue(firstPostLikeButton.label.hasPrefix(.postLiked), file: file, line: line)
202+
_ = verifyFirstPostLiked()
225203
} else if state == .withoutPosts {
226204
verifyEmptyPostList()
227205
}
@@ -242,7 +220,6 @@ public class ReaderScreen: ScreenObject {
242220

243221
private extension String {
244222
static let emptyListLabel = "Empty list"
245-
static let postLiked = "Liked"
246223
static let postNotEqualOneError = "There should only be 1 post!"
247224
static let postNotEqualSavedPostError = "Post displayed does not match saved post!"
248225
static let postNotGreaterThanOneError = "There shouldn't only be 1 post!"

WordPress/Classes/Extensions/UINavigationController+Helpers.swift

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ extension UINavigationController {
44
@objc func scrollContentToTopAnimated(_ animated: Bool) {
55
guard viewControllers.count == 1 else { return }
66

7-
if let topViewController = topViewController as? WPScrollableViewController {
7+
if let topViewController = topViewController as? ScrollableViewController {
88
topViewController.scrollViewToTop()
99
} else if let scrollView = topViewController?.view as? UIScrollView {
1010
// If the view controller's view is a scrollview
@@ -40,3 +40,7 @@ extension UINavigationController {
4040
self.pushViewController(viewController, animated: animated)
4141
}
4242
}
43+
44+
protocol ScrollableViewController {
45+
func scrollViewToTop()
46+
}

WordPress/Classes/Extensions/UIPopoverPresentationController+PopoverAnchor.swift

Lines changed: 0 additions & 9 deletions
This file was deleted.

WordPress/Classes/System/ReaderPresenter.swift

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ final class ReaderPresenter: NSObject, SplitViewDisplayable {
1414
var secondary: UINavigationController
1515

1616
/// The navigation controller for the main content when shown using tabs.
17-
private let mainNavigationController = UINavigationController()
17+
private var mainNavigationController = UINavigationController()
1818
private var latestContentVC: UIViewController?
1919

2020
private var viewContext: NSManagedObjectContext {
@@ -37,11 +37,14 @@ final class ReaderPresenter: NSObject, SplitViewDisplayable {
3737

3838
// TODO: (reader) update to allow seamless transitions between split view and tabs
3939
@objc func prepareForTabBarPresentation() -> UINavigationController {
40+
sidebar.onViewDidLoad = { [weak self] in
41+
self?.showInitialSelection()
42+
}
4043
sidebarViewModel.isCompact = true
44+
sidebarViewModel.restoreSelection(defaultValue: nil)
4145
mainNavigationController.navigationBar.prefersLargeTitles = true
42-
mainNavigationController.viewControllers = [sidebar]
46+
mainNavigationController = UINavigationController(rootViewController: sidebar) // Loads sidebar lazily
4347
sidebar.navigationItem.backButtonDisplayMode = .minimal
44-
showInitialSelection()
4548
return mainNavigationController
4649
}
4750

WordPress/Classes/System/WordPress-Bridging-Header.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,6 @@
8888
#import "WPUploadStatusButton.h"
8989
#import "WPError.h"
9090
#import "WPImageViewController.h"
91-
#import "WPScrollableViewController.h"
9291
#import "WPStyleGuide+Pages.h"
9392
#import "WPStyleGuide+WebView.h"
9493
#import "WPTableViewHandler.h"

0 commit comments

Comments
 (0)