Skip to content

Commit

Permalink
Add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
lexiwitch committed Jan 25, 2022
1 parent 5a7ec8c commit 479b2b4
Showing 1 changed file with 14 additions and 7 deletions.
21 changes: 14 additions & 7 deletions test/integration/admin/sites_integration_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,17 @@ class AdminSitesIntegrationTest < ActionDispatch::IntegrationTest
assert_select 'label', 'Hero image'
assert_select 'label', 'Hero image credit'

# See all neighbourhoods
assert_select '#site_neighbourhood_ids' do
assert_select 'option', @number_of_neighbourhoods
end
# See just neighbourhoods they admin
# In short:
# - Find the cocoon template for the Secondary Neighbourhoods <select> item
# - Grep for all occurences of "option value=" which grabs only the first <option> tag (not the closing tag)
# - That gives us all the neighbourhoods it is displaying
#
# Please replace this with Capybara in the future lol

cocoon_select_template = assert_select('.add_fields').first['data-association-insertion-template']
neighbourhoods_shown = cocoon_select_template.scan(/(option value=)/).size
assert neighbourhoods_shown == @number_of_neighbourhoods
end

test 'site admin users see appropriate fields' do
Expand All @@ -63,8 +70,8 @@ class AdminSitesIntegrationTest < ActionDispatch::IntegrationTest
assert_select 'label', 'Hero image credit'

# See just neighbourhoods they admin
assert_select '#site_neighbourhood_ids' do
assert_select 'option', 2
end
cocoon_select_template = assert_select('.add_fields').first['data-association-insertion-template']
neighbourhoods_shown = cocoon_select_template.scan(/(option value=)/).size
assert neighbourhoods_shown == 2
end
end

0 comments on commit 479b2b4

Please sign in to comment.