Skip to content
This repository was archived by the owner on Dec 4, 2017. It is now read-only.

Commit ebb4297

Browse files
committed
add upgrade-phonecat-3-router, move final to upgrade-phonecat-4-final
1 parent aba181b commit ebb4297

File tree

146 files changed

+1672
-88
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

146 files changed

+1672
-88
lines changed

public/docs/_examples/upgrade-phonecat-3-final/ts/karma.conf.ng1.js

-74
This file was deleted.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
This is the Angular Phonecat application adjusted to fit our boilerplate project
2+
structure.
3+
4+
The following changes from vanilla Phonecat are applied:
5+
6+
* Karma config for unit tests is in karma.conf.ng1.js because the boilerplate
7+
Karma config is not compatible with the way Angular 1 tests need to be run.
8+
The shell script run-unit-tests.sh can be used to run the unit tests.
9+
* There's a `package.ng1.json`, which is not used to run anything but only to
10+
show an example of changing the PhoneCat http-server root path.
11+
* Also for the Karma shim, there is a `karma-test-shim.1.js` file which isn't
12+
used but is shown in the test appendix.
13+
* Instead of using Bower, Angular 1 and its dependencies are fetched from a CDN
14+
in index.html and karma.conf.ng1.js.
15+
* E2E tests have been moved to the parent directory, where `run-e2e-tests` can
16+
discover and run them along with all the other examples.
17+
* Most of the phone JSON and image data removed in the interest of keeping
18+
repo weight down. Keeping enough to retain testability of the app.
19+
20+
## Running the app
21+
22+
Start like any example
23+
24+
npm run start
25+
26+
## Running unit tests
27+
28+
./run-unit-tests.sh
29+
30+
## Running E2E tests
31+
32+
Like for any example (at the project root):
33+
34+
gulp run-e2e-tests --filter=phonecat-2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,107 @@
1+
'use strict'; // necessary for es6 output in node
2+
3+
import { browser, element, by } from 'protractor';
4+
import { setProtractorToHybridMode } from '../protractor-helpers';
5+
6+
// Angular E2E Testing Guide:
7+
// https://docs.angularjs.org/guide/e2e-testing
8+
9+
describe('PhoneCat Application', function() {
10+
11+
beforeAll(function () {
12+
setProtractorToHybridMode();
13+
});
14+
15+
it('should redirect `index.html` to `index.html#!/phones', function() {
16+
browser.get('index.html');
17+
expect(browser.getLocationAbsUrl()).toBe('/phones');
18+
});
19+
20+
xdescribe('View: Phone list', function() {
21+
22+
beforeEach(function() {
23+
browser.get('index.html#!/phones');
24+
});
25+
26+
it('should filter the phone list as a user types into the search box', function() {
27+
let phoneList = element.all(by.css('.phones li'));
28+
let query = element(by.css('input'));
29+
30+
expect(phoneList.count()).toBe(20);
31+
32+
query.sendKeys('nexus');
33+
expect(phoneList.count()).toBe(1);
34+
35+
query.clear();
36+
query.sendKeys('motorola');
37+
expect(phoneList.count()).toBe(8);
38+
});
39+
40+
it('should be possible to control phone order via the drop-down menu', function() {
41+
let queryField = element(by.css('input'));
42+
let orderSelect = element(by.css('select'));
43+
let nameOption = orderSelect.element(by.css('option[value="name"]'));
44+
let phoneNameColumn = element.all(by.css('.phones .name'));
45+
46+
function getNames() {
47+
return phoneNameColumn.map(function(elem) {
48+
return elem.getText();
49+
});
50+
}
51+
52+
queryField.sendKeys('tablet'); // Let's narrow the dataset to make the assertions shorter
53+
54+
expect(getNames()).toEqual([
55+
'Motorola XOOM\u2122 with Wi-Fi',
56+
'MOTOROLA XOOM\u2122'
57+
]);
58+
59+
nameOption.click();
60+
61+
expect(getNames()).toEqual([
62+
'MOTOROLA XOOM\u2122',
63+
'Motorola XOOM\u2122 with Wi-Fi'
64+
]);
65+
});
66+
67+
it('should render phone specific links', function() {
68+
let query = element(by.css('input'));
69+
query.sendKeys('nexus');
70+
71+
element.all(by.css('.phones li a')).first().click();
72+
browser.sleep(200); // Not sure why this is needed but it is. The route change works fine.
73+
expect(browser.getLocationAbsUrl()).toBe('/phones/nexus-s');
74+
});
75+
76+
});
77+
78+
xdescribe('View: Phone detail', function() {
79+
80+
beforeEach(function() {
81+
browser.get('index.html#!/phones/nexus-s');
82+
});
83+
84+
it('should display the `nexus-s` page', function() {
85+
expect(element(by.css('h1')).getText()).toBe('Nexus S');
86+
});
87+
88+
it('should display the first phone image as the main phone image', function() {
89+
let mainImage = element(by.css('img.phone.selected'));
90+
91+
expect(mainImage.getAttribute('src')).toMatch(/img\/phones\/nexus-s.0.jpg/);
92+
});
93+
94+
it('should swap the main image when clicking on a thumbnail image', function() {
95+
let mainImage = element(by.css('img.phone.selected'));
96+
let thumbnails = element.all(by.css('.phone-thumbs img'));
97+
98+
thumbnails.get(2).click();
99+
expect(mainImage.getAttribute('src')).toMatch(/img\/phones\/nexus-s.2.jpg/);
100+
101+
thumbnails.get(0).click();
102+
expect(mainImage.getAttribute('src')).toMatch(/img\/phones\/nexus-s.0.jpg/);
103+
});
104+
105+
});
106+
107+
});
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
**/*.js
2+
aot/**/*
3+
!aot/bs-config.json
4+
!aot/index.html
5+
!copy-dist-files.js
6+
!rollup-config.js
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"port": 8000,
3+
"files": ["./aot/**/*.{html,htm,css,js}"],
4+
"server": { "baseDir": "./aot" }
5+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
<!-- #docregion -->
2+
<!doctype html>
3+
<html lang="en">
4+
<head>
5+
<meta charset="utf-8">
6+
7+
<base href="/app/">
8+
9+
<title>Google Phone Gallery</title>
10+
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" />
11+
<link rel="stylesheet" href="app.css" />
12+
<link rel="stylesheet" href="app.animations.css" />
13+
14+
<script src="https://code.jquery.com/jquery-2.2.4.js"></script>
15+
<script src="https://code.angularjs.org/1.5.5/angular.js"></script>
16+
<script src="https://code.angularjs.org/1.5.5/angular-animate.js"></script>
17+
<script src="https://code.angularjs.org/1.5.5/angular-resource.js"></script>
18+
<script src="https://code.angularjs.org/1.5.5/angular-route.js"></script>
19+
20+
<script src="app.module.ng1.js"></script>
21+
<script src="app.config.js"></script>
22+
<script src="app.animations.js"></script>
23+
<script src="core/core.module.js"></script>
24+
<script src="core/phone/phone.module.js"></script>
25+
<script src="phone-list/phone-list.module.js"></script>
26+
<script src="phone-detail/phone-detail.module.js"></script>
27+
28+
<script src="/node_modules/core-js/client/shim.min.js"></script>
29+
<script src="/node_modules/zone.js/dist/zone.min.js"></script>
30+
31+
<script>window.module = 'aot';</script>
32+
</head>
33+
34+
<body>
35+
<phonecat-app></phonecat-app>
36+
</body>
37+
<script src="/dist/build.js"></script>
38+
</html>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
/* Animate `ngRepeat` in `phoneList` component */
2+
.phone-list-item.ng-enter,
3+
.phone-list-item.ng-leave,
4+
.phone-list-item.ng-move {
5+
overflow: hidden;
6+
transition: 0.5s linear all;
7+
}
8+
9+
.phone-list-item.ng-enter,
10+
.phone-list-item.ng-leave.ng-leave-active,
11+
.phone-list-item.ng-move {
12+
height: 0;
13+
margin-bottom: 0;
14+
opacity: 0;
15+
padding-bottom: 0;
16+
padding-top: 0;
17+
}
18+
19+
.phone-list-item.ng-enter.ng-enter-active,
20+
.phone-list-item.ng-leave,
21+
.phone-list-item.ng-move.ng-move-active {
22+
height: 120px;
23+
margin-bottom: 20px;
24+
opacity: 1;
25+
padding-bottom: 4px;
26+
padding-top: 15px;
27+
}
28+
29+
/* Animate view transitions with `ngView` */
30+
.view-container {
31+
position: relative;
32+
}
33+
34+
.view-frame {
35+
margin-top: 20px;
36+
}
37+
38+
.view-frame.ng-enter,
39+
.view-frame.ng-leave {
40+
background: white;
41+
left: 0;
42+
position: absolute;
43+
right: 0;
44+
top: 0;
45+
}
46+
47+
.view-frame.ng-enter {
48+
animation: 1s fade-in;
49+
z-index: 100;
50+
}
51+
52+
.view-frame.ng-leave {
53+
animation: 1s fade-out;
54+
z-index: 99;
55+
}
56+
57+
@keyframes fade-in {
58+
from { opacity: 0; }
59+
to { opacity: 1; }
60+
}
61+
62+
@keyframes fade-out {
63+
from { opacity: 1; }
64+
to { opacity: 0; }
65+
}
66+
67+
/* Older browsers might need vendor-prefixes for keyframes and animation! */
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
'use strict';
2+
3+
angular.
4+
module('phonecatApp').
5+
animation('.phone', function phoneAnimationFactory() {
6+
return {
7+
addClass: animateIn,
8+
removeClass: animateOut
9+
};
10+
11+
function animateIn(element: JQuery, className: string, done: () => void) {
12+
if (className !== 'selected') { return; }
13+
14+
element.css({
15+
display: 'block',
16+
position: 'absolute',
17+
top: 500,
18+
left: 0
19+
}).animate({
20+
top: 0
21+
}, done);
22+
23+
return function animateInEnd(wasCanceled: boolean) {
24+
if (wasCanceled) { element.stop(); }
25+
};
26+
}
27+
28+
function animateOut(element: JQuery, className: string, done: () => void) {
29+
if (className !== 'selected') { return; }
30+
31+
element.css({
32+
position: 'absolute',
33+
top: 0,
34+
left: 0
35+
}).animate({
36+
top: -500
37+
}, done);
38+
39+
return function animateOutEnd(wasCanceled: boolean) {
40+
if (wasCanceled) { element.stop(); }
41+
};
42+
}
43+
});
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
// #docregion
2+
import { Component } from '@angular/core';
3+
4+
@Component({
5+
selector: 'phonecat-app',
6+
template: `
7+
<div class="view-container">
8+
<router-outlet class="view-frame"></router-outlet>
9+
<div ng-view class="view-frame"></div>
10+
</div>
11+
`
12+
})
13+
export class AppComponent { }

0 commit comments

Comments
 (0)