mirror of
https://github.com/Hopiu/angular.js.git
synced 2026-03-16 23:30:23 +00:00
Adding e2e tests for the PersonalLog app
- added scenario runner - added scenario specs - cookie cleaning DSL - making rmLog independent on ordering in the view
This commit is contained in:
parent
943377a091
commit
01c52e92b1
5 changed files with 122 additions and 12 deletions
|
|
@ -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>
|
||||
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
};
|
||||
|
||||
|
|
|
|||
98
example/personalLog/scenario/personalLogScenario.js
Normal file
98
example/personalLog/scenario/personalLogScenario.js
Normal file
|
|
@ -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();
|
||||
});
|
||||
};
|
||||
});
|
||||
10
example/personalLog/scenario/runner.html
Normal file
10
example/personalLog/scenario/runner.html
Normal file
|
|
@ -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>
|
||||
|
|
@ -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(/\[\]/);
|
||||
});
|
||||
});
|
||||
|
|
|
|||
Loading…
Reference in a new issue