aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorIgor Minar2010-10-23 21:40:27 -0700
committerIgor Minar2010-10-26 21:58:00 -0700
commit01c52e92b120eea498e0352a42a489d55e7d9979 (patch)
tree07e5e7d83e783a62e5333f1c22415dd3ac397900
parent943377a091bd7521d33e680dcd2141f7f9fa10c4 (diff)
downloadangular.js-01c52e92b120eea498e0352a42a489d55e7d9979.tar.bz2
Adding e2e tests for the PersonalLog app
- added scenario runner - added scenario specs - cookie cleaning DSL - making rmLog independent on ordering in the view
-rw-r--r--example/personalLog/personalLog.html8
-rw-r--r--example/personalLog/personalLog.js6
-rw-r--r--example/personalLog/scenario/personalLogScenario.js98
-rw-r--r--example/personalLog/scenario/runner.html10
-rw-r--r--example/personalLog/test/personalLogSpec.js12
5 files changed, 122 insertions, 12 deletions
diff --git a/example/personalLog/personalLog.html b/example/personalLog/personalLog.html
index 64a6115d..6915b9a0 100644
--- a/example/personalLog/personalLog.html
+++ b/example/personalLog/personalLog.html
@@ -6,8 +6,10 @@
<script type="text/javascript" src="personalLog.js"></script>
</head>
-
- <body ng:controller="example.personalLog.LogCtrl">
+
+ <!-- TODO: we need to expose $root so that we can delete cookies in the scenario runner, there
+ must be a better way to do this -->
+ <body ng:controller="example.personalLog.LogCtrl" ng:init="$window.$root = $root">
<form action="" ng:submit="addLog(newMsg)">
<input type="text" name="newMsg" />
@@ -20,7 +22,7 @@
<ul>
<li ng:repeat="log in logs.$orderBy('-at')">
{{log.at | date:'yy-MM-dd HH:mm'}} {{log.msg}}
- [<a href="" ng:click="rmLog($index)">x</a>]
+ [<a href="" ng:click="rmLog(log)">x</a>]
</li>
</ul>
diff --git a/example/personalLog/personalLog.js b/example/personalLog/personalLog.js
index da946a6f..acaf371e 100644
--- a/example/personalLog/personalLog.js
+++ b/example/personalLog/personalLog.js
@@ -51,10 +51,10 @@ function LogCtrl($cookieStore) {
/**
* Persistently removes a log from logs.
- * @param {number} msgIdx Index of the log to remove.
+ * @param {object} log The log to remove.
*/
- this.rmLog = function(msgIdx) {
- logs.splice(msgIdx,1);
+ this.rmLog = function(log) {
+ angular.Array.remove(logs, log);
$cookieStore.put(LOGS, logs);
};
diff --git a/example/personalLog/scenario/personalLogScenario.js b/example/personalLog/scenario/personalLogScenario.js
new file mode 100644
index 00000000..3679a33c
--- /dev/null
+++ b/example/personalLog/scenario/personalLogScenario.js
@@ -0,0 +1,98 @@
+describe('personal log', function() {
+
+ beforeEach(function() {
+ navigateTo('../personalLog.html');
+ });
+
+
+ afterEach(function() {
+ clearCookies();
+ });
+
+
+ it('should create new logs and order them in reverse chronological order', function(){
+ //create first msg
+ input('newMsg').enter('my first message');
+ element('form input[type="submit"]').click();
+
+ expect(repeater('ul li').count()).toEqual(1);
+ expect(repeater('ul li').column('log.msg')).toEqual('my first message');
+
+ //create second msg
+ input('newMsg').enter('my second message');
+ element('form input[type="submit"]').click();
+
+ expect(repeater('ul li').count()).toEqual(2);
+ expect(repeater('ul li').column('log.msg')).toEqual(['my second message', 'my first message']);
+ });
+
+
+ it('should delete a log when user clicks on the related X link', function() {
+ //create first msg
+ input('newMsg').enter('my first message');
+ element('form input[type="submit"]').click();
+ //create second msg
+ input('newMsg').enter('my second message');
+ element('form input[type="submit"]').click();
+ expect(repeater('ul li').count()).toEqual(2);
+
+ element('ul li a:eq(1)').click();
+ expect(repeater('ul li').count()).toEqual(1);
+ expect(repeater('ul li').column('log.msg')).toEqual('my second message');
+
+ element('ul li a:eq(0)').click();
+ expect(repeater('ul li').count()).toEqual(0);
+ });
+
+
+ it('should delete all cookies when user clicks on "remove all" button', function() {
+ //create first msg
+ input('newMsg').enter('my first message');
+ element('form input[type="submit"]').click();
+ //create second msg
+ input('newMsg').enter('my second message');
+ element('form input[type="submit"]').click();
+ expect(repeater('ul li').count()).toEqual(2);
+
+ element('input[value="remove all"]').click();
+ expect(repeater('ul li').count()).toEqual(0);
+ });
+
+
+ it('should preserve logs over page reloads', function() {
+ input('newMsg').enter('my persistent message');
+ element('form input[type="submit"]').click();
+ expect(repeater('ul li').count()).toEqual(1);
+
+ navigateTo('about:blank');
+ navigateTo('../personalLog.html');
+
+ expect(repeater('ul li').column('log.msg')).toEqual('my persistent message');
+ expect(repeater('ul li').count()).toEqual(1);
+ });
+});
+
+
+/**
+ * DSL for deleting all cookies.
+ */
+angular.scenario.dsl('clearCookies', function() {
+ /**
+ * Deletes cookies by interacting with the cookie service within the application under test.
+ */
+ return function() {
+ this.addFutureAction('clear all cookies', function($window, $document, done) {
+ //TODO: accessing angular services is pretty nasty, we need a better way to reach them
+ var $cookies = $window.$root.$cookies,
+ cookieName;
+
+ for (cookieName in $cookies) {
+ console.log('deleting cookie: ' + cookieName);
+ delete $cookies[cookieName];
+ }
+ $window.$root.$eval();
+
+ done();
+ });
+ };
+});
diff --git a/example/personalLog/scenario/runner.html b/example/personalLog/scenario/runner.html
new file mode 100644
index 00000000..7129c228
--- /dev/null
+++ b/example/personalLog/scenario/runner.html
@@ -0,0 +1,10 @@
+<!doctype html">
+<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
+ <head>
+ <title>Personal Log Scenario Runner</title>
+ <script type="text/javascript" src="../../../src/scenario/angular-bootstrap.js"></script>
+ <script type="text/javascript" src="personalLogScenario.js"></script>
+ </head>
+ <body>
+ </body>
+</html>
diff --git a/example/personalLog/test/personalLogSpec.js b/example/personalLog/test/personalLogSpec.js
index f111aba4..d3df1b64 100644
--- a/example/personalLog/test/personalLogSpec.js
+++ b/example/personalLog/test/personalLogSpec.js
@@ -72,10 +72,10 @@ describe('example.personalLog.LogCtrl', function() {
it('should delete a message identified by index', function() {
- logCtrl.rmLog(1);
+ logCtrl.rmLog(logCtrl.logs[1]);
expect(logCtrl.logs.length).toBe(3);
- logCtrl.rmLog(2);
+ logCtrl.rmLog(logCtrl.logs[2]);
expect(logCtrl.logs.length).toBe(2);
expect(logCtrl.logs[0].msg).toBe('message1');
expect(logCtrl.logs[1].msg).toBe('message3');
@@ -85,12 +85,12 @@ describe('example.personalLog.LogCtrl', function() {
it('should update cookies when a log is deleted', function() {
expect(logCtrl.$cookies.logs).toMatch(/\[\{.*?\}(,\{.*?\}){3}\]/);
- logCtrl.rmLog(1);
+ logCtrl.rmLog(logCtrl.logs[1]);
expect(logCtrl.$cookies.logs).toMatch(/\[\{.*?\}(,\{.*?\}){2}\]/);
- logCtrl.rmLog(0);
- logCtrl.rmLog(0);
- logCtrl.rmLog(0);
+ logCtrl.rmLog(logCtrl.logs[0]);
+ logCtrl.rmLog(logCtrl.logs[0]);
+ logCtrl.rmLog(logCtrl.logs[0]);
expect(logCtrl.$cookies.logs).toMatch(/\[\]/);
});
});