Skip to content

Commit be08131

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

4 files changed

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

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

6474
// MARK: - GutenbergKit
6575

@@ -154,28 +164,58 @@ class NewGutenbergViewController: PostGBKEditorViewController, PostEditor, Publi
154164

155165
private func gutenbergDidRequestToggleRedoButton(_ isDisabled: Bool) {
156166
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-
}
167+
self.isRedoButtonDisabled = isDisabled
161168
}
162169
}
163170

164171
private func gutenbergDidRequestToggleUndoButton(_ isDisabled: Bool) {
165172
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-
}
173+
self.isUndoButtonDisabled = isDisabled
170174
}
171175
}
172176

173177
private func setNavigationItemsEnabled(_ enabled: Bool) {
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+
if enabled {
183+
updateUndoButton()
184+
updateRedoButton()
185+
} else {
186+
updateHistoryButton(navigationBarManager.undoButton, isDisabled: true)
187+
updateHistoryButton(navigationBarManager.redoButton, isDisabled: true)
188+
}
189+
}
190+
191+
private func updateUndoButtonIfNavigationIsEnabled() {
192+
guard navigationBarManager.closeButton.isEnabled else {
193+
return
194+
}
195+
updateUndoButton()
196+
}
197+
198+
private func updateRedoButtonIfNavigationIsEnabled() {
199+
guard navigationBarManager.closeButton.isEnabled else {
200+
return
201+
}
202+
updateRedoButton()
203+
}
204+
205+
private func updateUndoButton() {
206+
updateHistoryButton(navigationBarManager.undoButton, isDisabled: isUndoButtonDisabled)
207+
}
208+
209+
private func updateRedoButton() {
210+
updateHistoryButton(navigationBarManager.redoButton, isDisabled: isRedoButtonDisabled)
211+
}
212+
213+
private func updateHistoryButton(_ button: UIButton, isDisabled: Bool) {
214+
let isEnabled = !isDisabled
215+
UIView.animate(withDuration: 0.2) {
216+
button.isEnabled = isEnabled
217+
button.alpha = isEnabled ? 1.0 : 0.3
218+
}
179219
}
180220

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