require "spec_helper" describe Element do html <<-HTML
Erm
erm
" end it "should only return html for first matched element" do Element.find('.html-bridge').html.should == "Hello" end it "should return empty string for empty set" do Element.find('.html-nothing-here').html.should == "" end end describe '#remove_class' do it "should have no effect on elements without class" do foo = Element.find '#remove-foo' foo.class_name.should == '' foo.remove_class 'blah' foo.class_name.should == '' end it "should remove the given class from the element" do bar = Element.find '#remove-bar' bar.remove_class "lemons" bar.class_name.should == '' baz = Element.find '#remove-baz' baz.remove_class 'lemons' baz.class_name.should == 'apples oranges' baz.remove_class 'apples' baz.class_name.should == 'oranges' buz = Element.find '#remove-buz' buz.remove_class 'mangos' buz.class_name.should == 'pineapples' buz.remove_class 'pineapples' buz.class_name.should == '' end it "should return self" do bleh = Element.find '#remove-bleh' bleh.remove_class('fruit').should equal(bleh) bleh.remove_class('hmmmm').should equal(bleh) end end describe '#toggle_class' do it 'adds the given class name to the element if not already present' do foo = Element.find('#foo') foo.has_class?('oranges').should eq(false) foo.toggle_class 'oranges' foo.has_class?('oranges').should eq(true) end it 'removes the class if the element already has it' do bar = Element.find('#bar') bar.has_class?('apples').should eq(true) bar.toggle_class 'apples' bar.has_class?('apples').should eq(false) end end describe "#value" do it "should return the selected value of select elements" do Element.find('#value-foo').value.should == "Hello" end it "should return the value of normal input fields" do Element.find('#value-bar').value.should == "Blah" end it "should return an empty string for elements with no value attr" do Element.find('#value-baz').value.should == "" end end describe "#value=" do it "should set the value of the element to the given value" do foo = Element.find '#value-woosh' foo.value.should == "" foo.value = "Hi" foo.value.should == "Hi" foo.value = "There" foo.value.should == "There" end end end