Skip to content
This repository was archived by the owner on Feb 26, 2024. It is now read-only.

Added inline annotation to controller definition #207

Closed
wants to merge 7 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions app/css/app.css
Original file line number Diff line number Diff line change
@@ -1 +1,6 @@
/* app css stylesheet */

body {
padding-top: 20px;
}

37 changes: 33 additions & 4 deletions app/index.html
Original file line number Diff line number Diff line change
@@ -1,12 +1,41 @@
<!doctype html>
<html lang="en">
<html lang="en" ng-app="phonecatApp">
<head>
<meta charset="utf-8">
<title>My HTML File</title>
<title>Google Phone Gallery</title>
<link rel="stylesheet" href="bower_components/bootstrap/dist/css/bootstrap.css">
<link rel="stylesheet" href="css/app.css">
<script src="bower_components/angular/angular.js"></script>
<script src="js/controllers.js"></script>
</head>
<body>
<body ng-controller="PhoneListCtrl">

<div class="container-fluid">
<div class="row">
<div class="col-md-2">
<!--Sidebar content-->

Search: <input ng-model="query">
Sort by:
<select ng-model="orderProp">
<option value="name">Alphabetical</option>
<option value="age">Newest</option>
</select>

</div>
<div class="col-md-10">
<!--Body content-->

<ul class="phones">
<li ng-repeat="phone in phones | filter:query | orderBy:orderProp">
<span>{{phone.name}}</span>
<p>{{phone.snippet}}</p>
</li>
</ul>

</div>
</div>
</div>

</body>
</html>
</html>
11 changes: 11 additions & 0 deletions app/js/controllers.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,14 @@
'use strict';

/* Controllers */

var phonecatApp = angular.module('phonecatApp', []);

phonecatApp.controller('PhoneListCtrl', ['$scope', '$http',
function($scope, $http) {
$http.get('phones/phones.json').success(function(data) {
$scope.phones = data;
});

$scope.orderProp = 'age';
}]);
53 changes: 49 additions & 4 deletions test/e2e/scenarios.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,55 @@

/* http://docs.angularjs.org/guide/dev_guide.e2e-testing */

describe('my app', function() {
describe('PhoneCat App', function() {

beforeEach(function() {
browser.get('app/index.html');
});
describe('Phone list view', function() {

beforeEach(function() {
browser.get('app/index.html');
});


it('should filter the phone list as a user types into the search box', function() {

var phoneList = element.all(by.repeater('phone in phones'));
var query = element(by.model('query'));

expect(phoneList.count()).toBe(20);

query.sendKeys('nexus');
expect(phoneList.count()).toBe(1);

query.clear();
query.sendKeys('motorola');
expect(phoneList.count()).toBe(8);
});


it('should be possible to control phone order via the drop down select box', function() {

var phoneNameColumn = element.all(by.repeater('phone in phones').column('{{phone.name}}'));
var query = element(by.model('query'));

function getNames() {
return phoneNameColumn.map(function(elm) {
return elm.getText();
});
}

query.sendKeys('tablet'); //let's narrow the dataset to make the test assertions shorter

expect(getNames()).toEqual([
"Motorola XOOM\u2122 with Wi-Fi",
"MOTOROLA XOOM\u2122"
]);

element(by.model('orderProp')).element(by.css('option[value="name"]')).click();

expect(getNames()).toEqual([
"MOTOROLA XOOM\u2122",
"Motorola XOOM\u2122 with Wi-Fi"
]);
});
});
});
28 changes: 25 additions & 3 deletions test/unit/controllersSpec.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,33 @@
'use strict';

/* jasmine specs for controllers go here */
describe('PhoneCat controllers', function() {

describe('controllers', function() {
describe('PhoneListCtrl', function(){
var scope, ctrl, $httpBackend;

it("should do something", function() {
beforeEach(module('phonecatApp'));
beforeEach(inject(function(_$httpBackend_, $rootScope, $controller) {
$httpBackend = _$httpBackend_;
$httpBackend.expectGET('phones/phones.json').
respond([{name: 'Nexus S'}, {name: 'Motorola DROID'}]);

});
scope = $rootScope.$new();
ctrl = $controller('PhoneListCtrl', {$scope: scope});
}));


it('should create "phones" model with 2 phones fetched from xhr', function() {
expect(scope.phones).toBeUndefined();
$httpBackend.flush();

expect(scope.phones).toEqual([{name: 'Nexus S'},
{name: 'Motorola DROID'}]);
});


it('should set the default value of orderProp model', function() {
expect(scope.orderProp).toBe('age');
});
});
});