Skip to content
Open
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
117 changes: 117 additions & 0 deletions client/demo/ex/assignment1/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
<html ng-app>
<head>
<script src="/bower_components/jquery/dist/jquery.js"></script>
<script src="/bower_components/angular/angular.js"></script>
<script src="/bower_components/bootstrap/dist/js/bootstrap.js"></script>
<script src="/bower_components/angular-bootstrap/ui-bootstrap-tpls.js"></script>
<link rel="stylesheet" href="/bower_components/bootstrap/dist/css/bootstrap.css">
<title>Expense App Assignment1</title>
</head>
<body>
<div class="container"
ng-init="
expenses = [];
types= ['food', 'transportation', 'lodging', 'financial', 'sales', 'other.'];
isEditing = false;
index = -1;">
<h1>Expenses</h1>
<div class="create_expense">
<!-- <form name="expenseForm" ng-init="expense = {};"> -->
<form ng-init="expense = {};">
<h4>Create Expense</h4>
<div class="row">
<div class="col-sm-6 col-sm-offset-3">
<input type="text" hidden ng-model="expense.id" />
<div class="form-group">
<input type="date" class="form-control" placeholder="Date" ng-model="expense.date" />
</div>
<div class="form-group">
<select id="type" name="type" class="form-control" ng-model="expense.type" ng-options="option for option in types track by option">
<option value="">-- Select type --</option>
</select>
</div>
<div class="form-group">
<input type="text" class="form-control" placeholder="Description" ng-model="expense.description" />
</div>
<div class="form-group">
<input type="number" class="form-control" placeholder="Amount" ng-model="expense.amount" />
</div>
<div>
<input type="button" id="create-button" value="Create" class="btn btn-primary"
ng-click="expense.id = (expenses.length)+1;
expenses.push(expense);
expense = {};"
ng-hide="isEditing">
<input type="button" id="update-button" value="Update" class="btn btn-primary"
ng-click="expenses[index] = expense;;
expense = {};
isEditing = false;"
ng-show="isEditing">
<input type="button" id="cancel-button" value="Cancel" class="btn btn-primary"
ng-click="expense = {};
isEditing = false;"
ng-show="isEditing">
</div>
</div>
</div>
</form>
</div>
<div class="display_expenses">
<table class="table items">
<thead>
<th>Date</th>
<th>Type</th>
<th>Description</th>
<th>Amount</th>
</thead>
<tbody>
<tr ng-repeat="exp in expenses track by exp.id">
<td>{{ exp.date | date: 'MM/dd/yy'}}</td>
<td>{{ exp.type }}</td>
<td>{{ exp.description }}</td>
<td>{{ exp.amount }}</td>
<td>
<button class="btn btn-default edit-expense"
ng-click="$parent.expense = exp;
$parent.isEditing = true;
$parent.index = expenses.indexOf(exp);">
<i class="glyphicon glyphicon-pencil"></i>
</button>
<button class="btn btn-default delete-expense"
ng-click="expenses.splice(expenses.indexOf(exp),1)">
<i class="glyphicon glyphicon-trash"></i>
</button>
</td>
</tr>
</tbody>
</table>
<hr>
<div class="row">
<h3>Totals by Type</h3>
<div class="col-sm-6 col-sm-offset-3">
<table class="table" id="totals_table">
<thead>
<th>Type</th>
<th>Total</th>
</thead>
<tbody>
<tr ng-repeat="type in types">
<td>{{type}}</td>
<td ng-init="total=0;"
ng-repeat="exp in expenses | filter: type">{{ exp.amount + total }}
</td>
</tr>
</tbody>
</table>
</div>
</div>
<h3>Total All Types</h3>
<div class="row">
<div class="col-sm-6 col-sm-offset-3">
<p ng-init="total=0;" ng-repeat="exp in expenses">{{ exp.amount + total}}</p>
</div>
</div>
</div>
</div>
</body>
</html>
76 changes: 76 additions & 0 deletions e2e/ex/main.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
'use strict';

describe('Expenses app', function () {
var page;
beforeEach(function () {
browser.get('/demo/ex/assignment1/');
page = {};
});

it('should include H1 title', function () {
expect(element(by.tagName('h1')).getText()).to.eventually.equal('Expenses');
});

it('should add/edit/delete an item from/to the table', function () {
page.date = element(by.model('expense.date'));
page.date.sendKeys('09/06/1988');

page.type = element(by.cssContainingText('option', 'transportation')).click();
page.description = element(by.model('expense.description')).sendKeys('Testing Expense');
page.amount = element(by.model('expense.amount')).sendKeys('1000');

page.button = element(by.id('create-button'));
page.button.click();

//Quantity
var items = element.all(by.repeater('exp in expensGIT STATUes track by exp.id'));
expect(items.count()).to.eventually.equal(1);

//Check content
element(by.css('.table.items')).all(by.css('tbody tr')).then(function (rows) {
return rows[0].$$('td').then(function (cols) {
expect(cols[0].getText()).to.eventually.equal('09/06/88');
expect(cols[1].getText()).to.eventually.equal('transportation');
expect(cols[2].getText()).to.eventually.equal('Testing Expense');
expect(cols[3].getText()).to.eventually.equal('1000');
});
});

//Check if fields were cleaned
expect(page.date.getAttribute('value')).to.eventually.equal('');
expect(page.description.getAttribute('value')).to.eventually.equal('');
expect(page.amount.getAttribute('value')).to.eventually.equal('');

//Edit
var items = element.all(by.repeater('exp in expenses track by exp.id'));
items.first().then(function () {
page.button = element(by.css('.edit-expense'));
page.button.click();
});

page.date = element(by.model('expense.date'));
page.date.sendKeys('01/01/2015');

page.button = element(by.id('update-button'));
page.button.click();

element(by.css('.table.items')).all(by.css('tbody tr')).then(function (rows) {
return rows[0].$$('td').then(function (cols) {
expect(cols[0].getText()).to.eventually.equal('01/01/15');
expect(cols[1].getText()).to.eventually.equal('transportation');
expect(cols[2].getText()).to.eventually.equal('Testing Expense');
expect(cols[3].getText()).to.eventually.equal('1000');
});
});

//Delete
var items = element.all(by.repeater('exp in expenses track by exp.id'));
items.first().then(function () {
page.button = element(by.css('.delete-expense'));
page.button.click();
});

expect(element.all(by.repeater('exp in expenses track by exp.id')).count()).to.eventually.equal(0);
});

});