diff --git a/client/demo/ex/assignment1/index.html b/client/demo/ex/assignment1/index.html new file mode 100644 index 0000000..ed960e4 --- /dev/null +++ b/client/demo/ex/assignment1/index.html @@ -0,0 +1,117 @@ + + + + + + + + Expense App Assignment1 + + +
+

Expenses

+
+ +
+

Create Expense

+
+
+ +
+ +
+
+ +
+
+ +
+
+ +
+
+ + + +
+
+
+
+
+
+ + + + + + + + + + + + + + + + +
DateTypeDescriptionAmount
{{ exp.date | date: 'dd/MM/yy'}}{{ exp.type }}{{ exp.description }}{{ exp.amount }} + + +
+
+
+

Totals by Type

+
+ + + + + + + + + + + +
TypeTotal
{{type}}{{ exp.amount + total }} +
+
+
+

Total All Types

+
+
+

{{ exp.amount + total}}

+
+
+
+
+ + diff --git a/client/demo/ex/assignment1/index2.html b/client/demo/ex/assignment1/index2.html new file mode 100644 index 0000000..fac60cd --- /dev/null +++ b/client/demo/ex/assignment1/index2.html @@ -0,0 +1,118 @@ + + + + + + + + + + +
+
+

Todo List #{{list.length}}

+
+ +
+
+ Date: +
+
+ +
+
+ Type: +
+
+ +
+
+ Description: +
+
+ +
+
+ Amount: +
+
+ +
+
+
+
+ + + + + +
+
+ + + + + + + + + + + + + + + + + + + +
DateTypeDescriptionAmountAction
{{item.date}}{{item.type}}{{item.description}}{{item.amount}} + + + +
+ + + + + + + + + + + + + +
TypeTotal
{{type}}{{total + item.amout * 1}}
+ +
+
+
+ + \ No newline at end of file diff --git a/client/demo/ex/assignment2/app.js b/client/demo/ex/assignment2/app.js new file mode 100644 index 0000000..954b27e --- /dev/null +++ b/client/demo/ex/assignment2/app.js @@ -0,0 +1,2 @@ +angular + .module('expensesApp', []); \ No newline at end of file diff --git a/client/demo/ex/assignment2/expensesController.js b/client/demo/ex/assignment2/expensesController.js new file mode 100644 index 0000000..b474c08 --- /dev/null +++ b/client/demo/ex/assignment2/expensesController.js @@ -0,0 +1,101 @@ +angular + .module('expensesApp') + .controller('ExpenseController', ExpenseController); + + +ExpenseController.$inject = ['$filter']; + +function ExpenseController($filter){ + vm = this; + + vm.expenses = []; + vm.expense = {}; + vm.types = ['food', 'transportation', 'lodging', 'financial', 'sales', 'other.']; + vm.isEditing = false; + + vm.total = 0; + + vm.newExpense = function(){ + vm.expense.id = vm.expenses.length + 1; + vm.expenses.push(vm.expense); + //console.debug(vm.expense); + vm.expense = {}; + }; + + vm.delete = function(exp){ + vm.expenses.splice(vm.expenses.indexOf(exp),1); + }; + + vm.edit = function(exp){ + vm.expense = angular.copy(exp); + vm.isEditing = true; + }; + + vm.update = function(exp){ + var selectedExpense = $filter('filter')(vm.expenses, {id: exp.id})[0]; + selectedExpense.date = exp.date; + selectedExpense.type = exp.type; + selectedExpense.description = exp.description; + selectedExpense.amount = exp.amount; + + vm.isEditing = false; + vm.expense = {}; + }; + + vm.cancel = function(){ + vm.expense = {}; + vm.isEditing = false; + }; + + vm.getTotal = getTotal; + vm.getTotalByType = getTotalByType; + vm.setColor = setColor; + + function getTotal(){ + var totals = 0; + angular.forEach(vm.expenses, function(key, value){ + totals += key.amount; + }); + return totals; + } + + function getTotalByType(type){ + var totals = 0; + angular.forEach(vm.expenses, function(key, value){ + if (key.type == type){ + totals += key.amount; + } + }); + return totals; + } + + function setColor(type){ + console.log(type); + switch (type){ + case 'food': + return { 'background-color': "lightblue" }; + case 'transportation': + return { 'background-color': "lightcoral" }; + case 'lodging': + return { 'background-color': "lightgray" }; + case 'financial': + return { 'background-color': "lightgreen" }; + case 'sales': + return { 'background-color': "lightskyblue" }; + case 'other.': + return { 'background-color': "lightsalmon" }; + } + } +} + + + + + + + + + + + + diff --git a/client/demo/ex/assignment2/expensesController.spec.js b/client/demo/ex/assignment2/expensesController.spec.js new file mode 100644 index 0000000..851cbfd --- /dev/null +++ b/client/demo/ex/assignment2/expensesController.spec.js @@ -0,0 +1,74 @@ +describe('Controller: expensesController', function () { + 'use strict'; + var controller, + scope; + // Refresh the $filter every time. + beforeEach(module('expensesApp')); + beforeEach(inject(function (_$rootScope_, $controller) { + scope = _$rootScope_.$new(); + controller = $controller('ExpenseController', + {$scope: scope}); + }) + ); + + it('should start empty', function () { + expect(controller.expenses.length).to.equal(0); + }); + + it('should add/remove items', function () { + //Create + //First expense + controller.expense.date = '09/06/1988'; + controller.expense.type = 'transportation'; + controller.expense.description = 'Testing Expense'; + controller.expense.amount = 1000; + controller.newExpense(); + + expect(controller.expenses.length).to.equal(1); + + //Second expense + controller.expense.date = '01/01/2015'; + controller.expense.type = 'food'; + controller.expense.description = 'Testing Expense 2'; + controller.expense.amount = 10000; + + controller.newExpense(); + + expect(controller.expenses.length).to.equal(2); + + //Delete: + controller.delete(controller.expense); + expect(controller.expenses.length).to.equal(1); + + //Edit: + //controller.expense = {}; + //controller.expense.date = '09/06/1988'; + controller.expense.type = 'transportation'; + //controller.expense.description = 'Testing Expense'; + //controller.expense.amount = 1000; + controller.update(controller.expense); + expect(controller.expenses[0].type).to.equal('financial'); + }); + +}); + +//newExpense OK +//delete OK +//update + +//gettotal +//gettotalbytype +//setcolor + + +//vm.update = function(index, exp){ +// var selectedExpense = $filter('filter')(vm.expenses, {id: exp.id})[0]; +// selectedExpense.date = exp.date; +// selectedExpense.type = exp.type; +// selectedExpense.description = exp.description; +// selectedExpense.amount = exp.amount; +// +// vm.isEditing = false; +// vm.expense = {}; +//}; +// diff --git a/client/demo/ex/assignment2/index.html b/client/demo/ex/assignment2/index.html new file mode 100644 index 0000000..7a49fc6 --- /dev/null +++ b/client/demo/ex/assignment2/index.html @@ -0,0 +1,112 @@ + + + + + + + + + + + + + Expense App Assignment2 + + +
+

Expenses

+
+
+

Create Expense

+
+
+ +
+ +
+
+ +
+
+ +
+
+ +
+
+ + + +
+
+
+
+
+
+
+ + + + + + + + + + + + + + + + +
DateTypeDescriptionAmount
{{ expen.date | date: 'MM/dd/yy'}}{{ expen.type }}{{ expen.description }}{{ expen.amount }} + + +
+
+
+
+
+ Totals by Type +
+
+
+ + + + + + + + + + + +
TypeTotal
{{ type }}{{ exp.getTotalByType(type) }}
+
+
+
+
+
+
+
+ Total All Types +
+
+
+

Total: {{ exp.getTotal() }}

+
+
+
+
+
+
+ + diff --git a/e2e/ex/main.spec.js b/e2e/ex/main.spec.js new file mode 100644 index 0000000..a3715cf --- /dev/null +++ b/e2e/ex/main.spec.js @@ -0,0 +1,76 @@ +'use strict'; + +describe('Expenses app', function () { + var page; + beforeEach(function () { + browser.get('/demo/ex/assignment2/'); + 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('exp.expense.date')); + page.date.sendKeys('09/06/1988'); + + page.type = element(by.cssContainingText('option', 'transportation')).click(); + page.description = element(by.model('exp.expense.description')).sendKeys('Testing Expense'); + page.amount = element(by.model('exp.expense.amount')).sendKeys('1000'); + + page.button = element(by.id('create-button')); + page.button.click(); + + //Quantity + var items = element.all(by.repeater('expen in exp.expenses track by expen.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('expen in exp.expenses track by expen.id')); + items.first().then(function () { + page.button = element(by.css('.edit-expense')); + page.button.click(); + }); + + page.date = element(by.model('exp.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('expen in exp.expenses track by expen.id')); + items.first().then(function () { + page.button = element(by.css('.delete-expense')); + page.button.click(); + }); + + expect(element.all(by.repeater('expen in exp.expenses track by expen.id')).count()).to.eventually.equal(0); + }); + +});