Index: trunk/extensions/MobileFrontend/tests/js/test_opensearch.js |
— | — | @@ -0,0 +1,84 @@ |
| 2 | +var MFEOS = MobileFrontend.opensearch; |
| 3 | + |
| 4 | +module("MobileFrontend opensearch.js - writeResults", { |
| 5 | + setup: function() { |
| 6 | + $('<input type="search" id="search">').appendTo(document.body); |
| 7 | + $('<div id="results"></div>').appendTo(document.body); |
| 8 | + }, |
| 9 | + teardown: function() { |
| 10 | + $("#results,#search").remove(); |
| 11 | + } |
| 12 | +}); |
| 13 | +test("no results", function() { |
| 14 | + MFEOS.writeResults([]); |
| 15 | + strictEqual($("#results").text(), "No results"); |
| 16 | +}); |
| 17 | + |
| 18 | +test("writeResults", function() { |
| 19 | + var results = [ |
| 20 | + { label: "Hello world", value: "/HelloWorld" }, |
| 21 | + { label: "Hello kitty", value: "/HelloKitty" } |
| 22 | + ]; |
| 23 | + MFEOS.writeResults(results); |
| 24 | + strictEqual($("#results .suggestions-results").length, 1, "1 wrapper for results"); |
| 25 | + strictEqual($("#results .suggestions-results .suggestions-result").length, 2, "2 results"); |
| 26 | + strictEqual($("#results .suggestions-results .suggestions-result a").length, 4, "2 links in 2 results = 4"); |
| 27 | + var autocomplete = $("#results .suggestions-result a.sq-val-update")[0]; |
| 28 | + var pageLink = $("#results .suggestions-result a.search-result-item")[0]; |
| 29 | + strictEqual($(autocomplete).text(), "+", "check plus link is there"); |
| 30 | + strictEqual($(pageLink).text(), "Hello world", "check the label is correct"); |
| 31 | + strictEqual($(pageLink).attr("href"), "/HelloWorld", "check the href is correct"); |
| 32 | + MFET.triggerEvent(autocomplete, "click"); |
| 33 | + strictEqual($("#search").val(), "Hello world ", "check the value has passed across to the search box"); |
| 34 | +}); |
| 35 | + |
| 36 | +module("MobileFrontend opensearch.js", { |
| 37 | + setup: function() { |
| 38 | + $("#results").remove(); |
| 39 | + var html = '<div class="suggestions-result"><a class="sq-val-update">+</a><a class="search-result-item">label</a></div>'; |
| 40 | + $('<div id="results" />').html(html).appendTo(document.body); |
| 41 | + $(document.body).show(); |
| 42 | + MFEOS.init(); |
| 43 | + }, |
| 44 | + teardown: function() { |
| 45 | + $('#results').remove(); |
| 46 | + } |
| 47 | +}); |
| 48 | + |
| 49 | +test("clear results (mouse down on body element)", function() { |
| 50 | + var results = $("#results"); |
| 51 | + var initialVisibility = results.is(":visible"); |
| 52 | + MFET.triggerEvent(document.body, "mousedown"); |
| 53 | + var nowVisibility = results.is(":visible"); |
| 54 | + strictEqual(initialVisibility, true, "visible at start"); |
| 55 | + strictEqual(nowVisibility, false, "hidden at end"); |
| 56 | +}); |
| 57 | + |
| 58 | +test("clear results (mousedown on child of #results)", function() { |
| 59 | + var initialVisibility = $("#results").is(":visible"); |
| 60 | + MFET.triggerEvent($("#results .sq-val-update")[0], "mousedown"); |
| 61 | + strictEqual(initialVisibility, true, "visible at start"); |
| 62 | + strictEqual($("#results").is(":visible"), true, "visible at end"); |
| 63 | +}); |
| 64 | + |
| 65 | +test("clear results (mousedown on #results element)", function() { |
| 66 | + var initialVisibility = $("#results").is(":visible"); |
| 67 | + MFET.triggerEvent($("#results")[0], "mousedown"); |
| 68 | + var nowVisibility = $("#results").is(":visible"); |
| 69 | + strictEqual(initialVisibility, true, "visible at start"); |
| 70 | + strictEqual(nowVisibility, false, "hidden at end"); |
| 71 | +}); |
| 72 | + |
| 73 | +test("createObjectArray", function() { |
| 74 | + var xmlString = ["<SearchSuggestion>", "<Query>Turing</Query>", |
| 75 | + "<Section>", |
| 76 | + "<Item><Text>Alan Turing</Text><Url>http://en.wikipedia.org/wiki/Turing</Url></Item>", |
| 77 | + "<Item><Text>Turing Machine</Text><Url>http://en.wikipedia.org/wiki/Turing_machine</Url></Item>", |
| 78 | + "</Section></SearchSuggestion>"].join(""); |
| 79 | + var xml = $(xmlString)[0] |
| 80 | + var obj = MFEOS.createObjectArray(xml); |
| 81 | + strictEqual(obj.length, 2, "2 results should be found"); |
| 82 | + strictEqual(obj[0].label, "Alan Turing", "check label"); |
| 83 | + strictEqual(obj[0].value, "http://en.wikipedia.org/wiki/Turing", "check value"); |
| 84 | + strictEqual(obj[1].label, "Turing Machine", "check label"); |
| 85 | +}); |
Index: trunk/extensions/MobileFrontend/MobileFrontend.body.php |
— | — | @@ -1296,7 +1296,8 @@ |
1297 | 1297 | public function addTestModules( array &$testModules, ResourceLoader &$resourceLoader ) { |
1298 | 1298 | $testModules['qunit']['ext.mobilefrontend.tests'] = array( |
1299 | 1299 | 'scripts' => array( 'tests/js/fixtures.js', 'javascripts/application.js', |
1300 | | - 'tests/js/test_application.js' ), |
| 1300 | + 'javascripts/opensearch.js', |
| 1301 | + 'tests/js/test_application.js', 'tests/js/test_opensearch.js' ), |
1301 | 1302 | 'dependencies' => array( ), |
1302 | 1303 | 'localBasePath' => dirname( __FILE__ ), |
1303 | 1304 | 'remoteExtPath' => 'MobileFrontend', |