Created
February 9, 2009 22:12
-
-
Save oddlyzen/61058 to your computer and use it in GitHub Desktop.
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
#!/usr/bin/env ruby | |
# :title:Category Filter Tests | |
# = Name | |
# Test the categories (left-nav checkboxes) filter | |
# = Description | |
# Show that the filter is working as intended. | |
require "selenium_helper" | |
class CategoryFilterTest < Test::Unit::TestCase | |
include SeleniumHelper | |
#1. Checking the All checkbox selects all the category checkboxes. | |
def test_select_all | |
get_research | |
check_all | |
assert all_checked? | |
checkbox_array.each do |e| | |
assert browser.checked?("#{e}") | |
end | |
end | |
#1a. Un-checking any category checkbox, de-selects the All checkbox. | |
def test_select_all_then_uncheck_one | |
get_research | |
check_all | |
assert all_checked? | |
browser.click(checkbox_array[1]) | |
assert !all_checked? | |
end | |
#2. Un-checking the All checkbox de-selects all the category checkboxes. | |
def test_check_all_then_uncheck_all | |
get_research | |
check_all | |
checkbox_array.each do |e| | |
assert browser.checked?("#{e}") | |
end | |
check_all | |
checkbox_array.each do |e| | |
assert !browser.checked?("#{e}") | |
end | |
end | |
#3. Clicking the 'Filter' button | |
# A. Results in an Ajax replacement of the current content, with content only from categories corresponding to whatever checkboxes are selected. | |
# B. Notifies the user that content is being loaded. Notification should remain visible until content has fully loaded. | |
# def test_clicking_the_filter_button | |
# get_research :popular | |
# browser.click(checkbox_array[1]) | |
# browser.click('filterButton') | |
# assert browser.js_eval("#{$window}$('filterSpinner').style.display === 'block')") | |
# js = "" << "(#{$window}$('filterSpinner').style.display === '')) && (#{$window}$('leftTabTable').style.display = '') == true;" | |
# wait_for_condition(js) | |
# assert browser.js_eval("#{$window}$('filterSpinner').style.display === '')") | |
# end | |
# Ancillary tests; make sure the leftnav is here. | |
def test_categories_display_on_research | |
get_research | |
has_category_filter? | |
get_research :popular | |
has_category_filter? | |
get_research :recent | |
has_category_filter? | |
end | |
# Ancillary tests; make sure the leftnav is here. | |
def test_categories_display_on_library | |
get_library | |
has_category_filter? | |
get_library :popular | |
has_category_filter? | |
get_library :alpha | |
has_category_filter? | |
end | |
# EXPERIMENTAL TESTS | |
# def test_number_of_categories | |
# get_research :recent | |
# no_cats = Category.count | |
# no_page = checkbox_array.length | |
# assert_equal no_cats, no_page | |
# end | |
protected | |
def has_category_filter? | |
assert_equal("Filter by:", browser.js_eval("#{$window}$$('form h2')[0].innerHTML")) | |
assert_equal("Categories", browser.js_eval("#{$window}$$('form h3')[0].innerHTML")) | |
end | |
def get_research(sym=nil) | |
browser.open "/research#{ sym.nil? ? '' : '/' + sym.to_s }" | |
end | |
def get_library(sym=nil) | |
browser.open "/library#{ sym.nil? ? '' : '/' + sym.to_s }" | |
end | |
def check_all | |
browser.click("checkAll") | |
end | |
def all_checked? | |
browser.checked?("checkAll") | |
end | |
def checkbox_array | |
ids_from_css("div\#tertiary.span-5 form input") | |
end | |
# == Given a CSS expression, return an array of the IDs of each of the elements matched by that expression. | |
def ids_from_css(css3_expression) | |
#ary = browser.js_eval("var checkboxes = #{$window}$$('div#tertiary.span-5 form input'); var ids = []; checkboxes.each(function(el){ids.push(el.id)}); ids.toString();").split(',') | |
ary = browser.js_eval("#{$window}ZEP.util.ids.fromCSS('#{css3_expression}').toString()").split(',') | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment