@@ -16,17 +16,37 @@ class SimpleUrlComponent {
16
16
attach (Scope scope) {}
17
17
}
18
18
19
+ class HtmlAndCssComponent {
20
+ static String $templateUrl = 'simple.html' ;
21
+ static String $cssUrl = 'simple.css' ;
22
+ attach (Scope scope) {}
23
+ }
24
+
25
+ class InlineWithCssComponent {
26
+ static String $template = '<div>inline!</div>' ;
27
+ static String $cssUrl = 'simple.css' ;
28
+ attach (Scope scope) {}
29
+ }
30
+
31
+ class OnlyCssComponent {
32
+ static String $cssUrl = 'simple.css' ;
33
+ attach (Scope scope) {}
34
+ }
35
+
19
36
main () {
20
- describe ('templateUrl ' , () {
37
+ describe ('async template loading ' , () {
21
38
beforeEach (module ((module) {
22
39
var mockHttp = new MockHttp ();
23
40
module.value (MockHttp , mockHttp);
24
41
module.value (Http , mockHttp);
25
42
module.directive (LogAttrDirective );
26
43
module.directive (SimpleUrlComponent );
44
+ module.directive (HtmlAndCssComponent );
45
+ module.directive (OnlyCssComponent );
46
+ module.directive (InlineWithCssComponent );
27
47
}));
28
48
29
- it ('should replace element with template from url' , inject ((MockHttp $http, Compiler $compile, Scope $rootScope, Log log) {
49
+ it ('should replace element with template from url' , inject ((MockHttp $http, Compiler $compile, Scope $rootScope, Log log) {
30
50
$http.expectGET ('simple.html' , '<div log="SIMPLE">Simple!</div>' );
31
51
32
52
var element = $('<div><simple-url log>ignore</replace><div>' );
@@ -37,7 +57,49 @@ main() {
37
57
// Note: There is no ordering. It is who ever comes off the wire first!
38
58
expect (log.result ()).toEqual ('LOG; SIMPLE' );
39
59
}));
60
+ }));
61
+
62
+ it ('should load a CSS file into a style' , inject ((MockHttp $http, Compiler $compile, Scope $rootScope, Log log) {
63
+ $http.expectGET ('simple.html' , '<div log="SIMPLE">Simple!</div>' );
64
+
65
+ var element = $('<div><html-and-css log>ignore</html-and-css><div>' );
66
+ $compile (element)(element)..attach ($rootScope);
67
+
68
+ $http.flush ().then (expectAsync1 ((data) {
69
+ expect (renderedText (element)).toEqual ('@import "simple.css"Simple!' );
70
+ expect (element[0 ].nodes[0 ].shadowRoot.innerHtml).toEqual (
71
+ '<style>@import "simple.css"</style><div log="SIMPLE">Simple!</div>'
72
+ );
73
+ // Note: There is no ordering. It is who ever comes off the wire first!
74
+ expect (log.result ()).toEqual ('LOG; SIMPLE' );
75
+ }));
76
+ }));
77
+
78
+ it ('should load a CSS file with a \$ template' , inject ((Compiler $compile, Scope $rootScope) {
79
+ var element = $('<div><inline-with-css log>ignore</inline-with-css><div>' );
80
+ $compile (element)(element)..attach ($rootScope);
81
+ expect (renderedText (element)).toEqual ('@import "simple.css"inline!' );
82
+ }));
83
+
84
+ it ('should load a CSS with no template' , inject ((Compiler $compile, Scope $rootScope) {
85
+ var element = $('<div><only-css log>ignore</only-css><div>' );
86
+ $compile (element)(element)..attach ($rootScope);
40
87
88
+ expect (renderedText (element)).toEqual ('@import "simple.css"' );
89
+ }));
90
+
91
+ it ('should load the CSS before the template is loaded' , inject ((MockHttp $http, Compiler $compile, Scope $rootScope) {
92
+ $http.expectGET ('simple.html' , '<div>Simple!</div>' );
93
+
94
+ var element = $('<html-and-css>ignore</html-and-css>' );
95
+ $compile (element)(element)..attach ($rootScope);
96
+
97
+ // The HTML is not loaded yet, but the CSS @import should be in the DOM.
98
+ expect (renderedText (element)).toEqual ('@import "simple.css"' );
99
+
100
+ $http.flush ().then (expectAsync1 ((data) {
101
+ expect (renderedText (element)).toEqual ('@import "simple.css"Simple!' );
102
+ }));
41
103
}));
42
104
});
43
105
}
0 commit comments