|
| 1 | +import 'dart:ui'; |
| 2 | + |
1 | 3 | import 'package:clock/clock.dart';
|
| 4 | +import 'package:flutter/services.dart'; |
2 | 5 | import 'package:flutter_test/flutter_test.dart';
|
3 | 6 | import 'package:flutter_test_robots/flutter_test_robots.dart';
|
4 | 7 | import 'package:flutter_test_runners/flutter_test_runners.dart';
|
@@ -158,6 +161,58 @@ void main() {
|
158 | 161 | await tester.pressCmdShiftZ(tester);
|
159 | 162 | _expectDocumentWithCaret("Hello", "1", 5);
|
160 | 163 | });
|
| 164 | + |
| 165 | + testWidgetsOnMac("undo when typing after an image", (tester) async { |
| 166 | + // A reported bug found that when inserting a paragraph after an image, typing some |
| 167 | + // text, and then undo'ing the text, the paragraph's text duplicates during the |
| 168 | + // undo operation: https://github.com/superlistapp/super_editor/issues/2164 |
| 169 | + // TODO: The root cause of this problem was mutability of DocumentNode's. Delete this test after completing: https://github.com/superlistapp/super_editor/issues/2166 |
| 170 | + final testContext = await tester |
| 171 | + .createDocument() // |
| 172 | + .withCustomContent(MutableDocument( |
| 173 | + nodes: [ |
| 174 | + ImageNode(id: "1", imageUrl: "https://fakeimage.com/myimage.png"), |
| 175 | + ], |
| 176 | + )) |
| 177 | + .withComponentBuilders([ |
| 178 | + const FakeImageComponentBuilder(size: Size(1000, 400)), |
| 179 | + ...defaultComponentBuilders, |
| 180 | + ]) |
| 181 | + .enableHistory(true) |
| 182 | + .autoFocus(true) |
| 183 | + .pump(); |
| 184 | + |
| 185 | + await tester.tapAtDocumentPosition( |
| 186 | + const DocumentPosition(nodeId: "1", nodePosition: UpstreamDownstreamNodePosition.downstream()), |
| 187 | + ); |
| 188 | + |
| 189 | + // Press enter to insert a new paragraph. |
| 190 | + await tester.pressEnter(); |
| 191 | + |
| 192 | + // Ensure we inserted a paragraph. |
| 193 | + expect(testContext.document.nodeCount, 2); |
| 194 | + expect(testContext.document.getNodeAt(0), isA<ImageNode>()); |
| 195 | + expect(testContext.document.getNodeAt(1), isA<TextNode>()); |
| 196 | + |
| 197 | + // Type some text. |
| 198 | + await tester.pressKey(LogicalKeyboardKey.keyA); |
| 199 | + |
| 200 | + // Wait long enough to avoid combining actions into a single transaction. |
| 201 | + await tester.pump(const Duration(seconds: 2)); |
| 202 | + |
| 203 | + // Type more text. |
| 204 | + await tester.pressKey(LogicalKeyboardKey.keyB); |
| 205 | + |
| 206 | + // Ensure we inserted the text. |
| 207 | + expect((testContext.document.getNodeAt(1) as TextNode).text.text, "ab"); |
| 208 | + |
| 209 | + // Undo the text insertion. |
| 210 | + // TODO: remove `tester` reference after updating flutter_test_robots |
| 211 | + await tester.pressCmdZ(tester); |
| 212 | + |
| 213 | + // Ensure that the paragraph removed the last entered character. |
| 214 | + expect((testContext.document.getNodeAt(1) as TextNode).text.text, "a"); |
| 215 | + }); |
161 | 216 | });
|
162 | 217 |
|
163 | 218 | group("content conversions >", () {
|
|
0 commit comments