Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Limit Classic editor access on Simple WP.com sites to existing Classic posts #15766

Merged
merged 17 commits into from
Apr 2, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .circleci/cache-version
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
# To invalidate the cache, generate a new UUID using `uuidgen` on the command line then paste it here
8412DC8E-32C7-48D9-9C6B-E84319AE0436
BA7CD240-05A5-4C42-AFD5-4C66D94F520C
12 changes: 10 additions & 2 deletions WordPress/Classes/Utility/Editor/GutenbergSettings.swift
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,10 @@ class GutenbergSettings {

// MARK: - Gutenberg Choice Logic

func isSimpleWPComSite(_ blog: Blog) -> Bool {
return !blog.isAtomic() && blog.isHostedAtWPcom
}

/// Call this method to know if Gutenberg must be used for the specified post.
///
/// - Parameters:
Expand All @@ -179,9 +183,8 @@ class GutenbergSettings {
///
func mustUseGutenberg(for post: AbstractPost) -> Bool {
let blog = post.blog

if post.isContentEmpty() {
return blog.isGutenbergEnabled
return isSimpleWPComSite(post.blog) || blog.isGutenbergEnabled
} else {
// It's an existing post
return post.containsGutenbergBlocks()
Expand All @@ -205,6 +208,11 @@ class GutenbergSettingsBridge: NSObject {
static func postSettingsToRemote(for blog: Blog) {
GutenbergSettings().postSettingsToRemote(for: blog)
}

@objc(isSimpleWPComSite:)
static func isSimpleWPComSite(_ blog: Blog) -> Bool {
return GutenbergSettings().isSimpleWPComSite(blog)
}
}

private extension String {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,10 @@ - (NSArray *)tableSections
[sections addObject:@(SiteSettingsSectionAccount)];
}

[sections addObject:@(SiteSettingsSectionEditor)];
// Only add the editor section if the site is not a Simple WP.com site
if (![GutenbergSettings isSimpleWPComSite:self.blog]) {
[sections addObject:@(SiteSettingsSectionEditor)];
}

if ([self.blog supports:BlogFeatureWPComRESTAPI] && self.blog.isAdmin) {
[sections addObject:@(SiteSettingsSectionWriting)];
Expand Down
4 changes: 4 additions & 0 deletions WordPress/WordPressUITests/Flows/EditorFlow.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ class EditorFlow {
}
}

static func gotoMySiteScreen() -> MySiteScreen {
return TabNavComponent().gotoMySiteScreen()
}

static func toggleBlockEditor(to state: SiteSettingsScreen.Toggle) -> SiteSettingsScreen {
if !SiteSettingsScreen.isLoaded() {
_ = TabNavComponent()
Expand Down
108 changes: 55 additions & 53 deletions WordPress/WordPressUITests/Tests/EditorAztecTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -24,57 +24,59 @@ class EditorAztecTests: XCTestCase {
super.tearDown()
}

func testTextPostPublish() {
let title = getRandomPhrase()
let content = getRandomContent()
editorScreen
.enterTextInTitle(text: title)
.enterText(text: content)
.publish()
.viewPublishedPost(withTitle: title)
.verifyEpilogueDisplays(postTitle: title, siteAddress: WPUITestCredentials.testWPcomSitePrimaryAddress)
.done()
}

func testBasicPostPublish() {
let title = getRandomPhrase()
let content = getRandomContent()
let category = getCategory()
let tag = getTag()
editorScreen
.enterTextInTitle(text: title)
.enterText(text: content)
.addImageByOrder(id: 0)
.openPostSettings()
.selectCategory(name: category)
.addTag(name: tag)
.setFeaturedImage()
.verifyPostSettings(withCategory: category, withTag: tag, hasImage: true)
.removeFeatureImage()
.verifyPostSettings(withCategory: category, withTag: tag, hasImage: false)
.setFeaturedImage()
.verifyPostSettings(withCategory: category, withTag: tag, hasImage: true)
.closePostSettings()
AztecEditorScreen(mode: .rich).publish()
.viewPublishedPost(withTitle: title)
.verifyEpilogueDisplays(postTitle: title, siteAddress: WPUITestCredentials.testWPcomSitePrimaryAddress)
.done()
}

// Github issue https://github.com/wordpress-mobile/AztecEditor-iOS/issues/385
func testLongTitle() {
let longTitle = "long title in a galaxy not so far away"
// Title heigh contains of actual textfield height + bottom line.
// 16.5px - is the height of that bottom line. Its not changing with different font sizes
let titleTextView = editorScreen.titleView
let titleLineHeight = titleTextView.frame.height - 16.5
let oneLineTitleHeight = titleTextView.frame.height

let repeatTimes = isIPhone ? 6 : 20
_ = editorScreen.enterTextInTitle(text: String(repeating: "very ", count: repeatTimes) + longTitle)

let twoLineTitleHeight = titleTextView.frame.height

XCTAssert(twoLineTitleHeight - oneLineTitleHeight >= titleLineHeight )
}
// TODO: Re-enable Aztec tests but for editing an existing Aztec post.
// For more information, see Issue: https://github.com/wordpress-mobile/WordPress-iOS/issues/16218
// func testTextPostPublish() {
// let title = getRandomPhrase()
// let content = getRandomContent()
// editorScreen
// .enterTextInTitle(text: title)
// .enterText(text: content)
// .publish()
// .viewPublishedPost(withTitle: title)
// .verifyEpilogueDisplays(postTitle: title, siteAddress: WPUITestCredentials.testWPcomSitePrimaryAddress)
// .done()
// }
//
// func testBasicPostPublish() {
// let title = getRandomPhrase()
// let content = getRandomContent()
// let category = getCategory()
// let tag = getTag()
// editorScreen
// .enterTextInTitle(text: title)
// .enterText(text: content)
// .addImageByOrder(id: 0)
// .openPostSettings()
// .selectCategory(name: category)
// .addTag(name: tag)
// .setFeaturedImage()
// .verifyPostSettings(withCategory: category, withTag: tag, hasImage: true)
// .removeFeatureImage()
// .verifyPostSettings(withCategory: category, withTag: tag, hasImage: false)
// .setFeaturedImage()
// .verifyPostSettings(withCategory: category, withTag: tag, hasImage: true)
// .closePostSettings()
// AztecEditorScreen(mode: .rich).publish()
// .viewPublishedPost(withTitle: title)
// .verifyEpilogueDisplays(postTitle: title, siteAddress: WPUITestCredentials.testWPcomSitePrimaryAddress)
// .done()
// }
//
// // Github issue https://github.com/wordpress-mobile/AztecEditor-iOS/issues/385
// func testLongTitle() {
// let longTitle = "long title in a galaxy not so far away"
// // Title heigh contains of actual textfield height + bottom line.
// // 16.5px - is the height of that bottom line. Its not changing with different font sizes
// let titleTextView = editorScreen.titleView
// let titleLineHeight = titleTextView.frame.height - 16.5
// let oneLineTitleHeight = titleTextView.frame.height
//
// let repeatTimes = isIPhone ? 6 : 20
// _ = editorScreen.enterTextInTitle(text: String(repeating: "very ", count: repeatTimes) + longTitle)
//
// let twoLineTitleHeight = titleTextView.frame.height
//
// XCTAssert(twoLineTitleHeight - oneLineTitleHeight >= titleLineHeight )
// }
}
3 changes: 1 addition & 2 deletions WordPress/WordPressUITests/Tests/EditorGutenbergTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,7 @@ class EditorGutenbergTests: XCTestCase {

_ = LoginFlow.loginIfNeeded(siteUrl: WPUITestCredentials.testWPcomSiteAddress, email: WPUITestCredentials.testWPcomUserEmail, password: WPUITestCredentials.testWPcomPassword)
editorScreen = EditorFlow
.toggleBlockEditor(to: .on)
.goBackToMySite()
.gotoMySiteScreen()
.tabBar.gotoBlockEditorScreen()
}

Expand Down