|
1 | 1 | import { |
2 | | - ComponentFixture, |
3 | | - AsyncTestCompleter, |
4 | | - TestComponentBuilder, |
5 | | - beforeEach, |
6 | | - ddescribe, |
7 | | - xdescribe, |
8 | | - describe, |
9 | | - el, |
10 | | - expect, |
11 | | - iit, |
12 | | - inject, |
13 | | - beforeEachProviders, |
14 | | - it, |
15 | | - xit |
16 | | -} from 'angular2/testing_internal'; |
| 2 | + describeRouter, |
| 3 | + ddescribeRouter, |
| 4 | + describeWith, |
| 5 | + describeWithout, |
| 6 | + describeWithAndWithout, |
| 7 | + itShouldRoute |
| 8 | +} from './util'; |
17 | 9 |
|
18 | | -import {provide, Component, Injector, Inject} from 'angular2/core'; |
19 | | - |
20 | | -import {Router, ROUTER_DIRECTIVES, RouteParams, RouteData, Location} from 'angular2/router'; |
21 | | -import {RouteConfig, Route, AuxRoute, Redirect} from 'angular2/src/router/route_config_decorator'; |
22 | | - |
23 | | -import {TEST_ROUTER_PROVIDERS, RootCmp, compile, clickOnElement, getHref} from './util'; |
24 | | - |
25 | | -function getLinkElement(rtc: ComponentFixture) { |
26 | | - return rtc.debugElement.componentViewChildren[0].nativeElement; |
27 | | -} |
28 | | - |
29 | | -var cmpInstanceCount; |
30 | | -var childCmpInstanceCount; |
| 10 | +import {registerSpecs} from './impl/aux_route_spec_impl'; |
31 | 11 |
|
32 | 12 | export function main() { |
33 | | - describe('auxiliary routes', () => { |
34 | | - |
35 | | - var tcb: TestComponentBuilder; |
36 | | - var fixture: ComponentFixture; |
37 | | - var rtr; |
38 | | - |
39 | | - beforeEachProviders(() => TEST_ROUTER_PROVIDERS); |
40 | | - |
41 | | - beforeEach(inject([TestComponentBuilder, Router], (tcBuilder, router) => { |
42 | | - tcb = tcBuilder; |
43 | | - rtr = router; |
44 | | - childCmpInstanceCount = 0; |
45 | | - cmpInstanceCount = 0; |
46 | | - })); |
47 | | - |
48 | | - it('should recognize and navigate from the URL', inject([AsyncTestCompleter], (async) => { |
49 | | - compile(tcb, `main {<router-outlet></router-outlet>} | aux {<router-outlet name="modal"></router-outlet>}`) |
50 | | - .then((rtc) => {fixture = rtc}) |
51 | | - .then((_) => rtr.config([ |
52 | | - new Route({path: '/hello', component: HelloCmp, name: 'Hello'}), |
53 | | - new AuxRoute({path: '/modal', component: ModalCmp, name: 'Aux'}) |
54 | | - ])) |
55 | | - .then((_) => rtr.navigateByUrl('/hello(modal)')) |
56 | | - .then((_) => { |
57 | | - fixture.detectChanges(); |
58 | | - expect(fixture.debugElement.nativeElement).toHaveText('main {hello} | aux {modal}'); |
59 | | - async.done(); |
60 | | - }); |
61 | | - })); |
62 | | - |
63 | | - it('should navigate via the link DSL', inject([AsyncTestCompleter], (async) => { |
64 | | - compile(tcb, `main {<router-outlet></router-outlet>} | aux {<router-outlet name="modal"></router-outlet>}`) |
65 | | - .then((rtc) => {fixture = rtc}) |
66 | | - .then((_) => rtr.config([ |
67 | | - new Route({path: '/hello', component: HelloCmp, name: 'Hello'}), |
68 | | - new AuxRoute({path: '/modal', component: ModalCmp, name: 'Modal'}) |
69 | | - ])) |
70 | | - .then((_) => rtr.navigate(['/Hello', ['Modal']])) |
71 | | - .then((_) => { |
72 | | - fixture.detectChanges(); |
73 | | - expect(fixture.debugElement.nativeElement).toHaveText('main {hello} | aux {modal}'); |
74 | | - async.done(); |
75 | | - }); |
76 | | - })); |
| 13 | + registerSpecs(); |
77 | 14 |
|
78 | | - it('should generate a link URL', inject([AsyncTestCompleter], (async) => { |
79 | | - compile( |
80 | | - tcb, |
81 | | - `<a [routerLink]="['/Hello', ['Modal']]">open modal</a> | main {<router-outlet></router-outlet>} | aux {<router-outlet name="modal"></router-outlet>}`) |
82 | | - .then((rtc) => {fixture = rtc}) |
83 | | - .then((_) => rtr.config([ |
84 | | - new Route({path: '/hello', component: HelloCmp, name: 'Hello'}), |
85 | | - new AuxRoute({path: '/modal', component: ModalCmp, name: 'Modal'}) |
86 | | - ])) |
87 | | - .then((_) => { |
88 | | - fixture.detectChanges(); |
89 | | - expect(getHref(getLinkElement(fixture))).toEqual('/hello(modal)'); |
90 | | - async.done(); |
91 | | - }); |
92 | | - })); |
93 | | - |
94 | | - it('should navigate from a link click', |
95 | | - inject([AsyncTestCompleter, Location], (async, location) => { |
96 | | - compile( |
97 | | - tcb, |
98 | | - `<a [routerLink]="['/Hello', ['Modal']]">open modal</a> | main {<router-outlet></router-outlet>} | aux {<router-outlet name="modal"></router-outlet>}`) |
99 | | - .then((rtc) => {fixture = rtc}) |
100 | | - .then((_) => rtr.config([ |
101 | | - new Route({path: '/hello', component: HelloCmp, name: 'Hello'}), |
102 | | - new AuxRoute({path: '/modal', component: ModalCmp, name: 'Modal'}) |
103 | | - ])) |
104 | | - .then((_) => { |
105 | | - fixture.detectChanges(); |
106 | | - expect(fixture.debugElement.nativeElement) |
107 | | - .toHaveText('open modal | main {} | aux {}'); |
108 | | - |
109 | | - rtr.subscribe((_) => { |
110 | | - fixture.detectChanges(); |
111 | | - expect(fixture.debugElement.nativeElement) |
112 | | - .toHaveText('open modal | main {hello} | aux {modal}'); |
113 | | - expect(location.urlChanges).toEqual(['/hello(modal)']); |
114 | | - async.done(); |
115 | | - }); |
116 | | - |
117 | | - clickOnElement(getLinkElement(fixture)); |
118 | | - }); |
119 | | - })); |
| 15 | + describeRouter('aux routes', () => { |
| 16 | + itShouldRoute(); |
| 17 | + describeWith('a primary route', itShouldRoute); |
120 | 18 | }); |
121 | 19 | } |
122 | | - |
123 | | - |
124 | | -@Component({selector: 'hello-cmp', template: `{{greeting}}`}) |
125 | | -class HelloCmp { |
126 | | - greeting: string; |
127 | | - constructor() { this.greeting = 'hello'; } |
128 | | -} |
129 | | - |
130 | | -@Component({selector: 'modal-cmp', template: `modal`}) |
131 | | -class ModalCmp { |
132 | | -} |
133 | | - |
134 | | -@Component({ |
135 | | - selector: 'aux-cmp', |
136 | | - template: 'main {<router-outlet></router-outlet>} | ' + |
137 | | - 'aux {<router-outlet name="modal"></router-outlet>}', |
138 | | - directives: [ROUTER_DIRECTIVES], |
139 | | -}) |
140 | | -@RouteConfig([ |
141 | | - new Route({path: '/hello', component: HelloCmp, name: 'Hello'}), |
142 | | - new AuxRoute({path: '/modal', component: ModalCmp, name: 'Aux'}) |
143 | | -]) |
144 | | -class AuxCmp { |
145 | | -} |
0 commit comments