# HG changeset patch # User Adrien Di Mascio # Date 1278609536 -7200 # Node ID f84dba9b8eca763347383be35b9b205e2911eb58 # Parent 2a273c896a38b5fdfc2239d861c14682cfdb1bc0 [test] fix test_ajax js tests. We have to mock some of our js functions / variables (e.g. _ or pageid) in the test environment diff -r 2a273c896a38 -r f84dba9b8eca devtools/data/cwmock.js --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/devtools/data/cwmock.js Thu Jul 08 19:18:56 2010 +0200 @@ -0,0 +1,11 @@ +/* + * cubicweb js mock for unit tests + * This module defines variables and functions used in quite a few places + * in cw js framework that can't be used or guessed without a real CW server + */ + +var pageid = 'my-page-id'; + +function _(message) { + return message; +} diff -r 2a273c896a38 -r f84dba9b8eca devtools/qunit.py --- a/devtools/qunit.py Thu Jul 08 18:59:42 2010 +0200 +++ b/devtools/qunit.py Thu Jul 08 19:18:56 2010 +0200 @@ -273,6 +273,7 @@ + ''' % data] if server_data is not None: diff -r 2a273c896a38 -r f84dba9b8eca web/test/jstests/test_ajax.html --- a/web/test/jstests/test_ajax.html Thu Jul 08 18:59:42 2010 +0200 +++ b/web/test/jstests/test_ajax.html Thu Jul 08 19:18:56 2010 +0200 @@ -9,9 +9,10 @@ - - + + + diff -r 2a273c896a38 -r f84dba9b8eca web/test/jstests/test_ajax.js --- a/web/test/jstests/test_ajax.js Thu Jul 08 18:59:42 2010 +0200 +++ b/web/test/jstests/test_ajax.js Thu Jul 08 19:18:56 2010 +0200 @@ -1,5 +1,16 @@ $(document).ready(function() { + module("ajax", { + setup: function() { + this.scriptsLength = $('head script[src]').length-1; + this.cssLength = $('head link[rel=stylesheet]').length-1; + }, + teardown: function() { + $('head script[src]:gt(' + this.scriptsLength + ')').remove(); + $('head link[rel=stylesheet]:gt(' + this.cssLength + ')').remove(); + } + }); + function jsSources() { return $.map($('head script[src]'), function(script) { return script.getAttribute('src'); @@ -161,18 +172,21 @@ callback: function() { var origLength = scriptsIncluded.length; scriptsIncluded = jsSources(); - // check that foo.js has been inserted in - equals(scriptsIncluded.length, origLength + 1); - equals(scriptsIncluded[origLength].indexOf('http://foo.js'), 0); - // check that
has been removed - equals(jQuery('#main').children().length, 1); - equals(jQuery('div.ajaxHtmlHead').length, 0); - equals(jQuery('#main h1').html(), 'Hello'); - // qunit.css is not added twice - equals(jQuery('head link').length, 1); - /* use endswith because in pytest context we have an absolute path */ - ok(jQuery('head link').attr('href').endswith('/qunit.css')); - start(); + try { + // check that foo.js has been inserted in + equals(scriptsIncluded.length, origLength + 1); + equals(scriptsIncluded[origLength].indexOf('http://foo.js'), 0); + // check that
has been removed + equals(jQuery('#main').children().length, 1); + equals(jQuery('div.ajaxHtmlHead').length, 0); + equals(jQuery('#main h1').html(), 'Hello'); + // qunit.css is not added twice + equals(jQuery('head link').length, 1); + /* use endswith because in pytest context we have an absolute path */ + ok(jQuery('head link').attr('href').endswith('/qunit.css')); + } finally { + start(); + } } }); }); diff -r 2a273c896a38 -r f84dba9b8eca web/test/jstests/test_htmlhelpers.html --- a/web/test/jstests/test_htmlhelpers.html Thu Jul 08 18:59:42 2010 +0200 +++ b/web/test/jstests/test_htmlhelpers.html Thu Jul 08 19:18:56 2010 +0200 @@ -7,6 +7,7 @@ + diff -r 2a273c896a38 -r f84dba9b8eca web/test/jstests/test_utils.html --- a/web/test/jstests/test_utils.html Thu Jul 08 18:59:42 2010 +0200 +++ b/web/test/jstests/test_utils.html Thu Jul 08 19:18:56 2010 +0200 @@ -8,6 +8,7 @@ +