Skip to content
This repository was archived by the owner on Feb 22, 2018. It is now read-only.

Commit e1745c6

Browse files
committed
feat(jquery): Add shadowRoot() and use it in templateurl_spec
1 parent 91b8a6b commit e1745c6

File tree

3 files changed

+36
-12
lines changed

3 files changed

+36
-12
lines changed

test/_specs.dart

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -177,9 +177,14 @@ class JQuery extends DelegatingList<Node> {
177177
_toHtml(node, [bool outer = false]) {
178178
if (node is Comment) {
179179
return '<!--${node.text}-->';
180+
} else if (node is DocumentFragment) {
181+
var acc = '';
182+
node.childNodes.forEach((n) { acc += _toHtml(n, true); });
183+
return acc;
180184
} else if (node is Element) {
181185
// Remove all the "ng-binding" internal classes
182186
node = node.clone(true) as Element;
187+
node.classes.remove('ng-binding');
183188
node.queryAll(".ng-binding").forEach((Element e) {
184189
e.classes.remove('ng-binding');
185190
});
@@ -238,6 +243,7 @@ class JQuery extends DelegatingList<Node> {
238243
(Element n) => n.style.getPropertyValue(name),
239244
(Element n, v) => n.style.setProperty(name, value), value);
240245
children() => new JQuery(this[0].childNodes);
246+
shadowRoot() => new JQuery((this[0] as Element).shadowRoot);
241247
}
242248

243249

test/_specs_spec.dart

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,5 +41,23 @@ main() {
4141
expect(div.html()).toEqual('text');
4242
});
4343
});
44+
45+
describe('shadowRoot', () {
46+
it('should return the shadowRoot if one exists', () {
47+
var elts = $('<div></div>');
48+
elts[0].createShadowRoot().innerHtml = "Hello shadow";
49+
expect(elts.shadowRoot().text()).toEqual("Hello shadow");
50+
});
51+
52+
it('should return empty list if there is no shadowRoot', () {
53+
expect($('<div></div>').shadowRoot()).toEqual([]);
54+
});
55+
56+
it('should print the html for the shadowRoot', () {
57+
var elts = $('<div></div>');
58+
elts[0].createShadowRoot().innerHtml = '<div class="ng-binding">Hello shadow</div>';
59+
expect(elts.shadowRoot().html()).toEqual('<div>Hello shadow</div>');
60+
});
61+
});
4462
});
4563
}

test/core/templateurl_spec.dart

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -69,8 +69,8 @@ void main() {
6969
backend.flush();
7070
microLeap();
7171

72-
expect(renderedText(element)).toEqual('.hello{}Simple!');
73-
expect(element[0].nodes[0].shadowRoot.innerHtml).toEqual(
72+
expect(element.textWithShadow()).toEqual('.hello{}Simple!');
73+
expect(element.children().shadowRoot().html()).toEqual(
7474
'<style>.hello{}</style><div log="SIMPLE">Simple!</div>'
7575
);
7676
})));
@@ -98,7 +98,7 @@ void main() {
9898
backend.flush();
9999
microLeap();
100100

101-
expect(renderedText(element)).toEqual('Simple!');
101+
expect(element.textWithShadow()).toEqual('Simple!');
102102
$rootScope.apply();
103103
// Note: There is no ordering. It is who ever comes off the wire first!
104104
expect(log.result()).toEqual('LOG; SIMPLE');
@@ -119,7 +119,7 @@ void main() {
119119
backend.flush();
120120
microLeap();
121121

122-
expect(renderedText(element)).toEqual('Simple!Simple!');
122+
expect(element.textWithShadow()).toEqual('Simple!Simple!');
123123
$rootScope.apply();
124124
// Note: There is no ordering. It is who ever comes off the wire first!
125125
expect(log.result()).toEqual('LOG; LOG; SIMPLE; SIMPLE');
@@ -138,8 +138,8 @@ void main() {
138138
backend.flush();
139139
microLeap();
140140

141-
expect(renderedText(element)).toEqual('.hello{}Simple!');
142-
expect(element[0].nodes[0].shadowRoot.innerHtml).toEqual(
141+
expect(element.textWithShadow()).toEqual('.hello{}Simple!');
142+
expect(element.children().shadowRoot().html()).toEqual(
143143
'<style>.hello{}</style><div log="SIMPLE">Simple!</div>'
144144
);
145145
$rootScope.apply();
@@ -156,7 +156,7 @@ void main() {
156156

157157
backend.flush();
158158
microLeap();
159-
expect(renderedText(element)).toEqual('.hello{}inline!');
159+
expect(element.textWithShadow()).toEqual('.hello{}inline!');
160160
})));
161161

162162
it('should ignore CSS load errors ', async(inject(
@@ -168,7 +168,7 @@ void main() {
168168

169169
backend.flush();
170170
microLeap();
171-
expect(renderedText(element)).toEqual(
171+
expect(element.textWithShadow()).toEqual(
172172
'/*\n'
173173
'HTTP 500: some error\n'
174174
'*/\n'
@@ -184,7 +184,7 @@ void main() {
184184

185185
backend.flush();
186186
microLeap();
187-
expect(renderedText(element)).toEqual('.hello{}');
187+
expect(element.textWithShadow()).toEqual('.hello{}');
188188
})));
189189

190190
it('should load the CSS before the template is loaded', async(inject(
@@ -199,7 +199,7 @@ void main() {
199199

200200
backend.flush();
201201
microLeap();
202-
expect(renderedText(element)).toEqual('.hello{}Simple!');
202+
expect(element.textWithShadow()).toEqual('.hello{}Simple!');
203203
})));
204204
});
205205

@@ -224,8 +224,8 @@ void main() {
224224
backend.flush();
225225
microLeap();
226226

227-
expect(renderedText(element)).toEqual('.hello{}.world{}Simple!');
228-
expect(element[0].nodes[0].shadowRoot.innerHtml).toEqual(
227+
expect(element.textWithShadow()).toEqual('.hello{}.world{}Simple!');
228+
expect(element.children().shadowRoot().html()).toEqual(
229229
'<style>.hello{}.world{}</style><div log="SIMPLE">Simple!</div>'
230230
);
231231
$rootScope.apply();

0 commit comments

Comments
 (0)