Skip to content

Commit 5aa54af

Browse files
test(integration): Wire up ui-router example
1 parent 38cd10b commit 5aa54af

File tree

16 files changed

+344
-125
lines changed

16 files changed

+344
-125
lines changed

test-angular-versions/v6/cypress.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"baseUrl": "http://localhost:4000",
3+
"videoRecording": false
4+
}
Lines changed: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
1+
describe('Angular v6 app', () => {
2+
beforeEach(() => {
3+
window.sessionStorage.clear();
4+
});
5+
6+
it('loads', () => {
7+
cy.visit('');
8+
});
9+
10+
it('loads home state by default', () => {
11+
cy.visit('');
12+
cy.url().should('include', '/home');
13+
});
14+
15+
it('renders uisref as links', () => {
16+
cy.visit('');
17+
cy.get('a').contains('home');
18+
cy.get('a').contains('about');
19+
cy.get('a').contains('lazy');
20+
cy.get('a').contains('lazy.child');
21+
cy.get('a').contains('lazy.child.viewtarget');
22+
});
23+
24+
it('renders home', () => {
25+
cy.visit('/home');
26+
cy
27+
.get('a')
28+
.contains('home')
29+
.should('have.class', 'active');
30+
cy
31+
.get('a')
32+
.contains('about')
33+
.should('not.have.class', 'active');
34+
cy.get('#default').contains('home works');
35+
});
36+
37+
it('renders about', () => {
38+
cy.visit('/home');
39+
cy.visit('/about');
40+
cy
41+
.get('a')
42+
.contains('home')
43+
.should('not.have.class', 'active');
44+
cy
45+
.get('a')
46+
.contains('about')
47+
.should('have.class', 'active');
48+
cy.get('#default').contains('about works');
49+
});
50+
51+
it('loads lazy routes', () => {
52+
cy.visit('/home');
53+
cy.visit('/lazy');
54+
cy
55+
.get('a')
56+
.contains('home')
57+
.should('not.have.class', 'active');
58+
cy
59+
.get('a')
60+
.contains('lazy')
61+
.should('have.class', 'active');
62+
cy.get('#default').contains('lazy works');
63+
});
64+
65+
it('routes to lazy routes', () => {
66+
cy.visit('/lazy');
67+
cy
68+
.get('a')
69+
.contains('home')
70+
.should('not.have.class', 'active');
71+
cy
72+
.get('a')
73+
.contains('lazy')
74+
.should('have.class', 'active');
75+
cy.get('#default').contains('lazy works');
76+
});
77+
78+
it('routes to lazy child routes', () => {
79+
cy.visit('/lazy/child');
80+
cy
81+
.get('a')
82+
.contains('home')
83+
.should('not.have.class', 'active');
84+
cy
85+
.get('a')
86+
.contains('lazy.child')
87+
.should('have.class', 'active');
88+
cy.get('#default').contains('lazy.child works');
89+
});
90+
91+
it('targets named views', () => {
92+
cy.visit('/lazy/child/viewtarget');
93+
cy
94+
.get('a')
95+
.contains('home')
96+
.should('not.have.class', 'active');
97+
cy
98+
.get('a')
99+
.contains('lazy.child')
100+
.should('have.class', 'active');
101+
cy.get('#default').contains('lazy.child works');
102+
cy.get('#header').contains('lazy.child.viewtarget works');
103+
cy.get('#footer').contains('lazy.child.viewtarget works');
104+
});
105+
});

test/angular-versions/v6/package.json

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33
"version": "0.0.0",
44
"scripts": {
55
"ng": "ng",
6-
"start": "ng serve",
7-
"build": "ng build",
6+
"start": "ng serve --prod --source-map",
7+
"build": "ng build --prod --source-map",
88
"test": "ng test",
99
"lint": "ng lint",
1010
"e2e": "ng e2e"
@@ -20,15 +20,15 @@
2020
"@angular/platform-browser": "^6.0.0",
2121
"@angular/platform-browser-dynamic": "^6.0.0",
2222
"@angular/router": "^6.0.0",
23+
"@uirouter/angular": "^1.1.0",
2324
"core-js": "^2.5.4",
2425
"rxjs": "^6.0.0",
2526
"zone.js": "^0.8.26"
2627
},
2728
"devDependencies": {
28-
"@angular/compiler-cli": "^6.0.0",
2929
"@angular-devkit/build-angular": "~0.6.0",
30-
"typescript": "~2.7.2",
3130
"@angular/cli": "~6.0.0",
31+
"@angular/compiler-cli": "^6.0.0",
3232
"@angular/language-service": "^6.0.0",
3333
"@types/jasmine": "~2.8.6",
3434
"@types/jasminewd2": "~2.0.3",
@@ -43,6 +43,7 @@
4343
"karma-jasmine-html-reporter": "^0.2.2",
4444
"protractor": "~5.3.0",
4545
"ts-node": "~5.0.1",
46-
"tslint": "~5.9.1"
46+
"tslint": "~5.9.1",
47+
"typescript": "~2.7.2"
4748
}
48-
}
49+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import { Component } from '@angular/core';
2+
3+
@Component({
4+
selector: 'app-about',
5+
template: `<p>about works!</p>`,
6+
})
7+
export class AboutComponent {}

test/angular-versions/v6/src/app/app.component.css

Whitespace-only changes.

test/angular-versions/v6/src/app/app.component.html

Lines changed: 0 additions & 20 deletions
This file was deleted.

test/angular-versions/v6/src/app/app.component.spec.ts

Lines changed: 0 additions & 25 deletions
This file was deleted.
Lines changed: 35 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,40 @@
11
import { Component } from '@angular/core';
22

3+
const template = `
4+
<ui-view name="header" id="header"></ui-view>
5+
6+
<div class="app">
7+
<img width="300" alt="Angular Logo" src="data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHZpZXdCb3g9IjAgMCAyNTAgMjUwIj4KICAgIDxwYXRoIGZpbGw9IiNERDAwMzEiIGQ9Ik0xMjUgMzBMMzEuOSA2My4ybDE0LjIgMTIzLjFMMTI1IDIzMGw3OC45LTQzLjcgMTQuMi0xMjMuMXoiIC8+CiAgICA8cGF0aCBmaWxsPSIjQzMwMDJGIiBkPSJNMTI1IDMwdjIyLjItLjFWMjMwbDc4LjktNDMuNyAxNC4yLTEyMy4xTDEyNSAzMHoiIC8+CiAgICA8cGF0aCAgZmlsbD0iI0ZGRkZGRiIgZD0iTTEyNSA1Mi4xTDY2LjggMTgyLjZoMjEuN2wxMS43LTI5LjJoNDkuNGwxMS43IDI5LjJIMTgzTDEyNSA1Mi4xem0xNyA4My4zaC0zNGwxNy00MC45IDE3IDQwLjl6IiAvPgogIDwvc3ZnPg==">
8+
9+
<div>
10+
11+
<a uiSref="home" uiSrefActive="active">home</a>
12+
<a uiSref="about" uiSrefActive="active">about</a>
13+
<a uiSref="lazy" uiSrefActiveEq="active">lazy</a>
14+
<a uiSref="lazy.child" uiSrefActive="active">lazy.child</a>
15+
<a uiSref="lazy.child.viewtarget" uiSrefActive="active">lazy.child.viewtarget</a>
16+
</div>
17+
18+
<ui-view id="default"></ui-view>
19+
</div>
20+
21+
<ui-view name="footer" id="footer"></ui-view>
22+
`;
23+
324
@Component({
425
selector: 'app-root',
5-
templateUrl: './app.component.html',
6-
styleUrls: ['./app.component.css'],
26+
template: template,
27+
styles: [
28+
`
29+
.app {
30+
text-align: center;
31+
border: 1px solid;
32+
}
33+
34+
.active {
35+
font-weight: bold;
36+
}
37+
`,
38+
],
739
})
8-
export class AppComponent {
9-
title = 'app';
10-
}
40+
export class AppComponent {}
Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,26 @@
11
import { BrowserModule } from '@angular/platform-browser';
2-
import { NgModule } from '@angular/core';
2+
import { NgModule, NgModuleFactoryLoader, SystemJsNgModuleLoader } from '@angular/core';
3+
import { UIRouterModule } from '@uirouter/angular';
4+
import { UIRouter } from '@uirouter/core';
35

46
import { AppComponent } from './app.component';
7+
import { HomeComponent } from './home.component';
8+
import { AboutComponent } from './about.component';
9+
10+
export const states = [
11+
{ name: 'home', url: '/home', component: HomeComponent },
12+
{ name: 'about', url: '/about', component: AboutComponent },
13+
{ name: 'lazy.**', url: '/lazy', loadChildren: './lazy/lazy.module#LazyModule' },
14+
];
15+
16+
export function config(router: UIRouter) {
17+
router.urlService.rules.initial({ state: 'home' });
18+
}
519

620
@NgModule({
7-
declarations: [AppComponent],
8-
imports: [BrowserModule],
9-
providers: [],
21+
imports: [BrowserModule, UIRouterModule.forRoot({ states, config })],
22+
providers: [{ provide: NgModuleFactoryLoader, useClass: SystemJsNgModuleLoader }],
23+
declarations: [AppComponent, HomeComponent, AboutComponent],
1024
bootstrap: [AppComponent],
1125
})
1226
export class AppModule {}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import { Component } from '@angular/core';
2+
3+
@Component({
4+
selector: 'app-home',
5+
template: `<p>home works!</p>`,
6+
})
7+
export class HomeComponent {}

0 commit comments

Comments
 (0)