Skip to content

Commit b89c067

Browse files
committed
test(refactor): cleanup test to use the new UrlMapper
1 parent 0a2f6dd commit b89c067

File tree

4 files changed

+87
-106
lines changed

4 files changed

+87
-106
lines changed

modules/angular2/test/core/compiler/compiler_spec.ts

Lines changed: 11 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ export function main() {
6060

6161
function createCompiler(renderCompileResults: List<renderApi.ProtoViewDto>,
6262
protoViewFactoryResults: List<List<AppProtoView>>) {
63-
var urlResolver = new FakeUrlResolver();
63+
var urlResolver = new UrlResolver();
6464
renderCompileRequests = [];
6565
renderCompiler.spy('compile').andCallFake((view) => {
6666
renderCompileRequests.push(view);
@@ -111,17 +111,17 @@ export function main() {
111111

112112
it('should fill templateAbsUrl given inline templates',
113113
inject([AsyncTestCompleter], (async) => {
114-
cmpUrlMapper.setComponentUrl(MainComponent, '/mainComponent');
114+
cmpUrlMapper.setComponentUrl(MainComponent, '/cmp/main.js');
115115
captureTemplate(new viewAnn.View({template: '<div></div>'}))
116116
.then((renderTpl) => {
117-
expect(renderTpl.templateAbsUrl).toEqual('http://www.app.com/%3Cspan%20class="x x-first x-last">mainComponent');
117+
expect(renderTpl.templateAbsUrl).toEqual('http://www.app.com/%3Cspan%20class="x x-first x-last">cmp/main.js');
118118
async.done();
119119
});
120120
}));
121121

122122
it('should not fill templateAbsUrl given no inline template or template url',
123123
inject([AsyncTestCompleter], (async) => {
124-
cmpUrlMapper.setComponentUrl(MainComponent, '/mainComponent');
124+
cmpUrlMapper.setComponentUrl(MainComponent, '/cmp/main.js');
125125
captureTemplate(new viewAnn.View({template: null, templateUrl: null}))
126126
.then((renderTpl) => {
127127
expect(renderTpl.templateAbsUrl).toBe(null);
@@ -130,23 +130,23 @@ export function main() {
130130
}));
131131

132132
it('should fill templateAbsUrl given url template', inject([AsyncTestCompleter], (async) => {
133-
cmpUrlMapper.setComponentUrl(MainComponent, '/mainComponent');
134-
captureTemplate(new viewAnn.View({templateUrl: '/someTemplate'}))
133+
cmpUrlMapper.setComponentUrl(MainComponent, '/cmp/main.js');
134+
captureTemplate(new viewAnn.View({templateUrl: 'tpl/main.html'}))
135135
.then((renderTpl) => {
136136
expect(renderTpl.templateAbsUrl)
137-
.toEqual('http://www.app.com/%3Cspan%20class="x x-first x-last">mainComponent/someTemplate');
137+
.toEqual('http://www.app.com/%3Cspan%20class="x x-first x-last">cmp/tpl/main.html');
138138
async.done();
139139
});
140140
}));
141141

142142
it('should fill styleAbsUrls given styleUrls', inject([AsyncTestCompleter], (async) => {
143-
cmpUrlMapper.setComponentUrl(MainComponent, '/mainComponent');
144-
captureTemplate(new viewAnn.View({styleUrls: ['/1.css', '/2.css']}))
143+
cmpUrlMapper.setComponentUrl(MainComponent, '/cmp/main.js');
144+
captureTemplate(new viewAnn.View({styleUrls: ['css/1.css', 'css/2.css']}))
145145
.then((renderTpl) => {
146146
expect(renderTpl.styleAbsUrls)
147147
.toEqual([
148-
'http://www.app.com/%3Cspan%20class="x x-first x-last">mainComponent/1.css',
149-
'http://www.app.com/%3Cspan%20class="x x-first x-last">mainComponent/2.css'
148+
'http://www.app.com/%3Cspan%20class="x x-first x-last">cmp/css/1.css',
149+
'http://www.app.com/%3Cspan%20class="x x-first x-last">cmp/css/2.css'
150150
]);
151151
async.done();
152152
});
@@ -566,17 +566,10 @@ class SpyRenderCompiler extends SpyObject {
566566
noSuchMethod(m) { return super.noSuchMethod(m) }
567567
}
568568

569-
class FakeUrlResolver extends UrlResolver {
570-
constructor() { super(); }
571-
572-
resolve(baseUrl: string, url: string): string { return baseUrl + url; }
573-
}
574-
575569
class FakeAppRootUrl extends AppRootUrl {
576570
get value() { return 'http://www.app.com'; }
577571
}
578572

579-
580573
class FakeTemplateResolver extends TemplateResolver {
581574
_cmpViews: Map<Type, viewAnn.View> = new Map();
582575

modules/angular2/test/render/dom/compiler/style_url_resolver_spec.ts

Lines changed: 20 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,13 @@ import {UrlResolver} from 'angular2/src/services/url_resolver';
55

66
export function main() {
77
describe('StyleUrlResolver', () => {
8+
let styleUrlResolver;
9+
10+
beforeEach(() => {
11+
styleUrlResolver = new StyleUrlResolver(new UrlResolver());
12+
});
13+
814
it('should resolve "url()" urls', () => {
9-
var styleUrlResolver = new StyleUrlResolver(new FakeUrlResolver());
1015
var css = `
1116
.foo {
1217
background-image: url(http://github.com/"double.jpg");
@@ -15,64 +20,57 @@ export function main() {
1520
}`;
1621
var expectedCss = `
1722
.foo {
18-
background-image: url('http://github.com/%3Cspan%20class=%22x%20x-first%20x-last%22%3Ebase%3C/span%3E/double.jpg');
19-
background-image: url('http://github.com/%3Cspan%20class=%22x%20x-first%20x-last%22%3Ebase%3C/span%3E/simple.jpg');
20-
background-image: url('http://github.com/%3Cspan%20class=%22x%20x-first%20x-last%22%3Ebase%3C/span%3E/noquote.jpg');
23+
background-image: url('http://github.com/%3Cspan%20class=%22x%20x-first%20x-last%22%3Ehttp://ng.io%3C/span%3E/double.jpg');
24+
background-image: url('http://github.com/%3Cspan%20class=%22x%20x-first%20x-last%22%3Ehttp://ng.io%3C/span%3E/simple.jpg');
25+
background-image: url('http://github.com/%3Cspan%20class=%22x%20x-first%20x-last%22%3Ehttp://ng.io%3C/span%3E/noquote.jpg');
2126
}`;
2227

23-
var resolvedCss = styleUrlResolver.resolveUrls(css, 'base');
28+
var resolvedCss = styleUrlResolver.resolveUrls(css, 'http://ng.io');
2429
expect(resolvedCss).toEqual(expectedCss);
2530
});
2631

2732
it('should resolve "@import" urls', () => {
28-
var styleUrlResolver = new StyleUrlResolver(new FakeUrlResolver());
2933
var css = `
3034
@import '1.css';
3135
@import "2.css";
3236
`;
3337
var expectedCss = `
34-
@import 'http://github.com/%3Cspan%20class="x x-first x-last">base/1.css';
35-
@import 'http://github.com/%3Cspan%20class="x x-first x-last">base/2.css';
38+
@import 'http://github.com/%3Cspan%20class="x x-first x-last">http://ng.io/1.css';
39+
@import 'http://github.com/%3Cspan%20class="x x-first x-last">http://ng.io/2.css';
3640
`;
3741

38-
var resolvedCss = styleUrlResolver.resolveUrls(css, 'base');
42+
var resolvedCss = styleUrlResolver.resolveUrls(css, 'http://ng.io');
3943
expect(resolvedCss).toEqual(expectedCss);
4044
});
4145

4246
it('should resolve "@import url()" urls', () => {
43-
var styleUrlResolver = new StyleUrlResolver(new FakeUrlResolver());
4447
var css = `
4548
@import url(http://github.com/'3.css');
4649
@import url(http://github.com/"4.css");
4750
@import url(http://github.com/5.css);
4851
`;
4952
var expectedCss = `
50-
@import url('http://github.com/%3Cspan%20class=%22x%20x-first%20x-last%22%3Ebase%3C/span%3E/3.css');
51-
@import url('http://github.com/%3Cspan%20class=%22x%20x-first%20x-last%22%3Ebase%3C/span%3E/4.css');
52-
@import url('http://github.com/%3Cspan%20class=%22x%20x-first%20x-last%22%3Ebase%3C/span%3E/5.css');
53+
@import url('http://github.com/%3Cspan%20class=%22x%20x-first%20x-last%22%3Ehttp://ng.io%3C/span%3E/3.css');
54+
@import url('http://github.com/%3Cspan%20class=%22x%20x-first%20x-last%22%3Ehttp://ng.io%3C/span%3E/4.css');
55+
@import url('http://github.com/%3Cspan%20class=%22x%20x-first%20x-last%22%3Ehttp://ng.io%3C/span%3E/5.css');
5356
`;
5457

55-
var resolvedCss = styleUrlResolver.resolveUrls(css, 'base');
58+
var resolvedCss = styleUrlResolver.resolveUrls(css, 'http://ng.io');
5659
expect(resolvedCss).toEqual(expectedCss);
5760
});
5861

5962
it('should support media query in "@import"', () => {
60-
var styleUrlResolver = new StyleUrlResolver(new FakeUrlResolver());
6163
var css = `
6264
@import 'print.css' print;
6365
@import url(http://github.com/print.css) print;
6466
`;
6567
var expectedCss = `
66-
@import 'http://github.com/%3Cspan%20class="x x-first x-last">base/print.css' print;
67-
@import url('http://github.com/%3Cspan%20class=%22x%20x-first%20x-last%22%3Ebase%3C/span%3E/print.css') print;
68+
@import 'http://github.com/%3Cspan%20class="x x-first x-last">http://ng.io/print.css' print;
69+
@import url('http://github.com/%3Cspan%20class=%22x%20x-first%20x-last%22%3Ehttp://ng.io%3C/span%3E/print.css') print;
6870
`;
6971

70-
var resolvedCss = styleUrlResolver.resolveUrls(css, 'base');
72+
var resolvedCss = styleUrlResolver.resolveUrls(css, 'http://ng.io');
7173
expect(resolvedCss).toEqual(expectedCss);
7274
});
7375
});
7476
}
75-
76-
class FakeUrlResolver extends UrlResolver {
77-
resolve(baseUrl: string, url: string): string { return baseUrl + '/' + url; }
78-
}

0 commit comments

Comments
 (0)