spec/druid/page_populator_spec.rb in druid-ts-1.2.5 vs spec/druid/page_populator_spec.rb in druid-ts-1.2.6
- old
+ new
@@ -21,10 +21,19 @@
describe Druid::PagePopulator do
let(:driver) { mock_driver }
let(:druid) { DruidPagePopulator.new(driver) }
+ it "should accept any object that can be converted to a Hash" do
+ os = OpenStruct.new('tf' => 'value', 'sl' => 'value')
+ expect(druid).to receive(:tf=).with('value')
+ expect(druid).to receive(:sl=).with('value')
+
+ allow(druid).to receive(:is_enabled?).and_return(true)
+ druid.populate_page_with(os)
+ end
+
it "should set a value in a text field" do
expect(druid).to receive(:tf=).with('value')
expect(druid).to receive(:is_enabled?).and_return(true)
druid.populate_page_with('tf' => 'value')
end
@@ -36,11 +45,11 @@
it "should not populate a text field when it is not visible" do
expect(druid).not_to receive(:tf=)
expect(druid).to receive(:tf_element).twice.and_return(driver)
expect(driver).to receive(:enabled?).and_return(true)
- expect(driver).to receive(:visible?).and_return(false)
+ expect(driver).to receive(:present?).and_return(false)
expect(driver).to receive(:tag_name).and_return('input')
druid.populate_page_with('tf' => true)
end
it "should set a value in a text area" do
@@ -94,11 +103,11 @@
it "should not populate a checkbox if it is not visible" do
expect(druid).not_to receive(:check_cb)
expect(druid).to receive(:cb_element).twice.and_return(driver)
expect(driver).to receive(:enabled?).and_return(true)
- expect(driver).to receive(:visible?).and_return(false)
+ expect(driver).to receive(:present?).and_return(false)
expect(driver).to receive(:tag_name).and_return('input')
druid.populate_page_with('cb' => true)
end
it "should not populate a radio button when it is disabled" do
@@ -119,11 +128,11 @@
it "should not populate a radio button when it is not visible" do
expect(druid).not_to receive(:select_rb)
expect(druid).to receive(:rb_element).twice.and_return(driver)
expect(driver).to receive(:enabled?).and_return(true)
- expect(driver).to receive(:visible?).and_return(false)
+ expect(driver).to receive(:present?).and_return(false)
expect(driver).to receive(:tag_name).and_return('input')
druid.populate_page_with('rb' => true)
end
context "when using a nested for a section" do
@@ -135,9 +144,18 @@
it "should populate a page section when the value is a hash and it exists" do
expect(section).to receive(:stf=).with('value')
expect(druid).to receive(:is_enabled?).and_return(true)
druid.populate_page_with('section' => {'stf' => 'value'})
+ end
+
+ it "populate a page section when the value repsonds to #to_h and it exists" do
+ os = OpenStruct.new('tf' => 'value', 'sl' => 'value')
+ expect(section).to receive(:tf=).with('value')
+ expect(section).to receive(:sl=).with('value')
+
+ allow(druid).to receive(:is_enabled?).twice.and_return(true)
+ druid.populate_page_with('section' => os)
end
it "should not set a value in a text field if it is not found on the page" do
expect(section).not_to receive(:text_field)
druid.populate_page_with('section' => {'coffee' => 'value'})