Skip to content

Commit

Permalink
Testing: Add publish tests using the block editor (#11696)
Browse files Browse the repository at this point in the history
* Add post publish UI tests for block editor
  • Loading branch information
rachelmcr committed May 21, 2019
1 parent 1340716 commit 41da008
Show file tree
Hide file tree
Showing 18 changed files with 359 additions and 157 deletions.
10 changes: 8 additions & 2 deletions WordPress/Classes/Utility/WPImmuTableRows.swift
Expand Up @@ -11,20 +11,23 @@ struct NavigationItemRow: ImmuTableRow {
let icon: UIImage?
let action: ImmuTableAction?
let accessoryType: UITableViewCell.AccessoryType
let accessibilityIdentifer: String?

init(title: String, detail: String? = nil, icon: UIImage? = nil, badgeCount: Int = 0, accessoryType: UITableViewCell.AccessoryType = .disclosureIndicator, action: @escaping ImmuTableAction) {
init(title: String, detail: String? = nil, icon: UIImage? = nil, badgeCount: Int = 0, accessoryType: UITableViewCell.AccessoryType = .disclosureIndicator, action: @escaping ImmuTableAction, accessibilityIdentifier: String? = nil) {
self.title = title
self.detail = detail
self.icon = icon
self.accessoryType = accessoryType
self.action = action
self.accessibilityIdentifer = accessibilityIdentifier
}

func configureCell(_ cell: UITableViewCell) {
cell.textLabel?.text = title
cell.detailTextLabel?.text = detail
cell.accessoryType = accessoryType
cell.imageView?.image = icon
cell.accessibilityIdentifier = accessibilityIdentifer

WPStyleGuide.configureTableViewCell(cell)
}
Expand Down Expand Up @@ -251,12 +254,14 @@ struct SwitchRow: ImmuTableRow {
let icon: UIImage?
let action: ImmuTableAction? = nil
let onChange: (Bool) -> Void
let accessibilityIdentifier: String?

init(title: String, value: Bool, icon: UIImage? = nil, onChange: @escaping (Bool) -> Void) {
init(title: String, value: Bool, icon: UIImage? = nil, onChange: @escaping (Bool) -> Void, accessibilityIdentifier: String? = nil) {
self.title = title
self.value = value
self.icon = icon
self.onChange = onChange
self.accessibilityIdentifier = accessibilityIdentifier
}

func configureCell(_ cell: UITableViewCell) {
Expand All @@ -267,6 +272,7 @@ struct SwitchRow: ImmuTableRow {
cell.selectionStyle = .none
cell.on = value
cell.onChange = onChange
cell.flipSwitch.accessibilityIdentifier = accessibilityIdentifier
}
}

Expand Down
Expand Up @@ -46,6 +46,8 @@ class AppSettingsViewController: UITableViewController {
WPStyleGuide.configureAutomaticHeightRows(for: tableView)

addAccountSettingsChangedObserver()

tableView.accessibilityIdentifier = "appSettingsTable"
}

override func viewWillAppear(_ animated: Bool) {
Expand Down Expand Up @@ -316,7 +318,8 @@ private extension AppSettingsViewController {
let gutenbergEditor = SwitchRow(
title: NSLocalizedString("Use Block Editor", comment: "Option to enable the block editor for new posts"),
value: enabled,
onChange: toggleGutenberg()
onChange: toggleGutenberg(),
accessibilityIdentifier: "useBlockEditorSwitch"
)

let headerText = NSLocalizedString("Editor", comment: "Title for the editor settings section")
Expand Down
12 changes: 8 additions & 4 deletions WordPress/Classes/ViewRelated/Me/MeViewController.swift
Expand Up @@ -139,7 +139,8 @@ class MeViewController: UITableViewController, UIViewControllerRestoration {
title: RowTitles.appSettings,
icon: Gridicon.iconOfType(.phone),
accessoryType: accessoryType,
action: pushAppSettings())
action: pushAppSettings(),
accessibilityIdentifier: "appSettings")
}

fileprivate func tableViewModel(_ loggedIn: Bool) -> ImmuTable {
Expand All @@ -149,19 +150,22 @@ class MeViewController: UITableViewController, UIViewControllerRestoration {
title: RowTitles.myProfile,
icon: Gridicon.iconOfType(.user),
accessoryType: accessoryType,
action: pushMyProfile())
action: pushMyProfile(),
accessibilityIdentifier: "myProfile")

let accountSettings = NavigationItemRow(
title: RowTitles.accountSettings,
icon: Gridicon.iconOfType(.cog),
accessoryType: accessoryType,
action: pushAccountSettings())
action: pushAccountSettings(),
accessibilityIdentifier: "accountSettings")

let notificationSettings = NavigationItemRow(
title: RowTitles.notificationSettings,
icon: Gridicon.iconOfType(.bell),
accessoryType: accessoryType,
action: pushNotificationSettings())
action: pushNotificationSettings(),
accessibilityIdentifier: "notificationSettings")

let helpAndSupportIndicator = IndicatorNavigationItemRow(
title: RowTitles.support,
Expand Down
36 changes: 24 additions & 12 deletions WordPress/WordPress.xcodeproj/project.pbxproj
Expand Up @@ -1240,15 +1240,16 @@
BEA0E4851BD83565000AEE81 /* WP3DTouchShortcutCreatorTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = BEA0E4841BD83565000AEE81 /* WP3DTouchShortcutCreatorTests.swift */; };
BED4D8301FF11DEF00A11345 /* EditorAztecTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = BED4D82F1FF11DEF00A11345 /* EditorAztecTests.swift */; };
BED4D8331FF11E3800A11345 /* LoginFlow.swift in Sources */ = {isa = PBXBuildFile; fileRef = BED4D8321FF11E3800A11345 /* LoginFlow.swift */; };
BED4D8351FF1208400A11345 /* EditorScreen.swift in Sources */ = {isa = PBXBuildFile; fileRef = BED4D8341FF1208400A11345 /* EditorScreen.swift */; };
BED4D8371FF1289B00A11345 /* EditorEditLinkScreen.swift in Sources */ = {isa = PBXBuildFile; fileRef = BED4D8361FF1289B00A11345 /* EditorEditLinkScreen.swift */; };
BED4D8391FF137FD00A11345 /* EditorTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = BED4D8381FF137FD00A11345 /* EditorTests.swift */; };
BED4D8351FF1208400A11345 /* AztecEditorScreen.swift in Sources */ = {isa = PBXBuildFile; fileRef = BED4D8341FF1208400A11345 /* AztecEditorScreen.swift */; };
BED4D83B1FF13B8A00A11345 /* EditorPublishEpilogueScreen.swift in Sources */ = {isa = PBXBuildFile; fileRef = BED4D83A1FF13B8A00A11345 /* EditorPublishEpilogueScreen.swift */; };
C533CF350E6D3ADA000C3DE8 /* CommentsViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = C533CF340E6D3ADA000C3DE8 /* CommentsViewController.m */; };
C545E0A21811B9880020844C /* ContextManager.m in Sources */ = {isa = PBXBuildFile; fileRef = C545E0A11811B9880020844C /* ContextManager.m */; };
C56636E91868D0CE00226AAB /* StatsViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = C56636E71868D0CE00226AAB /* StatsViewController.m */; };
C58349C51806F95100B64089 /* IOS7CorrectedTextView.m in Sources */ = {isa = PBXBuildFile; fileRef = C58349C41806F95100B64089 /* IOS7CorrectedTextView.m */; };
CC19BE06223FECAC00CAB3E1 /* EditorPostSettings.swift in Sources */ = {isa = PBXBuildFile; fileRef = CC19BE05223FECAC00CAB3E1 /* EditorPostSettings.swift */; };
CC2BB0CA2289CC3B0034F9AB /* BlockEditorScreen.swift in Sources */ = {isa = PBXBuildFile; fileRef = CC2BB0C92289CC3B0034F9AB /* BlockEditorScreen.swift */; };
CC2BB0CE2289D10D0034F9AB /* AppSettingsScreen.swift in Sources */ = {isa = PBXBuildFile; fileRef = CC2BB0CD2289D10D0034F9AB /* AppSettingsScreen.swift */; };
CC2BB0D0228ACF710034F9AB /* EditorGutenbergTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = CC2BB0CF228ACF710034F9AB /* EditorGutenbergTests.swift */; };
CC52188C2278C622008998CE /* EditorFlow.swift in Sources */ = {isa = PBXBuildFile; fileRef = CC52188B2278C622008998CE /* EditorFlow.swift */; };
CC52189A2279CF3B008998CE /* MediaPickerAlbumListScreen.swift in Sources */ = {isa = PBXBuildFile; fileRef = CC5218992279CF3B008998CE /* MediaPickerAlbumListScreen.swift */; };
CC52189C2279D295008998CE /* MediaPickerAlbumScreen.swift in Sources */ = {isa = PBXBuildFile; fileRef = CC52189B2279D295008998CE /* MediaPickerAlbumScreen.swift */; };
Expand Down Expand Up @@ -3298,9 +3299,7 @@
BEA0E4841BD83565000AEE81 /* WP3DTouchShortcutCreatorTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = WP3DTouchShortcutCreatorTests.swift; path = System/3DTouch/WP3DTouchShortcutCreatorTests.swift; sourceTree = "<group>"; };
BED4D82F1FF11DEF00A11345 /* EditorAztecTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = EditorAztecTests.swift; sourceTree = "<group>"; };
BED4D8321FF11E3800A11345 /* LoginFlow.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LoginFlow.swift; sourceTree = "<group>"; };
BED4D8341FF1208400A11345 /* EditorScreen.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = EditorScreen.swift; sourceTree = "<group>"; };
BED4D8361FF1289B00A11345 /* EditorEditLinkScreen.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = EditorEditLinkScreen.swift; sourceTree = "<group>"; };
BED4D8381FF137FD00A11345 /* EditorTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = EditorTests.swift; sourceTree = "<group>"; };
BED4D8341FF1208400A11345 /* AztecEditorScreen.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AztecEditorScreen.swift; sourceTree = "<group>"; };
BED4D83A1FF13B8A00A11345 /* EditorPublishEpilogueScreen.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = EditorPublishEpilogueScreen.swift; sourceTree = "<group>"; };
C52812131832E071008931FD /* WordPress 13.xcdatamodel */ = {isa = PBXFileReference; lastKnownFileType = wrapper.xcdatamodel; path = "WordPress 13.xcdatamodel"; sourceTree = "<group>"; };
C533CF330E6D3ADA000C3DE8 /* CommentsViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CommentsViewController.h; sourceTree = "<group>"; };
Expand All @@ -3317,6 +3316,9 @@
CC24E5F01577DBC300A6D5B5 /* AddressBook.framework */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = wrapper.framework; name = AddressBook.framework; path = System/Library/Frameworks/AddressBook.framework; sourceTree = SDKROOT; };
CC24E5F21577DFF400A6D5B5 /* Twitter.framework */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = wrapper.framework; name = Twitter.framework; path = System/Library/Frameworks/Twitter.framework; sourceTree = SDKROOT; };
CC24E5F41577E16B00A6D5B5 /* Accounts.framework */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = wrapper.framework; name = Accounts.framework; path = System/Library/Frameworks/Accounts.framework; sourceTree = SDKROOT; };
CC2BB0C92289CC3B0034F9AB /* BlockEditorScreen.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BlockEditorScreen.swift; sourceTree = "<group>"; };
CC2BB0CD2289D10D0034F9AB /* AppSettingsScreen.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppSettingsScreen.swift; sourceTree = "<group>"; };
CC2BB0CF228ACF710034F9AB /* EditorGutenbergTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = EditorGutenbergTests.swift; sourceTree = "<group>"; };
CC52188B2278C622008998CE /* EditorFlow.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = EditorFlow.swift; sourceTree = "<group>"; };
CC5218992279CF3B008998CE /* MediaPickerAlbumListScreen.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MediaPickerAlbumListScreen.swift; sourceTree = "<group>"; };
CC52189B2279D295008998CE /* MediaPickerAlbumScreen.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MediaPickerAlbumScreen.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -7548,6 +7550,7 @@
CC5218982279CF06008998CE /* Media */,
BED4D83D1FF13C7300A11345 /* Login */,
BED4D83C1FF13C6200A11345 /* Editor */,
CC2BB0CC2289D0F20034F9AB /* Me */,
BE6DD3251FD66C2900E55192 /* SignupScreen.swift */,
BE2B4E9E1FD664F5007AE3E4 /* BaseScreen.swift */,
BE6DD32D1FD67EDA00E55192 /* MySitesScreen.swift */,
Expand Down Expand Up @@ -7609,7 +7612,7 @@
FF2716911CAAC87B0006E2D4 /* LoginTests.swift */,
FFA0B7D61CAC1F9F00533B9D /* MainNavigationTests.swift */,
BED4D82F1FF11DEF00A11345 /* EditorAztecTests.swift */,
BED4D8381FF137FD00A11345 /* EditorTests.swift */,
CC2BB0CF228ACF710034F9AB /* EditorGutenbergTests.swift */,
);
path = Tests;
sourceTree = "<group>";
Expand Down Expand Up @@ -7638,9 +7641,9 @@
isa = PBXGroup;
children = (
CC8498CF2241473400DB490A /* EditorSettingsComponents */,
BED4D8361FF1289B00A11345 /* EditorEditLinkScreen.swift */,
BED4D83A1FF13B8A00A11345 /* EditorPublishEpilogueScreen.swift */,
BED4D8341FF1208400A11345 /* EditorScreen.swift */,
BED4D8341FF1208400A11345 /* AztecEditorScreen.swift */,
CC2BB0C92289CC3B0034F9AB /* BlockEditorScreen.swift */,
CC94FC67221452A4002E5825 /* EditorNoticeComponent.swift */,
CC19BE05223FECAC00CAB3E1 /* EditorPostSettings.swift */,
);
Expand Down Expand Up @@ -7730,6 +7733,14 @@
path = Notifications;
sourceTree = "<group>";
};
CC2BB0CC2289D0F20034F9AB /* Me */ = {
isa = PBXGroup;
children = (
CC2BB0CD2289D10D0034F9AB /* AppSettingsScreen.swift */,
);
path = Me;
sourceTree = "<group>";
};
CC5218982279CF06008998CE /* Media */ = {
isa = PBXGroup;
children = (
Expand Down Expand Up @@ -11146,7 +11157,7 @@
FFA0B7D71CAC1F9F00533B9D /* MainNavigationTests.swift in Sources */,
CCE911BE221D85E4007E1D4E /* LoginUsernamePasswordScreen.swift in Sources */,
BE6DD32E1FD67EDA00E55192 /* MySitesScreen.swift in Sources */,
BED4D8351FF1208400A11345 /* EditorScreen.swift in Sources */,
BED4D8351FF1208400A11345 /* AztecEditorScreen.swift in Sources */,
BE6DD32C1FD6782A00E55192 /* LoginEpilogueScreen.swift in Sources */,
BE87071B2006E65C004FB5A4 /* NotificationsScreen.swift in Sources */,
BE6DD3321FD6803700E55192 /* MeTabScreen.swift in Sources */,
Expand All @@ -11157,15 +11168,16 @@
CCF6ACE7221ED73900D0C5BE /* LoginCheckMagicLinkScreen.swift in Sources */,
FF2716921CAAC87B0006E2D4 /* LoginTests.swift in Sources */,
CC8498D32241477F00DB490A /* TagsComponent.swift in Sources */,
BED4D8391FF137FD00A11345 /* EditorTests.swift in Sources */,
BE2B4E9F1FD664F5007AE3E4 /* BaseScreen.swift in Sources */,
BE6DD32A1FD6708900E55192 /* LinkOrPasswordScreen.swift in Sources */,
CC2BB0CA2289CC3B0034F9AB /* BlockEditorScreen.swift in Sources */,
BE6DD3261FD66C2900E55192 /* SignupScreen.swift in Sources */,
CC2BB0D0228ACF710034F9AB /* EditorGutenbergTests.swift in Sources */,
CC8A5EAB22159FA6001B7874 /* WPUITestCredentials.swift in Sources */,
BE2B4EA41FD6659B007AE3E4 /* LoginEmailScreen.swift in Sources */,
BED4D8371FF1289B00A11345 /* EditorEditLinkScreen.swift in Sources */,
BE6DD3281FD6705200E55192 /* LoginPasswordScreen.swift in Sources */,
BE6DD3301FD67F3B00E55192 /* TabNavComponent.swift in Sources */,
CC2BB0CE2289D10D0034F9AB /* AppSettingsScreen.swift in Sources */,
CC94FC68221452A4002E5825 /* EditorNoticeComponent.swift in Sources */,
BED4D83B1FF13B8A00A11345 /* EditorPublishEpilogueScreen.swift in Sources */,
CC52188C2278C622008998CE /* EditorFlow.swift in Sources */,
Expand Down
9 changes: 9 additions & 0 deletions WordPress/WordPressUITests/Flows/EditorFlow.swift
Expand Up @@ -6,4 +6,13 @@ class EditorFlow {
navBackButton.tap()
}
}

static func toggleBlockEditor(to state: AppSettingsScreen.Toggle) -> AppSettingsScreen {
if !AppSettingsScreen.isLoaded() {
_ = TabNavComponent()
.gotoMeScreen()
.gotoAppSettings()
}
return AppSettingsScreen().toggleBlockEditor(to: state)
}
}
@@ -1,7 +1,7 @@
import Foundation
import XCTest

class EditorScreen: BaseScreen {
class AztecEditorScreen: BaseScreen {
enum Mode {
case rich
case html
Expand Down Expand Up @@ -86,7 +86,7 @@ class EditorScreen: BaseScreen {
}

@discardableResult
func addList(type: String) -> EditorScreen {
func addList(type: String) -> AztecEditorScreen {
tapToolbarButton(button: listButton)
if type == "ul" {
unorderedListOption.tap()
Expand All @@ -97,7 +97,7 @@ class EditorScreen: BaseScreen {
return self
}

func addListWithLines(type: String, lines: Array<String>) -> EditorScreen {
func addListWithLines(type: String, lines: Array<String>) -> AztecEditorScreen {
addList(type: type)

for (index, line) in lines.enumerated() {
Expand All @@ -113,7 +113,7 @@ class EditorScreen: BaseScreen {
Tapping on toolbar button. And swipes if needed.
*/
@discardableResult
func tapToolbarButton(button: XCUIElement) -> EditorScreen {
func tapToolbarButton(button: XCUIElement) -> AztecEditorScreen {
let swipeElement = mediaButton.isHittable ? mediaButton : linkButton

if !button.exists || !button.isHittable {
Expand All @@ -131,7 +131,7 @@ class EditorScreen: BaseScreen {
30:32 - first word in 2d indented line (list)
30:72 - first word in 3d intended line (blockquote)
*/
func tapByCordinates(x: Int, y: Int) -> EditorScreen {
func tapByCordinates(x: Int, y: Int) -> AztecEditorScreen {
// textView frames on different devices:
// iPhone X (0.0, 88.0, 375.0, 391.0)
// iPhone SE (0.0, 64.0, 320.0, 504.0)
Expand All @@ -150,18 +150,18 @@ class EditorScreen: BaseScreen {
/**
Switches between Rich and HTML view.
*/
func switchContentView() -> EditorScreen {
func switchContentView() -> AztecEditorScreen {
tapToolbarButton(button: sourcecodeButton)


return EditorScreen(mode: mode.toggle())
return AztecEditorScreen(mode: mode.toggle())
}

/**
Common method to type in different text fields
*/
@discardableResult
func enterText(text: String) -> EditorScreen {
func enterText(text: String) -> AztecEditorScreen {
contentPlaceholder.tap()
textView.typeText(text)
return self
Expand All @@ -171,15 +171,15 @@ class EditorScreen: BaseScreen {
Enters text into title field.
- Parameter text: the test to enter into the title
*/
func enterTextInTitle(text: String) -> EditorScreen {
func enterTextInTitle(text: String) -> AztecEditorScreen {
titleView.tap()
titleView.typeText(text)

return self
}

@discardableResult
func deleteText(chars: Int) -> EditorScreen {
func deleteText(chars: Int) -> AztecEditorScreen {
for _ in 1...chars {
app.keys["delete"].tap()
}
Expand All @@ -198,23 +198,18 @@ class EditorScreen: BaseScreen {
/**
Selects all entered text in provided textView element
*/
func selectAllText() -> EditorScreen {
func selectAllText() -> AztecEditorScreen {
textView.coordinate(withNormalizedOffset: CGVector.zero).press(forDuration: 1)
app.menuItems["Select All"].tap()

return self
}

func makeLink() -> EditorEditLinkScreen {
tapToolbarButton(button: linkButton)

return EditorEditLinkScreen()
}
/*
Select Image from Camera Roll by its ID. Starts with 0
Simulator range: 0..4
*/
func addImageByOrder(id: Int) -> EditorScreen {
func addImageByOrder(id: Int) -> AztecEditorScreen {
tapToolbarButton(button: mediaButton)

// Allow access to device media
Expand Down

0 comments on commit 41da008

Please sign in to comment.