spec/druid/page_populator_spec.rb in druid-ts-1.2.4 vs spec/druid/page_populator_spec.rb in druid-ts-1.2.5
- old
+ new
@@ -1,17 +1,24 @@
require 'spec_helper'
+class Section
+ include Druid
+
+ text_field(:stf, id: 'id')
+end
+
class DruidPagePopulator
include Druid
text_field(:tf, :id => 'id')
text_area(:ta, :id => 'id')
select_list(:sl, :id => 'id')
checkbox(:cb, :id => 'id')
radio_button(:rb, :id => 'id')
file_field(:ff, :id => 'id')
radio_button_group(:rbg, :id => 'id')
+ page_section(:section, Section, id: 'foo')
end
describe Druid::PagePopulator do
let(:driver) { mock_driver }
let(:druid) { DruidPagePopulator.new(driver) }
@@ -42,14 +49,11 @@
expect(driver).to receive(:tag_name).and_return('textarea')
druid.populate_page_with('ta' => 'value')
end
it "should set a value in a select list" do
- list = double('sl')
- expect(druid).to receive(:sl_element).and_return(list)
- expect(list).to receive(:options).and_return(['value'])
- expect(list).to receive(:select).with('value')
+ expect(druid).to receive(:sl=).with('value')
druid.populate_page_with('sl' => 'value')
end
it "should set a value in a file field" do
expect(druid).to receive(:ff=).with('value')
@@ -120,6 +124,32 @@
expect(driver).to receive(:visible?).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
+ let(:section) { double('section') }
+
+ before do
+ allow(druid).to receive(:section).and_return section
+ end
+
+ 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 "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'})
+ end
+
+ it "should not populate a text field when it is disabled" do
+ expect(section).not_to receive(:stf=)
+ expect(section).to receive(:stf_element).twice.and_return(driver)
+ expect(driver).to receive(:enabled?).and_return(false)
+ expect(driver).to receive(:tag_name).and_return('input')
+ druid.populate_page_with('section' => {'stf' => true})
+ end
+ end
end