Skip to content

Commit d6039c1

Browse files
authored
Fix AI undo redo editor test (#25630)
* Fix AI undo redo editor test * Retrigger regular CI
1 parent a2e0a19 commit d6039c1

4 files changed

Lines changed: 41 additions & 23 deletions

File tree

Tests/AgentTests/ui-tests/undo-redo-in-editor.md

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,18 @@
99
3. If a bottom sheet appears, select "Post".
1010
4. Verify the Undo button is disabled.
1111
5. Verify the Redo button is disabled.
12-
6. Enter "Rich post title" as the post title.
12+
6. Enter "Undo test" as the post title.
1313
7. Tap below the title to add a paragraph block.
14-
8. Type "Lorem ipsum dolor sit amet" as the paragraph content.
15-
9. Tap the Undo button twice to undo the paragraph and title.
16-
10. Verify the editor content is empty (no blocks visible).
17-
11. Tap the Redo button twice to restore the paragraph and title.
18-
12. Verify the paragraph content "Lorem ipsum dolor sit amet" is visible again.
14+
8. Type "Test" as the paragraph content.
15+
9. Tap the Undo button until the typed title and paragraph text are no longer visible and the Undo button becomes disabled.
16+
Undo is granular, so it may take several taps. Stop as soon as Undo is disabled. Do not tap Undo more than 15 times.
17+
10. Verify the typed title and paragraph text are no longer visible, and the Undo button is disabled.
18+
Empty title or paragraph placeholders may still be visible.
19+
11. Tap the Redo button until the title and paragraph are restored and the Redo button becomes disabled.
20+
Redo is granular, so it may take several taps. Stop as soon as Redo is disabled. Do not tap Redo more than 15 times.
21+
12. Verify the title "Undo test" and paragraph content "Test" are visible again, and the Redo button is disabled.
1922

2023
## Expected Outcome
21-
- After undoing, the editor content is empty.
22-
- After redoing, the title and paragraph content are restored.
24+
- After undoing all edits, the typed title and paragraph text are gone and the Undo button is disabled.
25+
- After redoing all edits, the title and paragraph content are restored and the Redo button is disabled.
2326
- Undo and Redo buttons correctly reflect available actions throughout the flow.

WordPress/Classes/ViewRelated/Gutenberg/GutenbergViewController.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1207,7 +1207,7 @@ extension GutenbergViewController: PostEditorNavigationBarManagerDelegate {
12071207
func gutenbergDidRequestToggleUndoButton(_ isDisabled: Bool) {
12081208
DispatchQueue.main.async {
12091209
UIView.animate(withDuration: 0.2) {
1210-
self.navigationBarManager.undoButton.isUserInteractionEnabled = isDisabled ? false : true
1210+
self.navigationBarManager.undoButton.isEnabled = !isDisabled
12111211
self.navigationBarManager.undoButton.alpha = isDisabled ? 0.3 : 1.0
12121212
}
12131213
}
@@ -1216,7 +1216,7 @@ extension GutenbergViewController: PostEditorNavigationBarManagerDelegate {
12161216
func gutenbergDidRequestToggleRedoButton(_ isDisabled: Bool) {
12171217
DispatchQueue.main.async {
12181218
UIView.animate(withDuration: 0.2) {
1219-
self.navigationBarManager.redoButton.isUserInteractionEnabled = isDisabled ? false : true
1219+
self.navigationBarManager.redoButton.isEnabled = !isDisabled
12201220
self.navigationBarManager.redoButton.alpha = isDisabled ? 0.3 : 1.0
12211221
}
12221222
}

WordPress/Classes/ViewRelated/NewGutenberg/NewGutenbergViewController.swift

Lines changed: 26 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,15 @@ class NewGutenbergViewController: PostGBKEditorViewController, PostEditor, Publi
6060

6161
// TODO: reimplemet
6262
// internal private(set) var contentInfo: ContentInfo?
63+
private var isNavigationEnabled = true {
64+
didSet { updateHistoryButtons() }
65+
}
66+
private var isUndoButtonDisabled = true {
67+
didSet { updateHistoryButtons() }
68+
}
69+
private var isRedoButtonDisabled = true {
70+
didSet { updateHistoryButtons() }
71+
}
6372

6473
// MARK: - GutenbergKit
6574

@@ -154,28 +163,34 @@ class NewGutenbergViewController: PostGBKEditorViewController, PostEditor, Publi
154163

155164
private func gutenbergDidRequestToggleRedoButton(_ isDisabled: Bool) {
156165
DispatchQueue.main.async {
157-
UIView.animate(withDuration: 0.2) {
158-
self.navigationBarManager.redoButton.isUserInteractionEnabled = isDisabled ? false : true
159-
self.navigationBarManager.redoButton.alpha = isDisabled ? 0.3 : 1.0
160-
}
166+
self.isRedoButtonDisabled = isDisabled
161167
}
162168
}
163169

164170
private func gutenbergDidRequestToggleUndoButton(_ isDisabled: Bool) {
165171
DispatchQueue.main.async {
166-
UIView.animate(withDuration: 0.2) {
167-
self.navigationBarManager.undoButton.isUserInteractionEnabled = isDisabled ? false : true
168-
self.navigationBarManager.undoButton.alpha = isDisabled ? 0.3 : 1.0
169-
}
172+
self.isUndoButtonDisabled = isDisabled
170173
}
171174
}
172175

173176
private func setNavigationItemsEnabled(_ enabled: Bool) {
177+
isNavigationEnabled = enabled
174178
navigationBarManager.closeButton.isEnabled = enabled
175179
navigationBarManager.moreButton.isEnabled = enabled
176-
navigationBarManager.publishButton.isEnabled = enabled
177-
navigationBarManager.undoButton.isEnabled = enabled
178-
navigationBarManager.redoButton.isEnabled = enabled
180+
navigationBarManager.publishButton.isEnabled = enabled && isPublishButtonEnabled
181+
}
182+
183+
private func updateHistoryButtons() {
184+
updateHistoryButton(navigationBarManager.undoButton, isDisabled: !isNavigationEnabled || isUndoButtonDisabled)
185+
updateHistoryButton(navigationBarManager.redoButton, isDisabled: !isNavigationEnabled || isRedoButtonDisabled)
186+
}
187+
188+
private func updateHistoryButton(_ button: UIButton, isDisabled: Bool) {
189+
let isEnabled = !isDisabled
190+
UIView.animate(withDuration: 0.2) {
191+
button.isEnabled = isEnabled
192+
button.alpha = isEnabled ? 1.0 : 0.3
193+
}
179194
}
180195

181196
private func performAutoSave() {

WordPress/Classes/ViewRelated/Post/PostEditorNavigationBarManager.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ class PostEditorNavigationBarManager {
4040
button.addTarget(self, action: #selector(undoWasPressed), for: .touchUpInside)
4141
button.sizeToFit()
4242
button.alpha = 0.3
43-
button.isUserInteractionEnabled = false
43+
button.isEnabled = false
4444
return button
4545
}()
4646

@@ -54,7 +54,7 @@ class PostEditorNavigationBarManager {
5454
button.addTarget(self, action: #selector(redoWasPressed), for: .touchUpInside)
5555
button.sizeToFit()
5656
button.alpha = 0.3
57-
button.isUserInteractionEnabled = false
57+
button.isEnabled = false
5858
return button
5959
}()
6060

0 commit comments

Comments
 (0)