|
@@ -0,0 +1,63 @@
|
|
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 'dart:ui';
|
|
5
|
+
|
|
6
|
+import 'package:flutter/material.dart';
|
|
7
|
+import 'package:flutter/rendering.dart';
|
|
8
|
+import 'package:flutter_test/flutter_test.dart';
|
|
9
|
+import 'package:zefyr/src/widgets/editable_box.dart';
|
|
10
|
+import 'package:zefyr/src/widgets/render_context.dart';
|
|
11
|
+import 'package:zefyr/src/widgets/rich_text.dart';
|
|
12
|
+import 'package:zefyr/zefyr.dart';
|
|
13
|
+
|
|
14
|
+void main() {
|
|
15
|
+ group('$RenderEditableProxyBox', () {
|
|
16
|
+ final doc = NotusDocument();
|
|
17
|
+ doc.insert(0, 'This House Is A Circus');
|
|
18
|
+ final text = TextSpan(text: 'This House Is A Circus');
|
|
19
|
+
|
|
20
|
+ ZefyrRenderContext renderContext;
|
|
21
|
+ RenderEditableProxyBox p;
|
|
22
|
+
|
|
23
|
+ setUp(() {
|
|
24
|
+ WidgetsFlutterBinding.ensureInitialized();
|
|
25
|
+ renderContext = ZefyrRenderContext();
|
|
26
|
+ final rt = RenderEditableParagraph(
|
|
27
|
+ text,
|
|
28
|
+ node: doc.root.children.first,
|
|
29
|
+ textDirection: TextDirection.ltr,
|
|
30
|
+ );
|
|
31
|
+ p = RenderEditableProxyBox(
|
|
32
|
+ child: rt,
|
|
33
|
+ node: doc.root.children.first,
|
|
34
|
+ layerLink: LayerLink(),
|
|
35
|
+ renderContext: renderContext,
|
|
36
|
+ showCursor: ValueNotifier<bool>(true),
|
|
37
|
+ selection: TextSelection.collapsed(offset: 0),
|
|
38
|
+ selectionColor: Color(0),
|
|
39
|
+ );
|
|
40
|
+ });
|
|
41
|
+
|
|
42
|
+ test('it registers with render context', () {
|
|
43
|
+ var owner = new PipelineOwner();
|
|
44
|
+ expect(renderContext.active, isNot(contains(p)));
|
|
45
|
+ p.attach(owner);
|
|
46
|
+ expect(renderContext.dirty, contains(p));
|
|
47
|
+ p.layout(BoxConstraints());
|
|
48
|
+ expect(renderContext.active, contains(p));
|
|
49
|
+
|
|
50
|
+ p.detach();
|
|
51
|
+ expect(renderContext.active, isNot(contains(p)));
|
|
52
|
+ p.attach(owner);
|
|
53
|
+ expect(renderContext.active, contains(p));
|
|
54
|
+
|
|
55
|
+ p.markNeedsLayout();
|
|
56
|
+ p.detach();
|
|
57
|
+ expect(renderContext.active, isNot(contains(p)));
|
|
58
|
+
|
|
59
|
+ p.layout(BoxConstraints());
|
|
60
|
+ expect(renderContext.active, contains(p));
|
|
61
|
+ });
|
|
62
|
+ });
|
|
63
|
+}
|