Skip to content

Commit 38b9ba4

Browse files
committed
Fix AI undo redo editor test
1 parent 28eaf06 commit 38b9ba4

4 files changed

Lines changed: 42 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: 27 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,9 @@ class NewGutenbergViewController: PostGBKEditorViewController, PostEditor, Publi
6060

6161
// TODO: reimplemet
6262
// internal private(set) var contentInfo: ContentInfo?
63+
private var areNavigationItemsEnabled = true
64+
private var isUndoButtonDisabled = true
65+
private var isRedoButtonDisabled = true
6366

6467
// MARK: - GutenbergKit
6568

@@ -154,28 +157,41 @@ class NewGutenbergViewController: PostGBKEditorViewController, PostEditor, Publi
154157

155158
private func gutenbergDidRequestToggleRedoButton(_ isDisabled: Bool) {
156159
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-
}
160+
self.isRedoButtonDisabled = isDisabled
161+
self.updateRedoButton()
161162
}
162163
}
163164

164165
private func gutenbergDidRequestToggleUndoButton(_ isDisabled: Bool) {
165166
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-
}
167+
self.isUndoButtonDisabled = isDisabled
168+
self.updateUndoButton()
170169
}
171170
}
172171

173172
private func setNavigationItemsEnabled(_ enabled: Bool) {
173+
areNavigationItemsEnabled = enabled
174174
navigationBarManager.closeButton.isEnabled = enabled
175175
navigationBarManager.moreButton.isEnabled = enabled
176-
navigationBarManager.publishButton.isEnabled = enabled
177-
navigationBarManager.undoButton.isEnabled = enabled
178-
navigationBarManager.redoButton.isEnabled = enabled
176+
navigationBarManager.publishButton.isEnabled = enabled && isPublishButtonEnabled
177+
updateUndoButton()
178+
updateRedoButton()
179+
}
180+
181+
private func updateUndoButton() {
182+
updateHistoryButton(navigationBarManager.undoButton, isDisabled: isUndoButtonDisabled)
183+
}
184+
185+
private func updateRedoButton() {
186+
updateHistoryButton(navigationBarManager.redoButton, isDisabled: isRedoButtonDisabled)
187+
}
188+
189+
private func updateHistoryButton(_ button: UIButton, isDisabled: Bool) {
190+
let isEnabled = areNavigationItemsEnabled && !isDisabled
191+
UIView.animate(withDuration: 0.2) {
192+
button.isEnabled = isEnabled
193+
button.alpha = isEnabled ? 1.0 : 0.3
194+
}
179195
}
180196

181197
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)