Ported Jasmine integration tests over to Qunit tests. Kept these in a different folder of integration tests has there purpose is to test at a page level rather then a method by method level.

This commit is contained in:
Jesse Streb 2010-12-24 08:27:24 -05:00
parent 60da49c6b9
commit 35c2fe8aa5
9 changed files with 222 additions and 3145 deletions

View file

@ -1,20 +0,0 @@
Copyright (c) 2008-2010 Pivotal Labs
Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
"Software"), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:
The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

View file

@ -1,188 +0,0 @@
jasmine.TrivialReporter = function(doc) {
this.document = doc || document;
this.suiteDivs = {};
this.logRunningSpecs = false;
};
jasmine.TrivialReporter.prototype.createDom = function(type, attrs, childrenVarArgs) {
var el = document.createElement(type);
for (var i = 2; i < arguments.length; i++) {
var child = arguments[i];
if (typeof child === 'string') {
el.appendChild(document.createTextNode(child));
} else {
if (child) { el.appendChild(child); }
}
}
for (var attr in attrs) {
if (attr == "className") {
el[attr] = attrs[attr];
} else {
el.setAttribute(attr, attrs[attr]);
}
}
return el;
};
jasmine.TrivialReporter.prototype.reportRunnerStarting = function(runner) {
var showPassed, showSkipped;
this.outerDiv = this.createDom('div', { className: 'jasmine_reporter' },
this.createDom('div', { className: 'banner' },
this.createDom('div', { className: 'logo' },
this.createDom('a', { href: 'http://pivotal.github.com/jasmine/', target: "_blank" }, "Jasmine"),
this.createDom('span', { className: 'version' }, runner.env.versionString())),
this.createDom('div', { className: 'options' },
"Show ",
showPassed = this.createDom('input', { id: "__jasmine_TrivialReporter_showPassed__", type: 'checkbox' }),
this.createDom('label', { "for": "__jasmine_TrivialReporter_showPassed__" }, " passed "),
showSkipped = this.createDom('input', { id: "__jasmine_TrivialReporter_showSkipped__", type: 'checkbox' }),
this.createDom('label', { "for": "__jasmine_TrivialReporter_showSkipped__" }, " skipped")
)
),
this.runnerDiv = this.createDom('div', { className: 'runner running' },
this.createDom('a', { className: 'run_spec', href: '?' }, "run all"),
this.runnerMessageSpan = this.createDom('span', {}, "Running..."),
this.finishedAtSpan = this.createDom('span', { className: 'finished-at' }, ""))
);
this.document.body.appendChild(this.outerDiv);
var suites = runner.suites();
for (var i = 0; i < suites.length; i++) {
var suite = suites[i];
var suiteDiv = this.createDom('div', { className: 'suite' },
this.createDom('a', { className: 'run_spec', href: '?spec=' + encodeURIComponent(suite.getFullName()) }, "run"),
this.createDom('a', { className: 'description', href: '?spec=' + encodeURIComponent(suite.getFullName()) }, suite.description));
this.suiteDivs[suite.id] = suiteDiv;
var parentDiv = this.outerDiv;
if (suite.parentSuite) {
parentDiv = this.suiteDivs[suite.parentSuite.id];
}
parentDiv.appendChild(suiteDiv);
}
this.startedAt = new Date();
var self = this;
showPassed.onclick = function(evt) {
if (showPassed.checked) {
self.outerDiv.className += ' show-passed';
} else {
self.outerDiv.className = self.outerDiv.className.replace(/ show-passed/, '');
}
};
showSkipped.onclick = function(evt) {
if (showSkipped.checked) {
self.outerDiv.className += ' show-skipped';
} else {
self.outerDiv.className = self.outerDiv.className.replace(/ show-skipped/, '');
}
};
};
jasmine.TrivialReporter.prototype.reportRunnerResults = function(runner) {
var results = runner.results();
var className = (results.failedCount > 0) ? "runner failed" : "runner passed";
this.runnerDiv.setAttribute("class", className);
//do it twice for IE
this.runnerDiv.setAttribute("className", className);
var specs = runner.specs();
var specCount = 0;
for (var i = 0; i < specs.length; i++) {
if (this.specFilter(specs[i])) {
specCount++;
}
}
var message = "" + specCount + " spec" + (specCount == 1 ? "" : "s" ) + ", " + results.failedCount + " failure" + ((results.failedCount == 1) ? "" : "s");
message += " in " + ((new Date().getTime() - this.startedAt.getTime()) / 1000) + "s";
this.runnerMessageSpan.replaceChild(this.createDom('a', { className: 'description', href: '?'}, message), this.runnerMessageSpan.firstChild);
this.finishedAtSpan.appendChild(document.createTextNode("Finished at " + new Date().toString()));
};
jasmine.TrivialReporter.prototype.reportSuiteResults = function(suite) {
var results = suite.results();
var status = results.passed() ? 'passed' : 'failed';
if (results.totalCount == 0) { // todo: change this to check results.skipped
status = 'skipped';
}
this.suiteDivs[suite.id].className += " " + status;
};
jasmine.TrivialReporter.prototype.reportSpecStarting = function(spec) {
if (this.logRunningSpecs) {
this.log('>> Jasmine Running ' + spec.suite.description + ' ' + spec.description + '...');
}
};
jasmine.TrivialReporter.prototype.reportSpecResults = function(spec) {
var results = spec.results();
var status = results.passed() ? 'passed' : 'failed';
if (results.skipped) {
status = 'skipped';
}
var specDiv = this.createDom('div', { className: 'spec ' + status },
this.createDom('a', { className: 'run_spec', href: '?spec=' + encodeURIComponent(spec.getFullName()) }, "run"),
this.createDom('a', {
className: 'description',
href: '?spec=' + encodeURIComponent(spec.getFullName()),
title: spec.getFullName()
}, spec.description));
var resultItems = results.getItems();
var messagesDiv = this.createDom('div', { className: 'messages' });
for (var i = 0; i < resultItems.length; i++) {
var result = resultItems[i];
if (result.type == 'log') {
messagesDiv.appendChild(this.createDom('div', {className: 'resultMessage log'}, result.toString()));
} else if (result.type == 'expect' && result.passed && !result.passed()) {
messagesDiv.appendChild(this.createDom('div', {className: 'resultMessage fail'}, result.message));
if (result.trace.stack) {
messagesDiv.appendChild(this.createDom('div', {className: 'stackTrace'}, result.trace.stack));
}
}
}
if (messagesDiv.childNodes.length > 0) {
specDiv.appendChild(messagesDiv);
}
this.suiteDivs[spec.suite.id].appendChild(specDiv);
};
jasmine.TrivialReporter.prototype.log = function() {
var console = jasmine.getGlobal().console;
if (console && console.log) {
if (console.log.apply) {
console.log.apply(console, arguments);
} else {
console.log(arguments); // ie fix: console.log.apply doesn't exist on ie
}
}
};
jasmine.TrivialReporter.prototype.getLocation = function() {
return this.document.location;
};
jasmine.TrivialReporter.prototype.specFilter = function(spec) {
var paramMap = {};
var params = this.getLocation().search.substring(1).split('&');
for (var i = 0; i < params.length; i++) {
var p = params[i].split('=');
paramMap[decodeURIComponent(p[0])] = decodeURIComponent(p[1]);
}
if (!paramMap["spec"]) return true;
return spec.getFullName().indexOf(paramMap["spec"]) == 0;
};

View file

@ -1,166 +0,0 @@
body {
font-family: "Helvetica Neue Light", "Lucida Grande", "Calibri", "Arial", sans-serif;
}
.jasmine_reporter a:visited, .jasmine_reporter a {
color: #303;
}
.jasmine_reporter a:hover, .jasmine_reporter a:active {
color: blue;
}
.run_spec {
float:right;
padding-right: 5px;
font-size: .8em;
text-decoration: none;
}
.jasmine_reporter {
margin: 0 5px;
}
.banner {
color: #303;
background-color: #fef;
padding: 5px;
}
.logo {
float: left;
font-size: 1.1em;
padding-left: 5px;
}
.logo .version {
font-size: .6em;
padding-left: 1em;
}
.runner.running {
background-color: yellow;
}
.options {
text-align: right;
font-size: .8em;
}
.suite {
border: 1px outset gray;
margin: 5px 0;
padding-left: 1em;
}
.suite .suite {
margin: 5px;
}
.suite.passed {
background-color: #dfd;
}
.suite.failed {
background-color: #fdd;
}
.spec {
margin: 5px;
padding-left: 1em;
clear: both;
}
.spec.failed, .spec.passed, .spec.skipped {
padding-bottom: 5px;
border: 1px solid gray;
}
.spec.failed {
background-color: #fbb;
border-color: red;
}
.spec.passed {
background-color: #bfb;
border-color: green;
}
.spec.skipped {
background-color: #bbb;
}
.messages {
border-left: 1px dashed gray;
padding-left: 1em;
padding-right: 1em;
}
.passed {
background-color: #cfc;
display: none;
}
.failed {
background-color: #fbb;
}
.skipped {
color: #777;
background-color: #eee;
display: none;
}
/*.resultMessage {*/
/*white-space: pre;*/
/*}*/
.resultMessage span.result {
display: block;
line-height: 2em;
color: black;
}
.resultMessage .mismatch {
color: black;
}
.stackTrace {
white-space: pre;
font-size: .8em;
margin-left: 10px;
max-height: 5em;
overflow: auto;
border: 1px inset red;
padding: 1em;
background: #eef;
}
.finished-at {
padding-left: 1em;
font-size: .6em;
}
.show-passed .passed,
.show-skipped .skipped {
display: block;
}
#jasmine_content {
position:fixed;
right: 100%;
}
.runner {
border: 1px solid gray;
display: block;
margin: 5px 0;
padding: 2px 0 2px 10px;
}

File diff suppressed because it is too large Load diff

View file

@ -1,49 +0,0 @@
/*function basicListViewHTML() {
var html = '<ul data-role="listview" data-theme="g">\
<li><a href="acura.html">Acura</a></li>\
<li><a href="audi.html">Audi</a></li>\
<li><a href="bmw.html">BMW</a></li>\
</ul>';
return html;
}*/
var listViewHelper = {};
(function ($, lvh, undefined ) {
var current_page
, pageShowFired = false;
lvh.resetForPage = function(new_page) {
//remove any old event listeners from the current page if defined
if(current_page)
current_page.die('pageshow', lvh.pageshowHandler);
pageShowFired = false;
current_page = new_page;
current_page.live('pageshow', lvh.pageshowHandler);
}
lvh.currentPage = function() {
return current_page;
}
lvh.transitionComplete = function() {
return pageShowFired;
}
lvh.pageshowHandler = function() {
pageShowFired = true;
}
lvh.showResultsWhenComplete = function() {
if($('.jasmine_reporter .running').length == 0) {
$('.ui-page-active').css('display', 'none');
} else {
setTimeout(lvh.showResultsWhenComplete, 500);
}
}
setTimeout(lvh.showResultsWhenComplete, 500);
})(jQuery, listViewHelper)

View file

@ -1,29 +1,25 @@
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<!DOCTYPE html>
<html lang="en">
<head>
<title>Integration Test Runner</title>
<link rel="stylesheet" href="../../themes/default" />
<script type="text/javascript" src="../../js/"></script>
<meta charset="UTF-8" />
<title>jQuery Mobile Listview Integration Test</title>
<link rel="stylesheet" type="text/css" href="../../external/jasmine-1.0.1/jasmine.css">
<script type="text/javascript" src="../../external/jasmine-1.0.1/jasmine.js"></script>
<script type="text/javascript" src="../../external/jasmine-1.0.1/jasmine-html.js"></script>
<script type="text/javascript" src="./helpers/spec_helpers.js"></script>
<!-- include source files here... -->
<!-- include spec files here... -->
<script type="text/javascript" src="specs/ListviewSpec.js"></script>
<script type="text/javascript" src="../../../js/"></script>
<script type="text/javascript" src="../../jquery.testHelper.js"></script>
<link rel="stylesheet" href="../../../themes/default" />
<link rel="stylesheet" href="../../../external/qunit.css" type="text/css"/>
<script type="text/javascript" src="../../../external/qunit.js"></script>
<script type="text/javascript" src="listview_integration.js"></script>
</head>
<body>
<script type="text/javascript">
jasmine.getEnv().addReporter(new jasmine.TrivialReporter());
jasmine.getEnv().execute();
</script>
<h1 id="qunit-header">jQuery Mobile Listview Integration Test</h1>
<h2 id="qunit-banner"></h2>
<h2 id="qunit-userAgent"></h2>
<ol id="qunit-tests">
</ol>
<!-- Basic Linked view test -->
<div data-role="page" id='basic-linked-test'>
<div data-role="header" data-position="inline">
@ -170,6 +166,5 @@
</div>
</div>
</body>
</html>

View file

@ -0,0 +1,197 @@
$.testHelper.hideActivePageWhenComplete()
module('Basic Linked list');
asyncTest( "The page should enhanced correctly", function(){
setTimeout(function() {
ok($('.ui-page-active').length > 0, "ui-page-active added to current page");
ok($('.ui-page-active [role="option"]').length == 3, "roles added to li elements");
start();
}, 100)
});
asyncTest( "Slides to the listview page when the li is clicked", function() {
$('.ui-page-active li').first().click();
setTimeout(function() {
ok($('#basic-link-results').hasClass('ui-page-active'));
start();
}, 1000)
});
asyncTest( "Slides back to main page when back button is clicked", function() {
$('#basic-link-results a:contains("Back")').click();
setTimeout(function() {
ok($('#basic-linked-test').hasClass('ui-page-active'));
start();
}, 1000)
});
module('Nested List Test')
asyncTest( "Changes page to nested list test and enhances", function() {
location.href = location.href.split('#')[0] + "#nested-list-test";
setTimeout(function() {
ok($('#nested-list-test').hasClass('ui-page-active'), "makes nested list test page active");
ok($('[role="option"]', $('#nested-list-test')).length == 2, 'Adds data role to the two LIs');
ok($('body > [data-url="nested-list-test&ui-page=More-animals-0"]').length == 1, "Adds first UL to the page");
ok($('body > [data-url="nested-list-test&ui-page=Groups-of-animals-1"]').length == 1, "Adds second nested UL to the page");
start();
}, 1000)
})
asyncTest( "change to nested page when the li is clicked", function() {
$('.ui-page-active li:eq(1)').click();
setTimeout(function() {
var $new_page = $('body > [data-url="nested-list-test&ui-page=More-animals-0"]');
ok($new_page.hasClass('ui-page-active'), 'Makes the nested page the active page.');
ok($('.ui-listview', $new_page).find(":contains('Rhumba of rattlesnakes')").length == 1, "The current page should have the proper text in the list.");
ok($('.ui-listview', $new_page).find(":contains('Shoal of Bass')").length == 1, "The current page should have the proper text in the list.");
start();
}, 1000);
})
asyncTest( "should go back to top level when the back button is clicked", function() {
$('body > [data-url="nested-list-test&ui-page=More-animals-0"]').find('a:contains("Back")').click();
setTimeout(function() {
ok($('#nested-list-test').hasClass('ui-page-active'), 'Transitions back to the parent nested page');
start();
}, 1000);
})
module('Ordered Lists')
asyncTest( "changes to the numbered list page and enhances it", function() {
location.href = location.href.split('#')[0] + "#numbered-list-test";
setTimeout(function() {
var $new_page = $('#numbered-list-test');
ok($new_page.hasClass('ui-page-active'), "Makes the new page active when the hash is changed.");
ok($('[role="option"]', $new_page).length == 3, "There should be three LI that are enhanced");
ok($('.ui-link-inherit', $new_page).first().text() == "Number 1", "The text of the first LI should be Number 1");
start();
}, 1000);
});
asyncTest( "changes to number 1 page when the li is clicked", function() {
$('.ui-page-active li').first().click();
setTimeout(function() {
ok($('#numbered-list-results').hasClass('ui-page-active'), "The new numbered page was transitioned correctly.")
start();
}, 1000);
});
asyncTest( "takes us back to the numbered list when the back button is clicked", function() {
$('.ui-page-active a:contains("Back")').click();
setTimeout(function() {
ok($('#numbered-list-test').hasClass('ui-page-active'));
start();
}, 1000);
})
module('Read only list')
asyncTest( "changes to the read only page when hash is changed", function() {
location.href = location.href.split('#')[0] + "#read-only-list-test";
setTimeout(function() {
var $new_page = $('#read-only-list-test');
ok($new_page.hasClass('ui-page-active'), "makes the read only page the active page");
ok($('[role="option"]', $new_page).length === 4, "There are 4 li that enhanced as role options");
ok($('li', $new_page).first().text() === "Read", "The first LI has the proper text.");
start();
}, 1000);
});
asyncTest( "Does not go to new page when an item is clicked", function() {
$('li', $('#read-only-list-test').first().click())
setTimeout(function() {
ok($('.ui-page-active').attr('id') == "read-only-list-test", "Page does not change for read only lists")
start();
}, 1000);
});
module('Split view list')
asyncTest( "changes the page to the split view list and enhances it correctly.", function() {
location.href = location.href.split('#')[0] + "#split-list-test";
setTimeout(function() {
var $new_page = $('#split-list-test');
ok($('[role="option"]', $new_page).length == 3);
ok($('.ui-li-link-alt', $new_page).length == 3);
ok($('.ui-link-inherit', $new_page).length == 3);
start();
}, 1000);
});
asyncTest( "change the page to the split view page 1 when the first link is clicked", function() {
$('.ui-page-active [role="option"]:eq(0)').click();
setTimeout(function() {
ok($('#split-list-link1').hasClass('ui-page-active'));
start();
}, 1000);
});
asyncTest( "Slide back to the parent list view when the back button is clicked", function() {
$('.ui-page-active a:contains("Back")').click();
setTimeout(function() {
ok($('#split-list-test').hasClass('ui-page-active'));
start();
}, 1000);
});
asyncTest( "Clicking on the icon (the second link) should take the user to other a href of this LI", function() {
$('.ui-page-active .ui-li-link-alt:eq(0)').click();
setTimeout(function() {
ok($('#split-list-link2').hasClass('ui-page-active'));
start();
}, 1000);
});
asyncTest( "Slide back to the parent list view when the back button is clicked", function() {
$('.ui-page-active a:contains("Back")').click();
setTimeout(function() {
ok($('#split-list-test').hasClass('ui-page-active'));
start();
}, 1000);
});
module( "List Dividers" );
asyncTest( "Makes the list divider page the active page and enhances it correctly.", function() {
location.href = location.href.split('#')[0] + "#list-divider-test";
setTimeout(function() {
var $new_page = $('#list-divider-test');
ok($new_page.find('.ui-li-divider').length == 2);
ok($new_page.hasClass('ui-page-active'));
start();
}, 1000);
});
module( "Search Filter" );
asyncTest( "Make the search filter page the actie page and enhance it correctly.", function() {
location.href = location.href.split('#')[0] + "#search-filter-test";
setTimeout(function() {
var $new_page = $('#search-filter-test');
ok($new_page.find('input').length == 1);
ok($new_page.hasClass('ui-page-active'));
start();
}, 1000);
});
asyncTest( "Filter downs results when the user enters information", function() {
$('.ui-page-active input').val('at');
$('.ui-page-active input').trigger('change');
setTimeout(function() {
ok($('.ui-page-active li[style="display: none; "]').length == 2);
start();
}, 1000);
});
asyncTest( "Redisplay results when user removes values", function() {
$('.ui-page-active input').val('a')
$('.ui-page-active input').trigger('change');
setTimeout(function() {
ok($('.ui-page-active li[style="display: none; "]').length == 0)
start();
}, 1000);
});

View file

@ -1,280 +0,0 @@
describe("Listviews", function() {
describe("Basic Linked list", function() {
it("should setup the listview correctly", function() {
waitsFor(function() {
return ($('.ui-page-active').length > 0)
})
runs(function() {
expect($('.ui-page-active .ui-listview').length).toEqual(1);
expect($('.ui-page-active [role="option"]').length).toEqual(3);
})
});
it("should slide the listview page into view when the list view link is clicked", function() {
listViewHelper.resetForPage($('#basic-link-results'))
$('.ui-page-active li').first().click();
waitsFor(function() {
return listViewHelper.transitionComplete();
})
runs(function() {
expect(listViewHelper.currentPage().hasClass('ui-page-active')).toBeTruthy();
})
});
it("should slide back to the main page when the back button is clicked", function() {
listViewHelper.resetForPage($('#basic-linked-test'))
$('#basic-link-results a:contains("Back")').click();
waitsFor(function() {
return listViewHelper.transitionComplete();
})
runs(function() {
expect(listViewHelper.currentPage().hasClass('ui-page-active')).toBeTruthy();
});
});
});
describe("Nested List", function() {
it("should change the page to the nested list and make sure the page was enhanced.", function() {
listViewHelper.resetForPage($('#nested-list-test'))
location.href = "http://localhost:8888/tests/integration/runner.html#nested-list-test";
$.mobile.changePage(listViewHelper.currentPage());
waitsFor(function() {
return listViewHelper.transitionComplete();
})
runs(function() {
expect(listViewHelper.currentPage().hasClass('ui-page-active')).toBeTruthy();
expect($('[role="option"]', listViewHelper.currentPage()).length).toEqual(2);
expect($('body > [data-url="nested-list-test&ui-page=More-animals-0"]').length).toEqual(1);
expect($('body > [data-url="nested-list-test&ui-page=Groups-of-animals-1"]').length).toEqual(1);
});
});
it("should change to nested page when it is clicked", function() {
listViewHelper.resetForPage($('body > [data-url="nested-list-test&ui-page=More-animals-0"]'));
$('.ui-page-active li:eq(1)').click();
waitsFor(function() {
return listViewHelper.transitionComplete();
});
runs(function() {
expect(listViewHelper.currentPage().hasClass('ui-page-active')).toBeTruthy();
expect($('[role="option"]', listViewHelper.currentPage()).length).toEqual(2);
expect($('.ui-listview', listViewHelper.currentPage()).find(":contains('Rhumba of rattlesnakes')").length).toEqual(1);
expect($('.ui-listview', listViewHelper.currentPage()).find(":contains('Shoal of Bass')").length).toEqual(1);
});
});
it("should go back to top level when the back button is clicked", function() {
listViewHelper.resetForPage($('#nested-list-test'));
$('body > [data-url="nested-list-test&ui-page=More-animals-0"]').find('a:contains("Back")').click();
waitsFor(function() {
return listViewHelper.transitionComplete();
});
runs(function() {
expect(listViewHelper.currentPage().hasClass('ui-page-active')).toBeTruthy();
});
});
});
describe("Ordered Lists", function() {
it("should change the page to the numbered list and make sure the page was enhanced.", function() {
listViewHelper.resetForPage($('#numbered-list-test'));
location.href = "http://localhost:8888/tests/integration/runner.html#numbered-list-test";
$.mobile.changePage(listViewHelper.currentPage());
waitsFor(function() {
return listViewHelper.transitionComplete();
});
runs(function() {
expect(listViewHelper.currentPage().hasClass('ui-page-active')).toBeTruthy();
expect($('[role="option"]', listViewHelper.currentPage()).length).toEqual(3);
expect($('.ui-link-inherit', listViewHelper.currentPage()).first().text()).toEqual("Number 1");
});
});
it("should take us to number 1 page when click", function() {
listViewHelper.resetForPage($('#numbered-list-results'));
$('.ui-page-active li').first().click();
waitsFor(function() {
return listViewHelper.transitionComplete();
});
runs(function() {
expect(listViewHelper.currentPage().hasClass('ui-page-active')).toBeTruthy();
})
});
it("should slide back to the main numbered page when the back button is clicked", function() {
listViewHelper.resetForPage($('#numbered-list-test'));
$('.ui-page-active a:contains("Back")').click();
waitsFor(function() {
return listViewHelper.transitionComplete();
});
runs(function() {
expect(listViewHelper.currentPage().hasClass('ui-page-active')).toBeTruthy();
});
});
});
describe("read only list", function() {
it("should change the page to the Read only list and make sure the page was enhanced.", function() {
listViewHelper.resetForPage($('#read-only-list-test'));
location.href = "http://localhost:8888/tests/integration/runner.html#read-only-list-test";
$.mobile.changePage(listViewHelper.currentPage());
waitsFor(function() {
return listViewHelper.transitionComplete();
});
runs(function() {
expect(listViewHelper.currentPage().hasClass('ui-page-active')).toBeTruthy();
expect($('[role="option"]', listViewHelper.currentPage()).length).toEqual(4);
expect($('li', listViewHelper.currentPage()).first().text()).toEqual("Read");
});
});
it("should not take us to new page when a list item clicked", function() {
var current_page = $('#read-only-list-test');
$('li', current_page).first().click();
//wait a second to make sure that we give it time to transition if it is going to. It shouldn't
waits(1000);
runs(function() {
expect($('.ui-page-active').attr('id')).toEqual('read-only-list-test');
})
});
});
describe("split view list", function() {
it("should change the page to the split view and list view and enhance the page correctly.", function() {
listViewHelper.resetForPage($('#split-list-test'));
location.href = "http://localhost:8888/tests/integration/runner.html#split-list-test";
$.mobile.changePage(listViewHelper.currentPage());
waitsFor(function() {
return listViewHelper.transitionComplete();
});
runs(function() {
expect(listViewHelper.currentPage().hasClass('ui-page-active')).toBeTruthy();
expect($('[role="option"]', listViewHelper.currentPage()).length).toEqual(3);
expect($('.ui-li-link-alt', listViewHelper.currentPage()).length).toEqual(3);
expect($('.ui-link-inherit', listViewHelper.currentPage()).length).toEqual(3);
});
});
it("should change the page to split view page 1 when the first link is clicked", function() {
listViewHelper.resetForPage($('#split-list-link1'));
$('.ui-page-active [role="option"]:eq(0)').click();
waitsFor(function() {
return listViewHelper.transitionComplete();
});
runs(function() {
expect(listViewHelper.currentPage().hasClass('ui-page-active')).toBeTruthy();
});
});
it("should slide the page back to the split list view when the back button is clicked", function() {
listViewHelper.resetForPage($('#split-list-test'));
$('.ui-page-active a:contains("Back")').click();
waitsFor(function() {
return listViewHelper.transitionComplete();
});
runs(function() {
expect(listViewHelper.currentPage().hasClass('ui-page-active')).toBeTruthy();
});
});
/*
* Once the bug in which the changePage call does not update the hash correctly, resulting in the back button
* going back to the wrong page is fixed, then we should implement these tests.
*/
it("should slide to the second link when the right icon is clicked", function() {
//pending
})
it("should slide back to the split list view page when teh back button is clicked", function() {
//pending
});
});
describe("List dividers", function() {
it("should make the list divider page the active page and enhance it correctly.", function() {
listViewHelper.resetForPage($('#list-divider-test'));
location.href = "http://localhost:8888/tests/integration/runner.html#list-divider-test";
$.mobile.changePage(listViewHelper.currentPage());
waitsFor(function() {
return listViewHelper.transitionComplete();
});
runs(function() {
expect($('.ui-page-active .ui-li-divider').length).toEqual(2);
expect(listViewHelper.currentPage().hasClass('ui-page-active')).toBeTruthy();
});
});
});
describe("Search Filter", function() {
it("should make the search filter page the active page and enhance it correctly.", function() {
listViewHelper.resetForPage($('#search-filter-test'));
location.href = "http://localhost:8888/tests/integration/runner.html#search-filter-test";
$.mobile.changePage(listViewHelper.currentPage());
waitsFor(function() {
return listViewHelper.transitionComplete();
});
runs(function() {
expect($('.ui-page-active input').length).toEqual(1)
expect(listViewHelper.currentPage().hasClass('ui-page-active')).toBeTruthy();
});
});
it("should filter down the results when the user enters information", function() {
$('.ui-page-active input').val('at');
$('.ui-page-active input').trigger('change');
waitsFor(function() {
return $('.ui-page-active li[style="display: none; "]').length == 2;
})
runs(function() {
expect( $('.ui-page-active li[style="display: none; "]').length).toEqual(2);
});
});
it("if user removes values it should redisplay the results", function() {
$('.ui-page-active input').val('a')
$('.ui-page-active input').trigger('change');
waitsFor(function() {
return $('.ui-page-active li[style="display: none; "]').length == 0;
})
runs(function() {
expect( $('.ui-page-active li[style="display: none; "]').length).toEqual(0);
});
});
});
});

View file

@ -45,6 +45,15 @@
result = extendFn(result, extraExtension);
return result;
};
},
hideActivePageWhenComplete: function() {
if( $('#qunit-testresult').length > 0 ) {
$('.ui-page-active').css('display', 'none');
//location.href = location.href.split('#')[0];
} else {
setTimeout($.testHelper.hideActivePageWhenComplete, 500);
}
}
};
})(jQuery);