Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
92 changes: 49 additions & 43 deletions lib/ae_page_objects/core/dsl/collection.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,74 +11,82 @@ module ClassMethods
# collection. collection() defines a method on the class that returns an instance of a collection
# class which contains instances of the collection's item class.
#
# Supported signatures are described below.
#
# ------------------------------------------------
# Signature: (:is, no :contains, no block)
#
# collection :addresses, :is => AddressList
#
# Collection class: AddressList
# Item class: AddressList.item_class
#
# ------------------------------------------------
# Signature: (no :is, :contains, no block)
#
# collection :addresses, :contains => Address
#
# Collection class: one-off subclass of ::AePageObjects::Collection
# Item class: Address
#
# Supported signatures are described below.
#
# ------------------------------------------------
# Signature: (:is, :contains, no block)
#
# collection :addresses, :is => AddressList, :contains => ExtendedAddress
#
# Collection class: one-off subclass ofAddressList
# Item class: ExtendedAddress
#
# Signature: (no :is, no :contains, no block)
#
# collection :addresses
#
# Collection class: ::AePageObjects::Collection
# Item class: ::AePageObjects::Element
#
# ------------------------------------------------
# Signature: (no :is, no :contains, block)
#
#
# collection :addresses do
# element :city
# element :state
# end
#
#
# Collection class: one-off subclass of ::AePageObjects::Collection
# Item class: one-off subclass of ::AePageObjects::Element
# Methods defined on item class:
# city() # -> instance of ::AePageObjects::Element
# state() # -> instance of ::AePageObjects::Element
#
#
# ------------------------------------------------
# Signature: (:is, no :contains, block)
#
# collection :addresses, :is => AddressList do
# Signature: (no :is, :contains, no block)
#
# collection :addresses, :contains => Address
#
# Collection class: one-off subclass of ::AePageObjects::Collection
# Item class: Address
#
# ------------------------------------------------
# Signature: (no :is, :contains, block)
#
# collection :addresses, :contains => Address do
# element :longitude
# element :latitude
# end
#
# Collection class: one-off subclass of AddressList
# Item class: one-off subclass of AddressList.item_class
#
# Collection class: one-off subclass of ::AePageObjects::Collection element
# Item class: one-off subclass of Address
# Methods defined on item class:
# longitude() # -> instance of ::AePageObjects::Element
# latitude() # -> instance of ::AePageObjects::Element
#
#
# ------------------------------------------------
# Signature: (no :is, :contains, block)
#
# collection :addresses, :contains => Address do
# Signature: (:is, no :contains, no block)
#
# collection :addresses, :is => AddressList
#
# Collection class: AddressList
# Item class: AddressList.item_class
#
# ------------------------------------------------
# Signature: (:is, no :contains, block)
#
# collection :addresses, :is => AddressList do
# element :longitude
# element :latitude
# end
#
# Collection class: one-off subclass of ::AePageObjects::Collection element
# Item class: one-off subclass of Address
#
# Collection class: one-off subclass of AddressList
# Item class: one-off subclass of AddressList.item_class
# Methods defined on item class:
# longitude() # -> instance of ::AePageObjects::Element
# latitude() # -> instance of ::AePageObjects::Element
#
# ------------------------------------------------
# Signature: (:is, :contains, no block)
#
# collection :addresses, :is => AddressList, :contains => ExtendedAddress
#
# Collection class: one-off subclass ofAddressList
# Item class: ExtendedAddress
#
# ------------------------------------------------
# Signature: (:is, :contains, block)
#
Expand Down Expand Up @@ -111,8 +119,6 @@ def collection(name, options = {}, &block)
ensure_class_for_param!(:is, options[:is], ::AePageObjects::Collection)
else
options[:is] = ::AePageObjects::Collection

raise ArgumentError, "Must specify either a block or a :contains option." if options[:contains].blank? && block.blank?
end

item_class = options.delete(:contains) || options[:is].item_class
Expand Down
4 changes: 2 additions & 2 deletions test/test_helpers/node_field_test_helpers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ def verify_field_with_intermediary_class(parent, field_method, expected_field_ty
end

def verify_item_field(collection, index, expected_item_type, expected_item_page)
collection.send(:[], index).tap do |item|
collection[index].tap do |item|
assert_false item.is_a?(AePageObjects::ElementProxy)
assert_equal expected_item_type, item.class
assert_equal collection.item_class, item.class
Expand All @@ -45,7 +45,7 @@ def verify_item_field(collection, index, expected_item_type, expected_item_page)
end

def verify_item_field_with_intermediary_class(collection, index, expected_item_type, expected_item_page)
collection.send(:[], index).tap do |item|
collection[index].tap do |item|
assert_false item.is_a?(AePageObjects::ElementProxy)
assert_equal expected_item_type, item.class.superclass
assert_equal collection.item_class, item.class
Expand Down
20 changes: 15 additions & 5 deletions test/unit/dsl/collection_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -298,12 +298,22 @@ def test_collection__is__contains__block
end

def test_collection__no_is__no_contains__no_block
assert_raises ArgumentError do
kitty = ::AePageObjects::Document.new_subclass do
collection :previous_owners
raise "You will never see this"
end
kitty = ::AePageObjects::Document.new_subclass do
collection :previous_owners
end

document_stub = mock
jon = kitty.new(document_stub)

previous_owners_page_object = mock
document_stub.expects(:find).with("#previous_owners").returns(previous_owners_page_object)

previous_owners = verify_field_with_intermediary_class(jon, :previous_owners, ::AePageObjects::Collection, previous_owners_page_object)

first_owner_page_object = mock
previous_owners_page_object.expects(:all).with(:xpath, ".//*[contains(@class, 'item-list')]//*[contains(@class,'row') and not(contains(@style,'display'))]").returns([first_owner_page_object])
previous_owners_page_object.expects(:find).with(:xpath, ".//*[contains(@class, 'item-list')]//*[contains(@class,'row') and not(contains(@style,'display'))][1]").returns(first_owner_page_object)
first_owner = verify_item_field(previous_owners, 0, ::AePageObjects::Element, first_owner_page_object)
end

def test_collection__locator
Expand Down