Skip to content

Commit

Permalink
Eliminated all of the children
Browse files Browse the repository at this point in the history
  • Loading branch information
Stuk committed Dec 6, 2010
1 parent 1012570 commit 933278d
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 85 deletions.
36 changes: 10 additions & 26 deletions collection_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -122,22 +122,9 @@

# sugar
describe 'syntactic sugar' do
it 'returns all decendants with the given tag' do
content = window.find_by_id('content').first.children
collection = content.span
collection.all? do |element|
child = false

# check that this element is somewhere under div#content
until element.parent.nil? do
element = element.parent
if element.attr(:id) == 'content'
return true
end
end

return false
end.should be_true
it 'returns all descendants with the given tag' do
content = window.find_by_id('promo').span
content.length.should == 5
end

it 'can be chained' do
Expand Down Expand Up @@ -271,30 +258,27 @@
end

it 'returns false if any collection elements are disabled' do
fieldset = window.find_by_id('new_user').first.children.first
fieldset.children.enabled?.should be_false
window.find_by_id('new_user').input.enabled?.should be_false
end
end

# enable!
describe '#enable!' do
it 'enables all elements in the collection' do
browser.goto(fixture('forms_with_input_elements.html'))
fieldset = window.find_by_id('delete_user').first.children.first
fieldset.children.enable!
window.find_by_id('new_user_species').enabled?.should be_true
window.find_by_id('new_user').input.enable!
window.find_by_id('new_user_species').first.enabled?.should be_true
end
end

# disable!
describe '#disable' do
it 'disables all elements in the collection' do
browser.goto(fixture('forms_with_input_elements.html'))
fieldset = window.find_by_id('delete_user').first.children.first
fieldset.children.disable!
fieldset.children.all? do |element|
element.enabled? == false
end.should be_true
window.find_by_id('new_user').input.disable!
window.find_by_id('new_user_species').input.any? do |element|
element.enabled?
end.should be_false
end
end

Expand Down
92 changes: 33 additions & 59 deletions element_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@
before :each do
browser.url = fixture('non_control_elements.html')

@element = window.id('descartes').first
@list = window.id('navbar').first
@leaf = window.id('link_2').first
@element = window.find_by_id('descartes').first
@list = window.find_by_id('navbar').first
@leaf = window.find_by_id('link_2').first
end

# parent
Expand All @@ -23,32 +23,6 @@
end
end

# children
describe '#children' do
it 'is not empty when there are child elements' do
@list.children.should_not be_empty
end

it 'contains the child elements of an element' do
@list.children.all? do |child|
child.parent.attr(:id) == 'navbar'
end.should be_true
end

it 'is empty when the element has no children' do
@leaf.children.should be_empty
end

it 'is a collection' do
@list.children.tag(:li).all? do |element|
element.parent == @list
end.should be_true
# Some example calls
@list.should.respond_to? :id
@list.should.respond_to? :tag
end
end

# attr(what, value=nil)
describe '#attr' do
it 'gets the value of the given attribute' do
Expand Down Expand Up @@ -107,19 +81,19 @@
end

it 'is an empty string when there is no text' do
window.tag(:body).first.children.first.text.should == ''
window.find_by_tag(:body).div.first.text.should == ''
end
end

describe '#text=' do
it 'sets the text content of the element' do
@element.children.first.text = 'test'
@element.em.first.text = 'test'
@element.text.should == 'Dubito, test, ergo sum.'
end

it 'overwrites child elements' do
@element.text = 'test'
@element.children.should be_empty
@element.em.should be_empty
end
end

Expand All @@ -130,20 +104,20 @@
end

it 'is an empty string if the element contains no text or html' do
window.tag(:body).first.children.first.html.should == ''
window.tag(:body).div.first.html.should == ''
end
end

describe '#html=' do
it 'sets the outer HTML of the element' do
@element.children.first.html = '<b>test</b>'
@element.em.first.html = '<b>test</b>'
@element.html.should == "<strong id='descartes' class='descartes'>Dubito, <b>test</b>, ergo sum.</strong>"
end

it 'creates child elements' do
@element.children.first.html = "<b>one</b> <b class='test'>two</b>"
@element.children.length.should == 2
@element.children[1].attr(:class).should == 'test'
@element.em.first.html = "<b>one</b> <b class='test'>two</b>"
@element.em.length.should == 2
@element.em[1].attr(:class).should == 'test'
end
end

Expand All @@ -163,11 +137,11 @@
before :each do
browser.url = fixture('forms_with_input_elements.html')

@textbox = window.id('new_user_username').first
@checkbox_checked = window.id('new_user_interests_books').first
@checkbox_unchecked = window.id('bowling').first
@radio_checked = window.id('new_user_newsletter_yes').first
@radio_unchecked = window.id('new_user_newsletter_no').first
@textbox = window.find_by_id('new_user_username').first
@checkbox_checked = window.find_by_id('new_user_interests_books').first
@checkbox_unchecked = window.find_by_id('bowling').first
@radio_checked = window.find_by_id('new_user_newsletter_yes').first
@radio_unchecked = window.find_by_id('new_user_newsletter_no').first
end

# TODO 'checked' is available for all <input> and <command>. Change this
Expand Down Expand Up @@ -231,19 +205,19 @@
end

it 'is false for an element with style attribute “display:none”' do
window.id('parent').first.visible?.should be_false
window.find_by_id('parent').first.visible?.should be_false
end

it 'is false a child of an element with style attribute “display:none”' do
window.id('child').first.visible?.should be_false
window.find_by_id('child').first.visible?.should be_false
end

it 'is false for an element hidden by CSS' do
window.id('hidden_by_css').first.visible?.should be_false
window.find_by_id('hidden_by_css').first.visible?.should be_false
end

it 'is true for an element with visibility:hidden' do
window.id('invisible').first.visible?.should be_true
window.find_by_id('invisible').first.visible?.should be_true
end

end
Expand All @@ -258,27 +232,27 @@
end

it 'focuses the element' do
input = window.id('new_user_email').first
input = window.find_by_id('new_user_email').first
input.focus!
window.type('test')
input.attr(:value).should == 'test'
end

it 'returns false if the element is disabled' do
input = window.id('new_user_species').first
input = window.find_by_id('new_user_species').first
input.focus!.should be_false
end
end

# click!([x, y]) , x,y relative to element top left
describe '#click!' do
it 'follows links' do
window.id('link_3').first.click!
window.find_by_id('link_3').first.click!
window.url.should match /forms_with_input_elements\.html$/
end

it 'triggers onclick handlers' do
div = window.id('best_language').first
div = window.find_by_id('best_language').first
div.click!
div.html.should == 'Ruby!'
end
Expand All @@ -288,8 +262,8 @@
describe '#check!' do
before :each do
browser.url = fixture('forms_with_input_elements.html')
@checkbox_unchecked = window.id('bowling').first
@radio_unchecked = window.id('new_user_newsletter_no').first
@checkbox_unchecked = window.find_by_id('bowling').first
@radio_unchecked = window.find_by_id('new_user_newsletter_no').first
end

it 'checks a checkbox' do
Expand All @@ -306,8 +280,8 @@
describe '#uncheck!' do
before :each do
browser.url = fixture('forms_with_input_elements.html')
@checkbox_checked = window.id('new_user_interests_books').first
@radio_checked = window.id('new_user_newsletter_yes').first
@checkbox_checked = window.find_by_id('new_user_interests_books').first
@radio_checked = window.find_by_id('new_user_newsletter_yes').first
end

it 'unchecks a checkbox' do
Expand All @@ -325,8 +299,8 @@
describe '#toggle_check!' do
before :each do
browser.url = fixture('forms_with_input_elements.html')
@checkbox_checked = window.id('new_user_interests_books').first
@radio_checked = window.id('new_user_newsletter_yes').first
@checkbox_checked = window.find_by_id('new_user_interests_books').first
@radio_checked = window.find_by_id('new_user_newsletter_yes').first
end

it 'toggles a checkbox' do
Expand All @@ -345,7 +319,7 @@
describe '#enable!' do
it 'enables a form element' do
window.url = fixture('forms_with_input_elements.html')
disabled = window.id('new_user_species')
disabled = window.find_by_id('new_user_species')
disabled.enabled?.should be_false
disabled.enable!
disabled.enabled?.should be_true
Expand All @@ -355,7 +329,7 @@
describe '#enable!' do
it 'enables a form element' do
window.url = fixture('forms_with_input_elements.html')
disabled = window.id('new_user_email')
disabled = window.find_by_id('new_user_email')
disabled.enabled?.should be_true
disabled.disable!
disabled.enabled?.should be_false
Expand All @@ -365,7 +339,7 @@
# show!
describe '#show!' do
it 'makes the element visible' do
hidden = window.id('hidden').first
hidden = window.find_by_id('hidden').first
hidden.visible?.should be_false
hidden.show!
hidden.visible?.should be_true
Expand Down

0 comments on commit 933278d

Please sign in to comment.