This repository has been archived by the owner on Nov 17, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
150 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
<html> | ||
<head> | ||
<title>mini.ajax.js test</title> | ||
<script type="text/javascript" src="/js/ajax.js"></script> | ||
<style type="text/css"> | ||
code { | ||
background-color: #eee; | ||
} | ||
</style> | ||
</head> | ||
<body> | ||
<h1>mini.ajax.js test</h1> | ||
<p>This HTML page serves to test the mini.ajax.js library in its basic functionality.</p> | ||
|
||
<h2>collect()</h2> | ||
<p> | ||
<a href="#" onclick="$('collect_results').innerHTML=collect(['a','b','c','notme'],function(i){if(i!='notme')return i+' changed'});return false;">test collect()</a> | ||
</p> | ||
<div id="collect_results">a,b,c,notme</div> | ||
|
||
<h2>mini.ajax.serialize()</h2> | ||
<p>Submit this form to test the <code>mini.ajax.serialize()</code> function.</p> | ||
<form onsubmit="$('serialize_results').innerHTML=mini.form.serialize(this);return false;"> | ||
<input type="hidden" name="hideme" value="i am hidden"/> | ||
<input name="text_input" value="some text"/> | ||
<input type="checkbox" name="checkbox_input1" value="yes"/> | ||
<input type="checkbox" name="checkbox_input2" value="yes" checked="checked"/> | ||
<input type="radio" name="radio_input" value="value 1"/> | ||
<input type="radio" name="radio_input" value="value 2" checked="checked"/> | ||
<input type="radio" name="radio_input" value="value 2"/> | ||
<select name="select_input"> | ||
<option value="value 1">value 1</option> | ||
<option value="value 2">value 2</option> | ||
<option value="value 3">value 3</option> | ||
</select> | ||
<textarea name="textarea_input">here is some text | ||
with | ||
|
||
a line break or two</textarea> | ||
<input type="submit" value="test serialize"/> | ||
</form> | ||
<div id="serialize_results"></div> | ||
|
||
<h2>mini.ajax.get()</h2> | ||
<p><a href="#" onclick="mini.ajax.get('/echo?foo=bar', function(r){$('get_results').innerHTML=r});return false;">test mini.ajax.get()</a></p> | ||
<div id="get_results"></div> | ||
|
||
<h2>mini.ajax.post()</h2> | ||
<p><a href="#" onclick="mini.ajax.post('/echo', function(r){$('post_results').innerHTML=r}, 'bar=baz');return false;">test mini.ajax.post()</a></p> | ||
<div id="post_results"></div> | ||
|
||
<h2>mini.ajax.update()</h2> | ||
<p><a href="#" onclick="mini.ajax.update('/echo', 'update_results', 'POST', 'baz=foo');return false;">test mini.ajax.update()</a></p> | ||
<div id="update_results"></div> | ||
|
||
<h2>mini.ajax.submit()</h2> | ||
<form onsubmit="mini.ajax.submit('/echo', this, 'submit_results');return false;"> | ||
<input name="foo" value="bar"/> | ||
<input type="submit" value="test submit"/> | ||
</form> | ||
<div id="submit_results"></div> | ||
</body> | ||
</html> | ||
|
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
require 'rubygems' | ||
require 'sinatra' | ||
|
||
get '/' do | ||
"test_server.rb is running" | ||
end | ||
|
||
get '/echo' do | ||
"you sent a GET with args #{params.inspect}" | ||
end | ||
|
||
post '/echo' do | ||
"you sent a POST with args #{params.inspect}" | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
require 'rubygems' | ||
require 'firewatir' | ||
require 'test/unit' | ||
require 'cgi' | ||
require 'open-uri' | ||
|
||
open('http://localhost:4567/') rescue raise('test_server.rb must be running for this set of tests') | ||
|
||
TEST_DIR = File.expand_path(File.dirname(__FILE__) + '/..') | ||
FF = FireWatir::Firefox.start("http://localhost:4567/html/ajax_test.html") | ||
|
||
class AjaxTest < Test::Unit::TestCase | ||
|
||
def setup | ||
@ff = FF | ||
end | ||
|
||
def test_collect | ||
@ff.link(:text, 'test collect()').click | ||
assert_equal 'a changed,b changed,c changed', @ff.div(:id, 'collect_results').text | ||
end | ||
|
||
def test_serialize | ||
@ff.button(:value, 'test serialize').click | ||
results = @ff.div(:id, 'serialize_results').text | ||
unescaped = CGI.unescape(results) | ||
assert_match /hideme=i am hidden/, unescaped | ||
assert_match /text_input=some text/, unescaped | ||
assert_no_match /checkbox_input1=yes/, unescaped | ||
assert_match /checkbox_input2=yes/, unescaped | ||
assert_match /radio_input=value 2/, unescaped | ||
assert_no_match /radio_input=value 1/, unescaped | ||
assert_match /select_input=value 1/, unescaped | ||
assert_no_match /select_input=value 2/, unescaped | ||
assert_match /textarea_input=here is some text\s*with\s*a line break or two/, unescaped | ||
end | ||
|
||
def test_get | ||
@ff.link(:text, 'test mini.ajax.get()').click | ||
assert_equal 'you sent a GET with args {"foo"=>"bar"}', @ff.div(:id, 'get_results').text | ||
end | ||
|
||
def test_post | ||
@ff.link(:text, 'test mini.ajax.post()').click | ||
assert_equal 'you sent a POST with args {"bar"=>"baz"}', @ff.div(:id, 'post_results').text | ||
end | ||
|
||
def test_update | ||
@ff.link(:text, 'test mini.ajax.update()').click | ||
assert_equal 'you sent a POST with args {"baz"=>"foo"}', @ff.div(:id, 'update_results').text | ||
end | ||
|
||
def test_submit | ||
@ff.button(:value, 'test submit').click | ||
assert_equal 'you sent a POST with args {"foo"=>"bar"}', @ff.div(:id, 'submit_results').text | ||
end | ||
end |