Repository navigation
Stabilize editor settings response tests #26405
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -12,11 +12,11 @@ private class TestableEditorSettingsService: EditorSettingsService { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| override func api(for blog: Blog) -> WordPressComRestApi? { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return mockApi | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| mockApi | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| override var apiForDefaultAccount: WordPressComRestApi? { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return mockApi | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| mockApi | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
@@ -98,8 +98,13 @@ class EditorSettingsServiceTest: CoreDataTestCase { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| let blogs = addBlogsToAccount(count: numberOfBlogs) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| let response = bulkResponse(with: .gutenberg, count: numberOfBlogs) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| service.migrateGlobalSettingToRemote(isGutenbergEnabled: true) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| remoteApi.successBlockPassedIn?(response as AnyObject, HTTPURLResponse()) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| blogs.forEach { $0.mobileEditor = .aztec } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| contextManager.saveContextAndWait(mainContext) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| waitForEditorUpdate(to: .gutenberg, blogs: blogs) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| service.migrateGlobalSettingToRemote(isGutenbergEnabled: true) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| remoteApi.successBlockPassedIn?(response as AnyObject, HTTPURLResponse()) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| blogs.forEach { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| XCTAssertTrue($0.isGutenbergEnabled) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
@@ -118,38 +123,47 @@ class EditorSettingsServiceTest: CoreDataTestCase { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| contextManager.saveContextAndWait(mainContext) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| let editorsUpdated = expectation(description: "Editors updated to Aztec") | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| waitForEditorUpdate(to: .aztec, blogs: blogs) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| service.migrateGlobalSettingToRemote(isGutenbergEnabled: false) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| remoteApi.successBlockPassedIn?(response as AnyObject, HTTPURLResponse()) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+126
to
+129
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Finding from Claude: This call site uses the Not blocking: apply this together with the other two suggestions in one batch ("Add suggestion to batch"). Each one depends on the others, so applying only some of them breaks the build.
Suggested change
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| blogs.forEach { blog in | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| XCTAssertFalse(blog.isGutenbergEnabled) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| XCTAssertEqual(blog.editor, .aztec) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| extension EditorSettingsServiceTest { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| private func waitForEditorUpdate(to editor: MobileEditor, blogs: [Blog], update: () -> Void) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| let editorsUpdated = expectation(description: "Editors updated to \(editor.rawValue.capitalized)") | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| var didFulfill = false | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| let observer = NotificationCenter.default.addObserver( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| forName: .NSManagedObjectContextObjectsDidChange, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| object: mainContext, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| queue: nil | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ) { _ in | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if blogs.allSatisfy({ $0.editor == .aztec && !$0.isGutenbergEnabled }) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| editorsUpdated.fulfill() | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| guard !didFulfill, blogs.allSatisfy({ $0.editor == editor }) else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| didFulfill = true | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| editorsUpdated.fulfill() | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| defer { NotificationCenter.default.removeObserver(observer) } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| service.migrateGlobalSettingToRemote(isGutenbergEnabled: false) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| remoteApi.successBlockPassedIn?(response as AnyObject, HTTPURLResponse()) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| update() | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| wait(for: [editorsUpdated], timeout: 2) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| NotificationCenter.default.removeObserver(observer) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| blogs.forEach { blog in | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| XCTAssertFalse(blog.isGutenbergEnabled) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| XCTAssertEqual(blog.editor, .aztec) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+139
to
157
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Finding from Claude:
Checked locally with all three suggestions applied:
Not blocking: apply this together with the other two suggestions in one batch ("Add suggestion to batch"). Each one depends on the others, so applying only some of them breaks the build.
Suggested change
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| extension EditorSettingsServiceTest { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| func addBlogsToAccount(count: Int) -> [Blog] { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| let blogs = makeTestBlogs(count: count) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| account.addBlogs(Set(blogs)) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return blogs | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| func makeTestBlogs(count: Int) -> [Blog] { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return (1...count).map(makeTestBlog) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| (1...count).map(makeTestBlog) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| func makeTestBlog(withID id: Int = 1) -> Blog { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
@@ -160,25 +174,29 @@ extension EditorSettingsServiceTest { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| func bulkResponse(with editor: MobileEditor, count: Int) -> [String: String] { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return (1...count).reduce(into: [String: String]()) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| $0["\($1)"] = editor.rawValue | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| (1...count) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| .reduce(into: [String: String]()) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| $0["\($1)"] = editor.rawValue | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| func responseWith(mobileEditor: String) -> AnyObject { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return [ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| [ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| "editor_mobile": mobileEditor, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| "editor_web": "classic", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| "editor_web": "classic" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ] as AnyObject | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| func sync(with blog: Blog) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| let expec = expectation(description: "success") | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| expec.assertForOverFulfill = true | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| service.syncEditorSettings(for: blog, success: { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| expec.fulfill() | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| }) { error in | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| service.syncEditorSettings( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| for: blog, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| success: { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| expec.fulfill() | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ) { error in | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| XCTFail("This call should succeed. Error: \(error)") | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| expec.fulfill() | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Finding from Claude:
This call site uses the
migrateGlobalSetting(to:response:)helper suggested at line 139.Not blocking: apply this together with the other two suggestions in one batch ("Add suggestion to batch"). Each one depends on the others, so applying only some of them breaks the build.