forked from dart-archive/angular.dart
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathnode_cursor_spec.dart
More file actions
78 lines (57 loc) · 2.17 KB
/
Copy pathnode_cursor_spec.dart
File metadata and controls
78 lines (57 loc) · 2.17 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
import '_specs.dart';
$(html) {
var body = new BodyElement();
body.innerHtml = html;
return body.nodes;
}
main() {
describe('NodeCursor', () {
var a, b, c, d;
beforeEach(() {
a = $('<a>A</a>')[0];
b = $('<b>B</b>')[0];
c = $('<i>C</i>')[0];
d = $('<span></span>')[0];
d.append(a);
d.append(b);
});
it('should allow single level traversal', () {
var cursor = new NodeCursor([a, b]);
expect(cursor.nodeList(), equals([a]));
expect(cursor.microNext(), equals(true));
expect(cursor.nodeList(), equals([b]));
expect(cursor.microNext(), equals(false));
});
it('should descend and ascend', () {
var cursor = new NodeCursor([d, c]);
expect(cursor.descend(), equals(true));
expect(cursor.nodeList(), equals([a]));
expect(cursor.microNext(), equals(true));
expect(cursor.nodeList(), equals([b]));
expect(cursor.microNext(), equals(false));
cursor.ascend();
expect(cursor.microNext(), equals(true));
expect(cursor.nodeList(), equals([c]));
expect(cursor.microNext(), equals(false));
});
it('should create child cursor upon replace of top level', () {
var parentCursor = new NodeCursor([a]);
var childCursor = parentCursor.replaceWithAnchor('child');
expect(parentCursor.elements.length, equals(1));
expect(STRINGIFY(parentCursor.elements[0]), equals('<!--ANCHOR: child-->'));
expect(childCursor.elements, equals([a]));
var leafCursor = childCursor.replaceWithAnchor('leaf');
expect(childCursor.elements.length, equals(1));
expect(STRINGIFY(childCursor.elements[0]), equals('<!--ANCHOR: leaf-->'));
expect(leafCursor.elements, equals([a]));
});
it('should create child cursor upon replace of mid level', () {
var dom = $('<div><span>text</span></div>');
var parentCursor = new NodeCursor(dom);
parentCursor.descend(); // <span>
var childCursor = parentCursor.replaceWithAnchor('child');
expect(STRINGIFY(dom), equals('[<div><!--ANCHOR: child--></div>]'));
expect(STRINGIFY(childCursor.elements[0]), equals('<span>text</span>'));
});
});
}