Преглед изворни кода

Added tests for new buttons and horizontal rule embed

Anatoly Pulyaevskiy пре 6 година
родитељ
комит
54bf81baf8

+ 2
- 2
packages/zefyr/lib/src/widgets/common.dart Прегледај датотеку

@@ -144,7 +144,7 @@ class _RawZefyrLineState extends State<RawZefyrLine> {
144 144
     EmbedAttribute embed = node.style.get(NotusAttribute.embed);
145 145
 
146 146
     if (embed.type == EmbedType.horizontalRule) {
147
-      final hr = new HorizontalRule(node: node);
147
+      final hr = new ZefyrHorizontalRule(node: node);
148 148
       return new EditableBox(
149 149
         child: hr,
150 150
         node: widget.node,
@@ -156,7 +156,7 @@ class _RawZefyrLineState extends State<RawZefyrLine> {
156 156
       );
157 157
     } else if (embed.type == EmbedType.image) {
158 158
       return new EditableBox(
159
-        child: ImageEmbed(node: node, delegate: editable.imageDelegate),
159
+        child: ZefyrImage(node: node, delegate: editable.imageDelegate),
160 160
         node: widget.node,
161 161
         layerLink: _link,
162 162
         renderContext: editable.renderContext,

+ 2
- 2
packages/zefyr/lib/src/widgets/horizontal_rule.dart Прегледај датотеку

@@ -10,8 +10,8 @@ import 'package:notus/notus.dart';
10 10
 
11 11
 import 'editable_box.dart';
12 12
 
13
-class HorizontalRule extends LeafRenderObjectWidget {
14
-  HorizontalRule({@required this.node}) : assert(node != null);
13
+class ZefyrHorizontalRule extends LeafRenderObjectWidget {
14
+  ZefyrHorizontalRule({@required this.node}) : assert(node != null);
15 15
 
16 16
   final EmbedNode node;
17 17
 

+ 5
- 5
packages/zefyr/lib/src/widgets/image.dart Прегледај датотеку

@@ -39,18 +39,18 @@ class ZefyrDefaultImageDelegate implements ZefyrImageDelegate<ImageSource> {
39 39
   }
40 40
 }
41 41
 
42
-class ImageEmbed extends StatefulWidget {
43
-  const ImageEmbed({Key key, @required this.node, @required this.delegate})
42
+class ZefyrImage extends StatefulWidget {
43
+  const ZefyrImage({Key key, @required this.node, @required this.delegate})
44 44
       : super(key: key);
45 45
 
46 46
   final EmbedNode node;
47 47
   final ZefyrImageDelegate delegate;
48 48
 
49 49
   @override
50
-  _ImageEmbedState createState() => _ImageEmbedState();
50
+  _ZefyrImageState createState() => _ZefyrImageState();
51 51
 }
52 52
 
53
-class _ImageEmbedState extends State<ImageEmbed> {
53
+class _ZefyrImageState extends State<ZefyrImage> {
54 54
   ImageProvider _provider;
55 55
   ImageStream _imageStream;
56 56
   ImageInfo _imageInfo;
@@ -70,7 +70,7 @@ class _ImageEmbedState extends State<ImageEmbed> {
70 70
   }
71 71
 
72 72
   @override
73
-  void didUpdateWidget(ImageEmbed oldWidget) {
73
+  void didUpdateWidget(ZefyrImage oldWidget) {
74 74
     super.didUpdateWidget(oldWidget);
75 75
     EmbedAttribute oldStyle = oldWidget.node.style.get(NotusAttribute.embed);
76 76
     final oldSource = oldStyle.value['source'];

+ 1
- 0
packages/zefyr/lib/zefyr.dart Прегледај датотеку

@@ -15,6 +15,7 @@ export 'src/widgets/common.dart';
15 15
 export 'src/widgets/controller.dart';
16 16
 export 'src/widgets/editable_text.dart';
17 17
 export 'src/widgets/editor.dart';
18
+export 'src/widgets/horizontal_rule.dart';
18 19
 export 'src/widgets/image.dart';
19 20
 export 'src/widgets/list.dart';
20 21
 export 'src/widgets/paragraph.dart';

+ 73
- 0
packages/zefyr/test/widgets/buttons_test.dart Прегледај датотеку

@@ -2,6 +2,7 @@
2 2
 // for details. All rights reserved. Use of this source code is governed by a
3 3
 // BSD-style license that can be found in the LICENSE file.
4 4
 import 'package:flutter/material.dart';
5
+import 'package:flutter/services.dart';
5 6
 import 'package:flutter_test/flutter_test.dart';
6 7
 import 'package:zefyr/src/widgets/buttons.dart';
7 8
 import 'package:zefyr/zefyr.dart';
@@ -67,6 +68,15 @@ void main() {
67 68
       await editor.tapButtonWithText('H2');
68 69
       expect(line.style.containsSame(NotusAttribute.heading.level2), isTrue);
69 70
     });
71
+
72
+    testWidgets('close overlay', (tester) async {
73
+      final editor = new EditorSandBox(tester: tester);
74
+      await editor.tapEditor();
75
+      await editor.tapButtonWithIcon(Icons.format_size);
76
+      expect(find.text('H1'), findsOneWidget);
77
+      await editor.tapButtonWithIcon(Icons.close);
78
+      expect(find.text('H1'), findsNothing);
79
+    });
70 80
   });
71 81
 
72 82
   group('$LinkButton', () {
@@ -132,4 +142,67 @@ void main() {
132 142
       expect(line.childCount, 1);
133 143
     });
134 144
   });
145
+
146
+  group('$ImageButton', () {
147
+    const MethodChannel channel =
148
+        const MethodChannel('plugins.flutter.io/image_picker');
149
+
150
+    final List<MethodCall> log = <MethodCall>[];
151
+
152
+    setUp(() {
153
+      channel.setMockMethodCallHandler((MethodCall methodCall) async {
154
+        log.add(methodCall);
155
+        return 'file:///tmp/test.jpg';
156
+      });
157
+      log.clear();
158
+    });
159
+
160
+    testWidgets('toggle overlay', (tester) async {
161
+      final editor = new EditorSandBox(tester: tester);
162
+      await editor.tapEditor();
163
+      await editor.tapButtonWithIcon(Icons.photo);
164
+
165
+      expect(find.byIcon(Icons.photo_camera), findsOneWidget);
166
+      await editor.tapButtonWithIcon(Icons.close);
167
+      expect(find.byIcon(Icons.photo_camera), findsNothing);
168
+    });
169
+
170
+    testWidgets('pick from camera', (tester) async {
171
+      final editor = new EditorSandBox(tester: tester);
172
+      await editor.tapEditor();
173
+      await editor.tapButtonWithIcon(Icons.photo);
174
+      await editor.tapButtonWithIcon(Icons.photo_camera);
175
+      expect(log, hasLength(1));
176
+      expect(
177
+        log.single,
178
+        isMethodCall(
179
+          'pickImage',
180
+          arguments: <String, dynamic>{
181
+            'source': 0,
182
+            'maxWidth': null,
183
+            'maxHeight': null,
184
+          },
185
+        ),
186
+      );
187
+    });
188
+
189
+    testWidgets('pick from gallery', (tester) async {
190
+      final editor = new EditorSandBox(tester: tester);
191
+      await editor.tapEditor();
192
+      await editor.tapButtonWithIcon(Icons.photo);
193
+      await editor.tapButtonWithIcon(Icons.photo_library);
194
+      expect(log, hasLength(1));
195
+      expect(
196
+        log.single,
197
+        isMethodCall(
198
+          'pickImage',
199
+          arguments: <String, dynamic>{
200
+            'source': 1,
201
+            'maxWidth': null,
202
+            'maxHeight': null,
203
+          },
204
+        ),
205
+      );
206
+    });
207
+  });
135 208
 }

+ 66
- 0
packages/zefyr/test/widgets/horizontal_rule_test.dart Прегледај датотеку

@@ -0,0 +1,66 @@
1
+// Copyright (c) 2018, the Zefyr project authors.  Please see the AUTHORS file
2
+// for details. All rights reserved. Use of this source code is governed by a
3
+// BSD-style license that can be found in the LICENSE file.
4
+import 'package:flutter/material.dart';
5
+import 'package:flutter_test/flutter_test.dart';
6
+import 'package:zefyr/zefyr.dart';
7
+
8
+import '../testing.dart';
9
+
10
+void main() {
11
+  group('$ZefyrHorizontalRule', () {
12
+    testWidgets('format as horizontal rule', (tester) async {
13
+      final editor = new EditorSandBox(tester: tester);
14
+      await editor.tapEditor();
15
+      await editor.tapButtonWithIcon(Icons.remove);
16
+
17
+      LineNode line = editor.document.root.children.last;
18
+      expect(line.hasEmbed, isTrue);
19
+    });
20
+
21
+    testWidgets('tap left side of horizontal rule puts caret before it',
22
+        (tester) async {
23
+      final editor = new EditorSandBox(tester: tester);
24
+      await editor.tapEditor();
25
+      await editor.tapButtonWithIcon(Icons.remove);
26
+      await editor.updateSelection(base: 0, extent: 0);
27
+
28
+      await tester.tapAt(tester.getTopLeft(find.byType(ZefyrHorizontalRule)));
29
+      LineNode line = editor.document.root.children.last;
30
+      EmbedNode embed = line.children.single;
31
+      expect(editor.selection.isCollapsed, isTrue);
32
+      expect(editor.selection.extentOffset, embed.documentOffset);
33
+    });
34
+
35
+    testWidgets('tap right side of horizontal rule puts caret after it',
36
+        (tester) async {
37
+      final editor = new EditorSandBox(tester: tester);
38
+      await editor.tapEditor();
39
+      await editor.tapButtonWithIcon(Icons.remove);
40
+      await editor.updateSelection(base: 0, extent: 0);
41
+
42
+      final hr = find.byType(ZefyrHorizontalRule);
43
+      final offset = tester.getBottomRight(hr) - new Offset(1.0, 1.0);
44
+      await tester.tapAt(offset);
45
+      LineNode line = editor.document.root.children.last;
46
+      EmbedNode embed = line.children.single;
47
+      expect(editor.selection.isCollapsed, isTrue);
48
+      expect(editor.selection.extentOffset, embed.documentOffset + 1);
49
+    });
50
+
51
+    testWidgets('selects on long press',
52
+        (tester) async {
53
+      final editor = new EditorSandBox(tester: tester);
54
+      await editor.tapEditor();
55
+      await editor.tapButtonWithIcon(Icons.remove);
56
+      await editor.updateSelection(base: 0, extent: 0);
57
+
58
+      final hr = find.byType(ZefyrHorizontalRule);
59
+      await tester.longPress(hr);
60
+      LineNode line = editor.document.root.children.last;
61
+      EmbedNode embed = line.children.single;
62
+      expect(editor.selection.baseOffset, embed.documentOffset);
63
+      expect(editor.selection.extentOffset, embed.documentOffset + 1);
64
+    });
65
+  });
66
+}

packages/zefyr/test/widgets/editable_paragraph_test.dart → packages/zefyr/test/widgets/rich_text_test.dart Прегледај датотеку