From 2cb530f0cff621b4e41954eb8c30c93097d0dd80 Mon Sep 17 00:00:00 2001 From: Kiran Rao Date: Thu, 19 Feb 2015 13:04:06 -0800 Subject: [PATCH] Adds memento-list, memento, and mementoCreate functionality and initial unit and integration tests Adds basic mementos module, controller, and html to application Adds spec for app.mementos and adds initial unit test for controller creation Adds mock memento data for getMementos testing Adds unit tests working with mock mementos data in dataservice spec Adds app.mementos to module Created and received mementos are now displayed on mementos view Adds mementos controller unit tests with mock data Begins links mementos view to created and existing memento views Adds a mock data for mementoDetail Memento unit tests added Refactors code to be more readable Adds memento.module to app Adds memento.module Adds memento javascript tags to index.html Sets up nested state for memento All tests passed for core functionality Mementos to memento displaying moments is now functional Adds additional unit test for getMemento method Adds functionality to hide/show received mementos depending on if user is creating memento or not Adds memento create view, controller, and module into application Adds and solves unit tests for memento-create Adds memento creation functionality Passes failing tests Title and recipients inputs for memento create now work. Button disabled if these fields are not set Save memento disabled until user input. On save, send user to memento view for created memento Removes tests from bottom of file Refactors to meet style guide expectations Fixes bugs from CurrentMoment commit Removes momentID property from mementos controller mementoCreate now adds latest moment to memento Moments are now added in memento-create Can now add moments to mementos in memento-list Updates dataservice to get and add moments correctly memento-create refactored to mimic moment.create style Fixes saveMoment on moment.create.html. Removes fake moment from dataservice memento-list and dataservice refactored memento and dataservice refactored promisifies elements of memento-create and mementos-list Adjusts addMoment method in dataservice Tests failing. Need to rewrite Refactors memento-create code for style purposes Memento test now working Fixes mementos tests Renames memento-create to memento.create Change memento-create to memento.create --- client/www/app/app.module.js | 23 +- client/www/app/core/dataservice.js | 113 ++++----- .../app/memento-create/memento.create.html | 22 ++ .../www/app/memento-create/memento.create.js | 70 ++++++ .../memento-create/memento.create.module.js | 5 + client/www/app/memento/memento.html | 14 +- client/www/app/memento/memento.js | 39 +++ client/www/app/memento/memento.module.js | 5 + client/www/app/mementos-list/mementos.html | 26 +- client/www/app/mementos-list/mementos.js | 54 ++++ .../www/app/mementos-list/mementos.module.js | 5 + client/www/app/moment/moment.create.html | 2 +- client/www/index.html | 12 +- client/www/test/lib/mockData.js | 230 +++++++----------- client/www/test/specs/dataservice.spec.js | 43 ++-- client/www/test/specs/memento.create.spec.js | 72 ++++++ client/www/test/specs/memento.spec.js | 57 +++++ client/www/test/specs/mementos.spec.js | 58 +++++ client/www/test/specs/moment.spec.js | 23 -- karma.conf.js | 3 + 20 files changed, 623 insertions(+), 253 deletions(-) create mode 100644 client/www/app/memento-create/memento.create.html create mode 100644 client/www/app/memento-create/memento.create.js create mode 100644 client/www/app/memento-create/memento.create.module.js create mode 100644 client/www/app/memento/memento.js create mode 100644 client/www/app/memento/memento.module.js create mode 100644 client/www/app/mementos-list/mementos.js create mode 100644 client/www/app/mementos-list/mementos.module.js create mode 100644 client/www/test/specs/memento.create.spec.js create mode 100644 client/www/test/specs/memento.spec.js create mode 100644 client/www/test/specs/mementos.spec.js delete mode 100644 client/www/test/specs/moment.spec.js diff --git a/client/www/app/app.module.js b/client/www/app/app.module.js index 75f315d..4307b6b 100644 --- a/client/www/app/app.module.js +++ b/client/www/app/app.module.js @@ -5,7 +5,10 @@ 'ionic', 'app.core', - 'app.moment' + 'app.moment', + 'app.mementos', + 'app.memento', + 'app.memento.create' ]) .run(function($ionicPlatform) { @@ -29,6 +32,24 @@ url: '/moment', templateUrl: 'app/moment/moment.create.html', controller: 'MomentCreate as vm' + }) + + .state('mementos', { + url: '/mementos', + templateUrl: 'app/mementos-list/mementos.html', + controller: 'Mementos as vm' + }) + // nested state + .state('memento', { + url: '/mementos/:ID', + templateUrl: 'app/memento/memento.html', + controller: 'Memento as vm' + }) + + .state('mementoCreate', { + url: '/create', + templateUrl: 'app/memento-create/memento.create.html', + controller: 'MementoCreate as vm' }); // if none of the above states are matched, use this as the fallback diff --git a/client/www/app/core/dataservice.js b/client/www/app/core/dataservice.js index 36d788b..300332b 100644 --- a/client/www/app/core/dataservice.js +++ b/client/www/app/core/dataservice.js @@ -30,14 +30,18 @@ getMemento: getMemento, saveMoment: saveMoment, saveMemento: saveMemento, - addMoment: addMoment + addMoment: addMoment, + /*NOTE: temp until server is connected*/ + getMoment: getMoment }; return service; // NOTE: server will only return mementos associated with user function getMementos() { - return mementos; + return $q(function(resolve, reject) { + resolve(mementos); + }); } // NOTE: memento ID will be supplied from getMementos call in list view @@ -45,38 +49,19 @@ var memento; var i; - ID = ID || 1; - for (i = 0; i < mementosDetail.length; i++) { if (mementosDetail[i].ID === ID) { memento = mementosDetail[i]; } } - return memento; + return $q(function(resolve, reject) { + resolve(memento); + }); } // NOTE: moment is saved to moments table first, then added to memento function saveMoment(obj) { - obj = obj || { - 'ID' : null, - 'title' : 'fake moment', - 'author' : ['Wes'], - 'releaseDate' : '01/01/2016', - 'meta' : { - 'creationDate' : '01/01/2015', - 'location' : { - 'latitude' : 0, - 'longitude' : 0, - 'place' : 'Someplace fake' - } - }, - content : [{ - 'type' : 'text', - 'url' : 'This is a fake moment' // using media instead of url pointing to it for time being - }] - }; - obj.ID = momentsSize() + 1; moments.push(obj); @@ -85,29 +70,31 @@ resolve(obj.ID); }); } + + // NOTE: temp until server is connected + function getMoment(ID) { + var moment; + var i; + + for (i = 0; i < moments.length; i++) { + if(moments[i].ID === ID) { + moment = moments[i]; + } + } + + return $q(function(resolve, reject) { + resolve(moment); + }); + } // NOTE: addMoment happens concurrently with memento creation function saveMemento(obj) { - obj = obj || { - 'ID' : null, - 'title' : 'Fake memento', - 'owner' : 'Wes', - 'authors' : ['Wes'], - 'recipients' : ['Mom'], - 'options' : { - 'public' : false, - 'releaseType' : 'default', - }, - 'latestReleasedIndex' : 1, // associated with moments array. latest moment released - 'moments' : [] - }; - obj.ID = mementosSize() + 1; // add to mementos detail mementosDetail.push(obj); - // add to mementos + // NOTE: adds to mementos. Below is TEMPORARY as server will handle adjusting the memento object var mementosObj = { 'ID': obj.ID, 'title': obj.title, @@ -115,25 +102,39 @@ 'recipients' : obj.recipients }; - if (obj.authors[0] === 'Wes') { + if (obj.authors[0] === 'Wes' || obj.authors[0] === 'User1') { mementos.created.push(mementosObj); } else { mementos.received.push(mementosObj); } + + // TEMP + /////////////////////////////////////////////////////////////////////////////////////////////////// + + return $q(function(resolve, reject) { + resolve(obj.ID); + }); } // NOTE: adds moment to selected memento - function addMoment(ID) { + function addMoment(mementoID, momentID) { var i; - ID = ID || 1; - for (i = 0; i < mementosDetail.length; i++) { - if (mementosDetail[i].ID === ID) { - var moment = moments[momentsSize() - 1]; - mementosDetail[i].moments.push(moment); + if (mementosDetail[i].ID === mementoID) { + return getMoment(momentID) + .then(function(data) { + mementosDetail[i].moments.push(data); + }) + .catch(function(err) { + console.error('There was an error getting the moment:', err); + }); } } + + return $q(function(resolve, reject) { + resolve(momentID); + }); } // NOTE: temp method to keep track of moment ID. @@ -148,22 +149,4 @@ } -})(); - -/*for testing - -var mementosBefore = dataservice.getMementos(); -console.log('Mementos Before', mementosBefore); - -var mementoBefore = dataservice.getMemento(); -console.log('Memento Before', mementoBefore); - -dataservice.saveMoment(); -dataservice.saveMemento(); -dataservice.addMoment(); - -var mementosAfter = dataservice.getMementos(); -console.log('Mementos After', mementosAfter); - -var mementoAfter = dataservice.getMemento(); -console.log('Memento After', mementoAfter);*/ \ No newline at end of file +})(); \ No newline at end of file diff --git a/client/www/app/memento-create/memento.create.html b/client/www/app/memento-create/memento.create.html new file mode 100644 index 0000000..1292237 --- /dev/null +++ b/client/www/app/memento-create/memento.create.html @@ -0,0 +1,22 @@ + + + +
+ +
+ +
+ +
+ + + + +
+
\ No newline at end of file diff --git a/client/www/app/memento-create/memento.create.js b/client/www/app/memento-create/memento.create.js new file mode 100644 index 0000000..5bde842 --- /dev/null +++ b/client/www/app/memento-create/memento.create.js @@ -0,0 +1,70 @@ +(function() { + 'use strict'; + + angular + .module('app.memento.create') + .controller('MementoCreate', MementoCreate); + + /* @ngInject */ + function MementoCreate($state, dataservice, CurrentMoment , $stateParams) { + /*jshint validthis: true */ + var vm = this; + vm.title = 'Create Memento'; + vm.currentMemento = new EmptyMemento(); + vm.saveMemento = saveMemento; + + activate(); + + //////////////////////////////////////////////////////////// + + function activate() { + return addMoment(); + } + + function saveMemento(currentMemento) { + return dataservice.saveMemento(currentMemento) + .then(function(mementoID) { + + console.log('Memento ' + mementoID + ' has been saved.'); + $state.go('memento', {ID: mementoID}); + + }) + .catch(function(err) { + // TODO: Connection errors, DB errors. + // savingError(err); + console.error('There was an error saving memento:', err); + }); + } + + function addMoment() { + var momentID = CurrentMoment.get(); + + // NOTE: adds entire moment to fit dummy data. Will only add momentID when connected with server + return dataservice.getMoment(momentID.momentID) + .then(function(data) { + console.log('Successfull getting moment'); + + vm.currentMemento.moments.push(data); + + // NOTE: sets moment back to an empty object + CurrentMoment.set({}); + }) + .catch(function(err) { + console.error('There was an error getting moment:', err); + }); + } + + function EmptyMemento() { + this.title = ''; + this.owner = 'User1'; + this.authors = [this.owner]; + this.recipients = ''; + this.options = { + 'public' : false, + 'releaseType' : 'default', + }; + this.latestReleasedIndex = 1; + this.moments = []; + } + } +})(); \ No newline at end of file diff --git a/client/www/app/memento-create/memento.create.module.js b/client/www/app/memento-create/memento.create.module.js new file mode 100644 index 0000000..8934531 --- /dev/null +++ b/client/www/app/memento-create/memento.create.module.js @@ -0,0 +1,5 @@ +(function() { + 'use strict'; + + angular.module('app.memento.create', []); +})(); \ No newline at end of file diff --git a/client/www/app/memento/memento.html b/client/www/app/memento/memento.html index dc93d7c..0bddf7a 100644 --- a/client/www/app/memento/memento.html +++ b/client/www/app/memento/memento.html @@ -1 +1,13 @@ -memento.html \ No newline at end of file + + + +
+ +
+ {{item.url}} +
+ +
+ +
+
\ No newline at end of file diff --git a/client/www/app/memento/memento.js b/client/www/app/memento/memento.js new file mode 100644 index 0000000..75a06d0 --- /dev/null +++ b/client/www/app/memento/memento.js @@ -0,0 +1,39 @@ +(function() { + 'use strict'; + + angular + .module('app.memento') + .controller('Memento', Memento); + + /* @ngInject */ + function Memento(dataservice, $stateParams) { + /*jshint validthis: true */ + var vm = this; + vm.memento = {}; + vm.mementoID = Number($stateParams.ID); + vm.getMemento = getMemento; + + activate(); + + //////////////////////////////////////////////////////////// + + function activate() { + return getMemento(vm.mementoID).then(function() { + console.log('Activated memento view'); + }); + } + + function getMemento(ID) { + return dataservice.getMemento(ID) + .then(function(data) { + console.log('Successfull getting memento'); + + vm.memento = data; + }) + .catch(function(err) { + console.error('There was an error getting memento:', err); + }); + } + + } +})(); \ No newline at end of file diff --git a/client/www/app/memento/memento.module.js b/client/www/app/memento/memento.module.js new file mode 100644 index 0000000..327a8b4 --- /dev/null +++ b/client/www/app/memento/memento.module.js @@ -0,0 +1,5 @@ +(function() { + 'use strict'; + + angular.module('app.memento', []); +})(); \ No newline at end of file diff --git a/client/www/app/mementos-list/mementos.html b/client/www/app/mementos-list/mementos.html index be76805..cec1f96 100644 --- a/client/www/app/mementos-list/mementos.html +++ b/client/www/app/mementos-list/mementos.html @@ -1 +1,25 @@ -mementos.html \ No newline at end of file + + + Create Memento + +
Created
+ + + {{memento.title}} + + + + + +
+
Received
+ + + {{memento.title}} + + + +
+ +
+
\ No newline at end of file diff --git a/client/www/app/mementos-list/mementos.js b/client/www/app/mementos-list/mementos.js new file mode 100644 index 0000000..f25bf42 --- /dev/null +++ b/client/www/app/mementos-list/mementos.js @@ -0,0 +1,54 @@ +(function() { + 'use strict'; + + angular + .module('app.mementos') + .controller('Mementos', Mementos); + + /* @ngInject */ + function Mementos(dataservice, CurrentMoment, $stateParams) { + /*jshint validthis: true */ + var vm = this; + vm.mementos = {}; + vm.title = 'Mementos'; + vm.addMoment = addMoment; + + activate(); + + //////////////////////////////////////////////////////////// + + function activate() { + return getMementos().then(function() { + console.log('Activated mementos view'); + }); + } + + function getMementos() { + return dataservice.getMementos() + .then(function(data) { + console.log('Successfull getting mementos'); + + vm.mementos = data; + }) + .catch(function(err) { + console.error('There was an error getting mementos:', err); + }); + } + + function addMoment(mementoID) { + var momentID = CurrentMoment.get(); + + return dataservice.addMoment(mementoID, momentID.momentID) + .then(function(momentID) { + console.log('Moment ' + momentID + ' has been added.'); + + // NOTE: sets moment back to an empty object + CurrentMoment.set({}); + }) + .catch(function(err) { + console.error('There was an error adding the moment:', err); + }); + } + + } +})(); \ No newline at end of file diff --git a/client/www/app/mementos-list/mementos.module.js b/client/www/app/mementos-list/mementos.module.js new file mode 100644 index 0000000..8f68019 --- /dev/null +++ b/client/www/app/mementos-list/mementos.module.js @@ -0,0 +1,5 @@ +(function() { + 'use strict'; + + angular.module('app.mementos', []); +})(); \ No newline at end of file diff --git a/client/www/app/moment/moment.create.html b/client/www/app/moment/moment.create.html index a85e764..e555a9b 100644 --- a/client/www/app/moment/moment.create.html +++ b/client/www/app/moment/moment.create.html @@ -20,7 +20,7 @@ - + diff --git a/client/www/index.html b/client/www/index.html index d0cb299..31437ae 100644 --- a/client/www/index.html +++ b/client/www/index.html @@ -21,13 +21,19 @@ + + + - - - + + + + + + diff --git a/client/www/test/lib/mockData.js b/client/www/test/lib/mockData.js index 32b0ef2..9ed78a9 100644 --- a/client/www/test/lib/mockData.js +++ b/client/www/test/lib/mockData.js @@ -1,149 +1,97 @@ -// FIXE: to be edited -/*var mockData = (function() { - return { - getMockMementos: getMockMementos - }; +var mockData = (function() { + var mementos; + var mementosDetail; - function getMockMementos() { - return [{ - 'ID' : 1, - 'title' : 'For mom', - 'owner' : 'Wes', - 'authors' : ['Wes'], - 'recipients' : ['Mom'], - 'options' : { - 'public' : false, - 'releaseType' : 'default', - }, - 'latestReleasedIndex' : 1, // associated with moments array. latest moment released - 'moments' : [{ - 'ID' : 1, - 'title' : 'Hi mom!', - 'author' : ['Wes'], - 'releaseDate' : '01/01/2016', - 'meta' : { - 'creationDate' : '01/01/2015', - 'location' : { - 'latitude' : 0, - 'longitude' : 0, - 'place' : 'Someplace awesome' - } - }, - content : [{ - 'type' : 'text', - 'url' : 'This is my awesome note to my mom who is awesome. Awesome bro!!' // using media instead of url pointing to it for time being - }] - }, { - 'ID' : 2, - 'title' : 'love youuuuuu mom!', - 'author' : ['Wes'], - 'releaseDate' : '01/01/2016', - 'meta' : { - 'creationDate' : '01/01/2015', - 'location' : { - 'latitude' : 0, - 'longitude' : 0, - 'place' : 'Someplace awesome' - } - }, - content : [{ - 'type' : 'text', - 'url' : 'This is my looooooooooove noooote tooo mmyyy mom!!' // using media instead of url pointing to it for time being - }] - }] + mementos = { + 'received' : [{ + 'ID': 1, + 'title': 'Mock Memento 1', + 'authors' : ['User2'], + 'recipients' : ['User1'] + }], + 'created' : [{ + 'ID': 2, + 'title': 'Mock Memento 2', + 'authors' : ['User1'], + 'recipients' : ['User2'] }, { - 'ID' : 2, - 'title' : 'For my girlfriend', - 'owner' : 'Wes', - 'authors' : ['Wes'], - 'recipients' : ['Girlfriend'], - 'options' : { - 'public' : false, - 'releaseType' : 'default', - }, - 'latestReleasedIndex' : 1, // associated with moments array. latest moment released - 'moments' : [{ - 'ID' : 3, - 'title' : 'Hey girl!', - 'author' : ['Wes'], - 'releaseDate' : '01/01/2016', - 'meta' : { - 'creationDate' : '01/01/2015', - 'location' : { - 'latitude' : 0, - 'longitude' : 0, - 'place' : 'Someplace awesome' - } - }, - content : [{ - 'type' : 'text', - 'url' : 'This is my awesome note to my girlfriend who is awesome. Awesome bro!!' // using media instead of url pointing to it for time being - }] - }, { - 'ID' : 4, - 'title' : 'love youuuuuu girl!', - 'author' : ['Wes'], - 'releaseDate' : '01/01/2016', - 'meta' : { - 'creationDate' : '01/01/2015', - 'location' : { - 'latitude' : 0, - 'longitude' : 0, - 'place' : 'Someplace awesome' - } - }, - content : [{ - 'type' : 'text', - 'url' : 'This is my looooooooooove noooote tooo mmyyy girl!!' // using media instead of url pointing to it for time being - }] - }] - }, { - 'ID' : 3, - 'title' : 'For Wes', - 'owner' : 'Mom', - 'authors' : ['Mom'], - 'recipients' : ['Wes'], - 'options' : { + 'ID': 3, + 'title': 'Mock Memento 3', + 'authors' : ['User1'], + 'recipients' : ['User2'] + }] + }; + + mementosDetail = [{ + 'ID' : 1, + 'title' : 'Mock Memento 1', + 'owner' : 'User2', + 'authors' : ['User2'], + 'recipients' : ['User1'], + 'options' : { 'public' : false, 'releaseType' : 'default', + }, + 'latestReleasedIndex' : 1, + 'moments' : [{ + 'ID' : 1, + 'title' : 'Mock Moment 1', + 'author' : ['User 2'], + 'releaseDate' : '01/01/2016', + 'meta' : { + 'creationDate' : '01/01/2015', + 'location' : { + 'latitude' : 0, + 'longitude' : 0, + 'place' : 'Mock place' + } }, - 'latestReleasedIndex' : 1, // associated with moments array. latest moment released - 'moments' : [{ - 'ID' : 5, - 'title' : 'Hey son!', - 'author' : ['Mom'], - 'releaseDate' : '01/01/2016', - 'meta' : { - 'creationDate' : '01/01/2015', - 'location' : { - 'latitude' : 0, - 'longitude' : 0, - 'place' : 'Someplace awesome' - } - }, - content : [{ - 'type' : 'text', - 'url' : 'This is my awesome note to my Wes who is awesome. Awesome!!' // using media instead of url pointing to it for time being - }] - }, { - 'ID' : 6, - 'title' : 'love youuuuuu son!', - 'author' : ['Mom'], - 'releaseDate' : '01/01/2016', - 'meta' : { - 'creationDate' : '01/01/2015', - 'location' : { - 'latitude' : 0, - 'longitude' : 0, - 'place' : 'Someplace awesome' - } - }, - content : [{ - 'type' : 'text', - 'url' : 'This is my looooooooooove noooote tooo mmyyy son!!' // using media instead of url pointing to it for time being - }] + content : [{ + 'type' : 'text', + 'url' : 'Mock text' }] - }]; + }] + }]; + + return { + getMockMementos: getMockMementos, + getMockMemento: getMockMemento, + saveMockMemento: saveMockMemento + }; + + function getMockMementos() { + return mementos; + } + + function getMockMemento(ID) { + var memento; + var i; + + for (i = 0; i < mementosDetail.length; i++) { + if (mementosDetail[i].ID === ID) { + memento = mementosDetail[i]; + } + } + + return memento; + } + + function saveMockMemento(obj) { + /* + NOTE: unecessary for current testing setup + // add to mementos detail + mementosDetail.push(obj); + */ + + // add to mementos + var mementosObj = { + 'ID': obj.ID, + 'title': obj.title, + 'authors' : obj.authors, + 'recipients' : obj.recipients + }; + + mementos.created.push(mementosObj); } -})();*/ \ No newline at end of file +})(); \ No newline at end of file diff --git a/client/www/test/specs/dataservice.spec.js b/client/www/test/specs/dataservice.spec.js index 9dce9ae..3c802a0 100644 --- a/client/www/test/specs/dataservice.spec.js +++ b/client/www/test/specs/dataservice.spec.js @@ -1,6 +1,6 @@ + describe('dataservice', function() { var dataservice; - var mocks = {}; beforeEach(function() { module('app'); @@ -11,8 +11,19 @@ describe('dataservice', function() { $rootScope = _$rootScope_; }); - /*mocks = mockData.getMockMementos();*/ + sinon.stub(dataservice, 'getMementos', function() { + return mockData.getMockMementos(); + }); + + sinon.stub(dataservice, 'getMemento', function() { + return mockData.getMockMemento(1); + }); + + }); + afterEach(function() { + dataservice.getMementos.restore(); // Unwraps stub + dataservice.getMemento.restore(); }); it('should be registered', function() { @@ -24,17 +35,12 @@ describe('dataservice', function() { expect(dataservice.getMementos).not.toBe(null); }); - // FIXME: come back to these tests... how to mock data for method calls? - it('should get 3 mementos', function() { - - /*// use this when endpoints set up - $httpBackend.when('GET', '/1/api/mementos').respond(200, mocks); - dataservice.getMementos().then(function(data) { - expect(data.length).toEqual(3); - done(); - }); - $rootScope.$apply(); - $httpBackend.flush();*/ + it('should get 1 received memento', function() { + expect(dataservice.getMementos().received.length).toEqual(1); + }); + + it('should get 2 created mementos', function() { + expect(dataservice.getMementos().created.length).toEqual(2); }); }); @@ -43,7 +49,9 @@ describe('dataservice', function() { expect(dataservice.getMemento).not.toBe(null); }); - // add additional tests + it('should get 1 memento', function() { + expect(dataservice.getMemento(1)).toEqual(jasmine.any(Object)); + }); }); describe('saveMoment function', function() { @@ -54,12 +62,13 @@ describe('dataservice', function() { // add additional tests }); - describe('saveMementos function', function() { + describe('saveMemento function', function() { it('should exist', function() { - expect(dataservice.saveMementos).not.toBe(null); + expect(dataservice.saveMemento).not.toBe(null); }); - // add additional tests + // NOTE: these tests are very similar to what is in each controller. + // should be thinking about these in terms of http request }); describe('addMoment function', function() { diff --git a/client/www/test/specs/memento.create.spec.js b/client/www/test/specs/memento.create.spec.js new file mode 100644 index 0000000..55f4d57 --- /dev/null +++ b/client/www/test/specs/memento.create.spec.js @@ -0,0 +1,72 @@ +describe('app.memento.create', function() { + var controller; + var mockMemento; + + beforeEach(function() { + module('app'); + + inject(function(_$controller_, _dataservice_) { + dataservice = _dataservice_; + $controller = _$controller_; + }); + + sinon.stub(dataservice, 'saveMemento', function() { + mockMemento = { + 'ID' : null, + 'title' : 'Fake memento', + 'owner' : 'User1', + 'authors' : ['User1'], + 'recipients' : ['User2'], + 'options' : { + 'public' : false, + 'releaseType' : 'default', + }, + 'latestReleasedIndex' : 1, + 'moments' : [] + }; + + return mockData.saveMockMemento(mockMemento); + }); + + controller = $controller('MementoCreate'); + }); + + afterEach(function() { + dataservice.saveMemento.restore(); // Unwraps stub + + }); + + describe('MementoCreate controller', function() { + it('should be created successfully', function() { + expect(controller).toBeDefined(); + }); + + it('should have a currentMemento property', function() { + expect(controller.currentMemento).not.toBe(null); + }); + + describe('currentMemento property', function() { + it('should have a title property', function() { + expect(controller.currentMemento.title).toEqual(''); + }); + + it('should have a recipient property', function() { + expect(controller.currentMemento.recipients).toEqual(''); + }); + }); + + it('should have a saveMemento method', function() { + expect(controller.saveMemento).not.toBe(null); + }); + + describe('saveMemento method', function() { + it('should add mementos to database', function() { + expect(mockData.getMockMementos().created.length).toEqual(2); + dataservice.saveMemento({}); + expect(mockData.getMockMementos().created.length).toEqual(3); + }); + }); + + }); + +}); \ No newline at end of file diff --git a/client/www/test/specs/memento.spec.js b/client/www/test/specs/memento.spec.js new file mode 100644 index 0000000..ca1078c --- /dev/null +++ b/client/www/test/specs/memento.spec.js @@ -0,0 +1,57 @@ +describe('app.memento', function() { + var controller; + + beforeEach(function() { + module('app'); + module('templates'); + + inject(function(_$controller_, _dataservice_, _$q_, _$rootScope_, _$httpBackend_) { + dataservice = _dataservice_; + $controller = _$controller_; + $q = _$q_; + $rootScope = _$rootScope_; + $httpBackend = _$httpBackend_; + }); + + sinon.stub(dataservice, 'getMemento', function() { + var deferred = $q.defer(); + deferred.resolve(mockData.getMockMemento(1)); + return deferred.promise; + }); + + controller = $controller('Memento'); + $rootScope.$apply(); + }); + + afterEach(function() { + dataservice.getMemento.restore(); // Unwraps stub + $httpBackend.verifyNoOutstandingExpectation(); + $httpBackend.verifyNoOutstandingRequest(); + }); + + describe('Memento controller', function() { + it('should be created successfully', function() { + expect(controller).toBeDefined(); + }); + + describe('after activate', function() { + + describe('memento data', function() { + it('memento should have title of "Mock Memento 1"', function() { + expect(controller.memento.title).toEqual('Mock Memento 1'); + }); + + it('memento should have ID of 1', function() { + expect(controller.memento.ID).toEqual(1); + }); + + it('memento should have 1 moment', function() { + expect(controller.memento.moments.length).toEqual(1); + }); + }); + + }); + + }); + +}); \ No newline at end of file diff --git a/client/www/test/specs/mementos.spec.js b/client/www/test/specs/mementos.spec.js new file mode 100644 index 0000000..e212754 --- /dev/null +++ b/client/www/test/specs/mementos.spec.js @@ -0,0 +1,58 @@ +describe('app.mementos', function() { + var controller; + + beforeEach(function() { + module('app'); + module('templates'); + + inject(function(_$controller_, _dataservice_, _$q_, _$rootScope_, _$httpBackend_) { + dataservice = _dataservice_; + $controller = _$controller_; + $q = _$q_; + $rootScope = _$rootScope_; + $httpBackend = _$httpBackend_; + }); + + sinon.stub(dataservice, 'getMementos', function() { + var deferred = $q.defer(); + deferred.resolve(mockData.getMockMementos()); + return deferred.promise; + }); + + controller = $controller('Mementos'); + $rootScope.$apply(); + }); + + afterEach(function() { + dataservice.getMementos.restore(); // Unwraps stub + $httpBackend.verifyNoOutstandingExpectation(); + $httpBackend.verifyNoOutstandingRequest(); + }); + + describe('Mementos controller', function() { + it('should be created successfully', function() { + expect(controller).toBeDefined(); + }); + + describe('after activate', function() { + it('should have title of Mementos', function() { + expect(controller.title).toEqual('Mementos'); + }); + + it('should have a mementos property', function() { + expect(controller.mementos).not.toBe(null); + }); + + it('should have 1 received memento in mementos', function() { + expect(controller.mementos.received.length).toEqual(1); + }); + + it('should have 3 received mementos in mementos', function() { + // NOTE: this is 3 because the mementoSave test adds a memento + expect(controller.mementos.created.length).toEqual(3); + }); + }); + + }); + +}); \ No newline at end of file diff --git a/client/www/test/specs/moment.spec.js b/client/www/test/specs/moment.spec.js deleted file mode 100644 index 5fab2e7..0000000 --- a/client/www/test/specs/moment.spec.js +++ /dev/null @@ -1,23 +0,0 @@ -/*old chai test -var chai = require('chai'); -var assert = chai.assert; -var should = chai.should(); -var expect = chai.expect; - -describe('Moment unit tests', function() { - var test = 5; - - it('test should be a number', function() { - expect(test).to.be.a('number'); - }); -});*/ - -// new jasmine test -describe('Moment', function() { - var test = 5; - - it('should equal 5', function() { - expect(test).toEqual(5); - }); -}); - diff --git a/karma.conf.js b/karma.conf.js index 7a591d8..9079693 100644 --- a/karma.conf.js +++ b/karma.conf.js @@ -19,6 +19,9 @@ module.exports = function(config) { 'client/www/lib/angular-sanitize/angular-sanitize.js', // app - need to load feature modules first, otherwise app breaks + 'client/www/app/memento-create/memento.create.module.js', + 'client/www/app/memento/memento.module.js', + 'client/www/app/mementos-list/mementos.module.js', 'client/www/app/moment/moment.module.js', 'client/www/app/core/core.module.js', 'client/www/app/**/*.js',