Files
nairobi/spec/factories/administration.rb
Javi Martín 9c037a484e Make proposals map test more robust
We were testing what happens when clicking on a geozone without HTML
coordinates, which won't happen in a real browser.

So we're now defining the HTML coordinates and clicking on the area in
the test, which is what real people will do.

We also avoid having two consecutive `visit` calls, which will interfere
with the way we plan to test the presence of the <main> tag after every
`visit`.

Note that, the test didn't work with the HTML coordinates defined in the
`with_html_coordinates` trait, with Capybara showing the following
error:

```
Selenium::WebDriver::Error::ElementClickInterceptedError:
element click intercepted: Element
  <area shape="poly"
  coords="30,139,45,153,77,148,107,165"
  href="/proposals?search=California"
  title="California" alt="California">
is not clickable at point (413, 456).
Other element would receive the click:
  <img usemap="#map" src="/assets/map.jpg">
```

The cause of this error was the strange shape of the polygon, which was
greatly concave and and so the middle of its area wasn't part of it.
We're changing the polygon so it's now convex and when Capybara clicks
on its middle point everything will work as expected.
2024-03-23 00:33:41 +01:00

122 lines
3.0 KiB
Ruby

FactoryBot.define do
factory :setting do
sequence(:key) { |n| "Setting Key #{n}" }
sequence(:value) { |n| "Setting #{n} Value" }
end
factory :geozone do
sequence(:name) { |n| "District #{n}" }
sequence(:external_code, &:to_s)
sequence(:census_code, &:to_s)
color { "#0081aa" }
trait :in_census do
census_code { "01" }
end
trait :with_html_coordinates do
html_map_coordinates { "30,139,45,153,77,148,107,125" }
end
trait :with_geojson do
geojson do
'{ "geometry": { "type": "Polygon", "coordinates": [[0.117,51.513],[0.118,51.512],[0.119,51.514]] } }'
end
end
end
factory :banner do
sequence(:title) { |n| "Banner title #{n}" }
sequence(:description) { |n| "This is the text of Banner #{n}" }
target_url { ["/proposals", "/debates"].sample }
post_started_at { Date.current - 7.days }
post_ended_at { Date.current + 7.days }
background_color { "#FF0000" }
font_color { "#FFFFFF" }
end
factory :web_section do
name { "homepage" }
end
factory :banner_section, class: "Banner::Section" do
banner_id factory: :banner
web_section
end
factory :site_customization_page, class: "SiteCustomization::Page" do
slug { "example-page" }
title { "Example page" }
subtitle { "About an example" }
content { "This page is about..." }
more_info_flag { false }
print_content_flag { false }
status { "draft" }
trait :published do
status { "published" }
end
trait :display_in_more_info do
more_info_flag { true }
end
end
factory :site_customization_content_block, class: "SiteCustomization::ContentBlock" do
name { "top_links" }
locale { "en" }
body { "Some top links content" }
end
factory :site_customization_image, class: "SiteCustomization::Image" do
image { Rack::Test::UploadedFile.new("spec/fixtures/files/logo_header.png") }
name { "logo_header" }
end
factory :map_location do
latitude { Setting["map.latitude"] }
longitude { Setting["map.longitude"] }
zoom { Setting["map.zoom"] }
trait :proposal_map_location do
proposal
end
trait :budget_investment_map_location do
investment factory: :budget_investment
end
end
factory :widget_card, class: "Widget::Card" do
sequence(:title) { |n| "Title #{n}" }
sequence(:description) { |n| "Description #{n}" }
sequence(:link_text) { |n| "Link text #{n}" }
sequence(:link_url) { |n| "Link url #{n}" }
trait :header do
header { true }
end
after :create do |widget_card|
create(:image, imageable: widget_card)
end
end
factory :widget_feed, class: "Widget::Feed"
factory :i18n_content, class: "I18nContent" do
key { "debates.index.section_footer.description" }
value_es { "Texto en español" }
value_en { "Text in english" }
end
factory :tenant do
sequence(:name) { |n| "Tenant #{n}" }
sequence(:schema) { |n| "subdomain#{n}" }
trait :domain do
schema_type { :domain }
end
end
end