From acaab690efaef2583fa8ad0079e89acadc90c3d5 Mon Sep 17 00:00:00 2001 From: Martin Edenhofer Date: Tue, 28 May 2013 14:24:48 +0200 Subject: [PATCH] Added browser tests for text module. Fixed jquery 1.9 compatibility. --- .../app/lib/base/jquery.caretposition.js | 18 ++ lib/auth/test.rb | 4 +- test/browser/text_module_test.rb | 171 ++++++++++++++++++ test/browser_test_helper.rb | 2 +- 4 files changed, 192 insertions(+), 3 deletions(-) create mode 100644 test/browser/text_module_test.rb diff --git a/app/assets/javascripts/app/lib/base/jquery.caretposition.js b/app/assets/javascripts/app/lib/base/jquery.caretposition.js index 7467500db..7be8c68d1 100644 --- a/app/assets/javascripts/app/lib/base/jquery.caretposition.js +++ b/app/assets/javascripts/app/lib/base/jquery.caretposition.js @@ -4,6 +4,24 @@ * @license under GNU license * @author Bevis Zhao (i@bevis.me, http://bevis.me) */ + +// workaround to work with jquery 1.9 +// http://api.jquery.com/jQuery.browser/ +(function(){ + if (!jQuery.browser) { + jQuery.browser={}; + jQuery.browser.msie = false; + jQuery.browser.version = 0; + if( navigator.userAgent.match(/MSIE ([0-9]+)\./) ){ + jQuery.browser.msie = true; + jQuery.browser.version = RegExp.$1; + } + else if ( !navigator.userAgent.match(/mozilla/i) && !navigator.userAgent.match(/webkit/i) ){ + jQuery.browser.mozilla = true; + } + } +})(); + $(function() { var calculator = { diff --git a/lib/auth/test.rb b/lib/auth/test.rb index 66b679b65..0930ce2d3 100644 --- a/lib/auth/test.rb +++ b/lib/auth/test.rb @@ -7,7 +7,7 @@ module Auth::TEST if !ENV['RAILS_ENV'] || ENV['RAILS_ENV'] == 'development' return user if password == 'test' end - + return false end -end \ No newline at end of file +end diff --git a/test/browser/text_module_test.rb b/test/browser/text_module_test.rb new file mode 100644 index 000000000..a3945c2fc --- /dev/null +++ b/test/browser/text_module_test.rb @@ -0,0 +1,171 @@ +# encoding: utf-8 +require 'browser_test_helper' + +class TextModuleTest < TestCase + def test_user + random = 'text_module_test_' + rand(999999).to_s + random2 = 'text_module_test_' + rand(999999).to_s + user_email = random + '@example.com' + + # user + tests = [ + { + :name => 'add #1', + :action => [ + { + :execute => 'click', + :css => 'a[href="#admin"]', + }, + { + :execute => 'click', + :css => 'a[href="#text_modules"]', + }, + { + :execute => 'wait', + :value => 1, + }, + { + :execute => 'click', + :css => 'a[data-type="new"]', + }, + { + :execute => 'wait', + :value => 2, + }, + { + :execute => 'set', + :css => 'input[name=name]', + :value => 'some name' + random, + }, + { + :execute => 'set', + :css => 'input[name="keywords"]', + :value => random, + }, + { + :execute => 'set', + :css => 'textarea[name="content"]', + :value => 'some content' + random, + }, + { + :execute => 'click', + :css => 'button.submit', + }, + { + :execute => 'wait', + :value => 3, + }, + { + :execute => 'match', + :css => 'body', + :value => random, + :match_result => true, + }, + ], + }, + { + :name => 'add #2', + :action => [ + { + :execute => 'click', + :css => 'a[href="#admin"]', + }, + { + :execute => 'click', + :css => 'a[href="#text_modules"]', + }, + { + :execute => 'wait', + :value => 1, + }, + { + :execute => 'click', + :css => 'a[data-type="new"]', + }, + { + :execute => 'wait', + :value => 1, + }, + { + :execute => 'set', + :css => 'input[name=name]', + :value => 'some name' + random2, + }, + { + :execute => 'set', + :css => 'input[name="keywords"]', + :value => random2, + }, + { + :execute => 'set', + :css => 'textarea[name="content"]', + :value => 'some content' + random2, + }, + { + :execute => 'click', + :css => 'button.submit', + }, + { + :execute => 'wait', + :value => 3, + }, + { + :execute => 'match', + :css => 'body', + :value => random2, + :match_result => true, + }, + ], + }, + { + :name => 'verify usage', + :action => [ + { + :execute => 'click', + :css => 'a[href="#new"]', + }, + { + :execute => 'click', + :css => 'a[href="#ticket_create/call_outbound"]', + }, + { + :execute => 'wait', + :value => 2, + }, + { + :execute => 'set', + :css => 'textarea[name=body]', + :value => '::' + random, + }, + { + :execute => 'wait', + :value => 1, + }, + { + :execute => 'match', + :css => 'body', + :value => random, + :match_result => true, + }, + { + :execute => 'sendkey', + :css => 'textarea[name=body]', + :value => :enter, + }, + { + :execute => 'wait', + :value => 1, + }, + { + :execute => 'match', + :css => 'textarea[name=body]', + :value => random, + :match_result => true, + }, + ], + + }, + ] + browser_signle_test_with_login(tests, { :username => 'master@example.com' }) + end +end diff --git a/test/browser_test_helper.rb b/test/browser_test_helper.rb index 6d6b3a493..5464820b9 100644 --- a/test/browser_test_helper.rb +++ b/test/browser_test_helper.rb @@ -227,7 +227,7 @@ class TestCase < Test::Unit::TestCase end end else - if action[:css] =~ /input/i + if action[:css] =~ /(input|textarea)/i text = element.attribute('value') else text = element.text