From cc1b0a8974aa695bfba67ead494dd7ce6bd61600 Mon Sep 17 00:00:00 2001 From: Stefano Mazzocchi Date: Thu, 6 May 2010 00:06:39 +0000 Subject: [PATCH] much less verbose js testing git-svn-id: http://google-refine.googlecode.com/svn/trunk@606 7d457c2a-affb-35e4-300a-418c747d4874 --- tests/windmill/js/facets.js | 37 +++++++++++++++ tests/windmill/js/initialize.js | 48 +++++++++++++++++++ tests/windmill/js/test_basic_functions.js | 57 ----------------------- 3 files changed, 85 insertions(+), 57 deletions(-) create mode 100644 tests/windmill/js/facets.js create mode 100644 tests/windmill/js/initialize.js delete mode 100644 tests/windmill/js/test_basic_functions.js diff --git a/tests/windmill/js/facets.js b/tests/windmill/js/facets.js new file mode 100644 index 000000000..cd025a390 --- /dev/null +++ b/tests/windmill/js/facets.js @@ -0,0 +1,37 @@ +var test_facets = new function() { + + // test opening Food project + this.test_open_project = [ + action("click", { link: "Food" } ), + action("waits.forPageLoad", { timeout: "20000" } ), + assert("gw_row_count", "7413" ) + ]; + + // create text facet from 1st word of Short Description + this.test_facet_creation = [ + action('click', { jquery: '(".column-header-layout tr:contains(\'Shrt_Desc\') .column-header-menu")[0]' } ), + action('mouseOver', { jquery: '("td:contains(\'Facet\')")[0]' } ), + action("gw_wait4menuitem", { name: 'Custom Text Facet' } ), + action("click", { jquery: '(".menu-item:contains(\'Custom Text Facet\')")[0]' } ), + action("type", { jquery: '(".expression-preview-code")[0]', text: "value.split(',')[0]" } ), + action("waits.forElement", { jquery: '("td:contains(\'value.split\')")[0]' } ), + action("click", { jquery: '("button:contains(\'OK\')")[0]' } ) + ]; + + // test created facet + this.test_created_facet = [ + action("waits.forElement", { jquery: '(".ui-button-text:contains(\'count\')")[0]' } ), + assert("gw_expected_top_value","ABALONE") + ]; + + // sort the facet by count and test the result + this.test_sorted_facet = [ + action("click", { jquery: '(".ui-button-text:contains(\'count\')")[0]' } ), + action("waits.forElement", { jquery: '(".ui-state-active .ui-button-text:contains(\'count\')")[0]' } ), + assert("gw_expected_top_value","BEEF") + ]; + +}; + + + diff --git a/tests/windmill/js/initialize.js b/tests/windmill/js/initialize.js new file mode 100644 index 000000000..8a1d36bae --- /dev/null +++ b/tests/windmill/js/initialize.js @@ -0,0 +1,48 @@ + +// ---------------------- actions extensions ---------------------------- + +var actions = windmill.jsTest.actions; + +function action(what,params) { + return { + method : what, + params : params + }; +} + +actions.gw_wait4ajaxend = function () { + return action("waits.forElement", { jquery: '("body[ajax_in_progress=\'false\']")[0]' } ); +}; +actions.gw_wait4menuitem = function (params) { + return action("waits.forElement", { jquery: '(".menu-item:contains(\'' + params.name + '\')")[0]' } ); +}; + +actions.gw_click_column_header = function (params) { + return action("click", { jquery: '(".column-header-layout tr:contains("' + params.column_name + '") .column-header-menu")[0]'} ); +}; + +// ---------------------- asserts extensions ---------------------------- + +var asserts = windmill.controller.asserts; + +function assert(what,params) { + return function() { + windmill.controller.asserts[what](params); + }; +} + +asserts.gw_row_count = function (count) { + asserts.assertText( { jquery: '(".viewPanel-summary-row-count")[0]', validator: count } ); +}; + +asserts.gw_expected_top_value = function (expected_value) { + asserts.assertEquals(expected_value, $.trim($("a.facet-choice-label")[0].text)); +}; + +// ----------------------- register tests --------------------------- + +windmill.jsTest.register([ + "test_facets" +]); + +windmill.jsTest.require("facets.js"); diff --git a/tests/windmill/js/test_basic_functions.js b/tests/windmill/js/test_basic_functions.js deleted file mode 100644 index 684576114..000000000 --- a/tests/windmill/js/test_basic_functions.js +++ /dev/null @@ -1,57 +0,0 @@ -var wm = windmill.jsTest; -var asserts = windmill.controller.asserts; - -asserts.gw = {}; -asserts.gw.row_count = function (count) { - asserts.assertText( { jquery: '(".viewPanel-summary-row-count")[0]', validator: count } ); -}; -asserts.gw.expected_top_value = function(expected_value) { - var actual_value = $.trim($("a.facet-choice-label")[0].text); - jum.assertEquals( expected_value, actual_value ); -} - - -/* haven't gotten this working yet.... -waits.gw = {}; -waits.gw.ajax = function () { - { method: "waits.forElement", params: { jquery: '("body[ajax_in_progress=\'false\']")[0]'} }; -}; */ - -wm.actions.gw = {}; -wm.actions.gw.click_column_header = function (column_name) { - wm.actions.click( { jquery: '(".column-header-layout tr:contains("' + column_name + '") .column-header-menu")[0]'} ); -}; -var gwActions = wm.actions.gw; - - - -var test_basic_functions = new function () { - - // open Food project - this.test_open_project = function () { wm.actions.click( { link: "Food" } ); }; - this.test_wait = { method: "waits.forPageLoad", params: { timeout: "20000" }}; - this.test_got_to_main_page = function () { asserts.gw.row_count("7413"); }; - -// create text facet from 1st word of Short Description -// this.test_facet_short_desc = function () { wm.actions.gw.click_column_header('Shrt_Desc'); }; // currently broken - this.test_filter_column = function () { - wm.actions.click( { jquery: '(".column-header-layout tr:contains(\'Shrt_Desc\') .column-header-menu")[0]'} ); //replace w/ above when able - wm.actions.mouseOver( { jquery: '("td:contains(\'Facet\')")[0]' } ); - }; - this.test_wait_for_menu = { method: "waits.forElement", params: {jquery: '(".menu-item:contains(\'Custom Text Facet\')")[0]'} }; - this.test_create_facet = function () { - wm.actions.click( { jquery: '(".menu-item:contains(\'Custom Text Facet\')")[0]'} ); - wm.actions.type( { jquery: '(".expression-preview-code")[0]', text: "value.split(',')[0]"} ); - }; - this.test_wait_for_value = {method: "waits.forElement", params: { jquery: '("td:contains(\'value.split\')")[0]'} }; - this.test_click_button = function () { wm.actions.click( { jquery: '("button:contains(\'OK\')")[0]'} ); }; - this.test_wait_for_link = {method: "waits.forElement", params: { jquery: '(".ui-button-text:contains(\'count\')")[0]'} }; - this.test_facet_worked= function () { asserts.gw.expected_top_value("ABALONE"); }; - this.test_sort_by_count = function () { wm.actions.click( { jquery: '(".ui-button-text:contains(\'count\')")[0]'} ); }; - this.test_wait_for_count = {method: "waits.forElement", params: { jquery: '(".ui-state-active .ui-button-text:contains(\'count\')")[0]'} }; - this.test_sort_worked= function () { asserts.gw.expected_top_value("BEEF"); }; - -}(); - - -