aboutsummaryrefslogtreecommitdiffstats
path: root/example/personalLog/test/personalLogSpec.js
diff options
context:
space:
mode:
authorIgor Minar2010-10-22 22:13:14 -0700
committerMisko Hevery2010-10-23 14:38:08 -0700
commit5b40e87ac687fc52ba86f39daf62975b169acf41 (patch)
tree4629c51f5e86d46a7c1792ede0257b6cc774aac0 /example/personalLog/test/personalLogSpec.js
parent1391f19fb49275af59230afef51b472c58d7818c (diff)
downloadangular.js-5b40e87ac687fc52ba86f39daf62975b169acf41.tar.bz2
personalLog demo - initial version with spec
Diffstat (limited to 'example/personalLog/test/personalLogSpec.js')
-rw-r--r--example/personalLog/test/personalLogSpec.js122
1 files changed, 122 insertions, 0 deletions
diff --git a/example/personalLog/test/personalLogSpec.js b/example/personalLog/test/personalLogSpec.js
new file mode 100644
index 00000000..f111aba4
--- /dev/null
+++ b/example/personalLog/test/personalLogSpec.js
@@ -0,0 +1,122 @@
+describe('example.personalLog.LogCtrl', function() {
+ var logCtrl;
+
+ function createNotesCtrl() {
+ var scope = angular.scope();
+ return scope.$new(example.personalLog.LogCtrl);
+ }
+
+
+ beforeEach(function() {
+ logCtrl = createNotesCtrl();
+ });
+
+
+ it('should initialize notes with an empty array', function() {
+ expect(logCtrl.logs).toEqual([]);
+ });
+
+
+ describe('addLog', function() {
+
+ beforeEach(function() {
+ expect(logCtrl.logs).toEqual([]);
+ });
+
+
+ it('should add newMsg to logs as a log entry', function() {
+ logCtrl.newMsg = 'first log message';
+ logCtrl.addLog();
+
+ expect(logCtrl.logs.length).toBe(1);
+ expect(logCtrl.logs[0].msg).toBe('first log message');
+
+ //one more msg, this time passed in as param
+ logCtrl.addLog('second log message');
+
+ expect(logCtrl.logs.length).toBe(2);
+ expect(logCtrl.logs[0].msg).toBe('first log message');
+ expect(logCtrl.logs[1].msg).toBe('second log message');
+ });
+
+
+ it('should clear newMsg when log entry is persisted', function() {
+ logCtrl.addLog('first log message');
+ expect(logCtrl.newMsg).toBe('');
+ });
+
+
+ it('should store logs in the logs cookie', function() {
+ expect(logCtrl.$cookies.logs).not.toBeDefined();
+ logCtrl.addLog('first log message');
+ expect(logCtrl.$cookies.logs).toBeTruthy();
+ });
+
+
+ it('should do nothing if newMsg is empty', function() {
+ logCtrl.addLog('');
+ expect(logCtrl.logs.length).toBe(0);
+ });
+ });
+
+
+ describe('rmLog', function() {
+
+ beforeEach(function() {
+ logCtrl.addLog('message1');
+ logCtrl.addLog('message2');
+ logCtrl.addLog('message3');
+ logCtrl.addLog('message4');
+ expect(logCtrl.logs.length).toBe(4);
+ });
+
+
+ it('should delete a message identified by index', function() {
+ logCtrl.rmLog(1);
+ expect(logCtrl.logs.length).toBe(3);
+
+ logCtrl.rmLog(2);
+ expect(logCtrl.logs.length).toBe(2);
+ expect(logCtrl.logs[0].msg).toBe('message1');
+ expect(logCtrl.logs[1].msg).toBe('message3');
+ });
+
+
+ it('should update cookies when a log is deleted', function() {
+ expect(logCtrl.$cookies.logs).toMatch(/\[\{.*?\}(,\{.*?\}){3}\]/);
+
+ logCtrl.rmLog(1);
+ expect(logCtrl.$cookies.logs).toMatch(/\[\{.*?\}(,\{.*?\}){2}\]/);
+
+ logCtrl.rmLog(0);
+ logCtrl.rmLog(0);
+ logCtrl.rmLog(0);
+ expect(logCtrl.$cookies.logs).toMatch(/\[\]/);
+ });
+ });
+
+
+ describe('rmLogs', function() {
+
+ beforeEach(function() {
+ logCtrl.addLog('message1');
+ logCtrl.addLog('message2');
+ logCtrl.addLog('message3');
+ logCtrl.addLog('message4');
+ expect(logCtrl.logs.length).toBe(4);
+ });
+
+
+ it('should remove all logs', function() {
+ logCtrl.rmLogs();
+ expect(logCtrl.logs).toEqual([]);
+ });
+
+
+ it('should remove logs cookie', function() {
+ expect(logCtrl.$cookies.logs).toBeTruthy();
+ logCtrl.rmLogs();
+ expect(logCtrl.$cookies.logs).not.toBeDefined();
+ });
+ });
+}); \ No newline at end of file