Skip to content

Commit

Permalink
Refactor conditional rendering for primary neighbourhood in site admin (
Browse files Browse the repository at this point in the history
  • Loading branch information
aaaaargZombies authored Aug 3, 2022
1 parent ecdc157 commit 5f7d211
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 25 deletions.
1 change: 0 additions & 1 deletion app/javascript/src/behaviors/all_behaviors.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,3 @@ import { Behaviors } from './behaviors.base.js'
import './behaviors.collection.js'
import './behaviors.partner.js'
import './behaviors.place.js'
import './behaviors.site.js'
12 changes: 0 additions & 12 deletions app/javascript/src/behaviors/behaviors.site.js

This file was deleted.

25 changes: 13 additions & 12 deletions app/views/admin/sites/_sites_neighbourhood_fields.html.erb
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
<fieldset class="input-group nested-fields p-0">
<%# The style width setting here is applied to dynamically created elements, we do not know why. %>
<%# TODO: Fix the dynamic styling so that width does not get applied, so we can remove this smell %>
<%= f.input :neighbourhood_id, collection: options_for_sites_neighbourhoods, include_blank: false,
value_method: ->(obj) { obj[:id] },
label_method: ->(obj) { obj[:name] },
input_html: { class: 'form-control', data: { controller: "select2" }, style: "width: 599.8px;" },
label: '', label_html: { hidden: true } %>

<%# This label causes behaviours.site.js to remove the association from the form %>
<%= f.label :ignore, class: 'cocoon_delete-this' if f.object.relation_type == 'Primary' %>
<div class="input-group-append p-0">
<%= f.hidden_field :relation_type, value: 'Secondary' %>
<%= link_to_remove_association 'Remove', f, class: "pl-2 pt-1 text-danger" %>
</div>
<% if f.object.relation_type != 'Primary' %>
<%# If the sites neighbourhood's relation_type is primary we do not render it %>
<%# so it does not submit a primary relation as being a secondary one or remove it %>
<%= f.input :neighbourhood_id, collection: options_for_sites_neighbourhoods, include_blank: false,
value_method: ->(obj) { obj[:id] },
label_method: ->(obj) { obj[:name] },
input_html: { class: 'form-control', data: { controller: "select2" }, style: "width: 599.8px;" },
label: '', label_html: { hidden: true } %>
<div class="input-group-append p-0">
<%= f.hidden_field :relation_type, value: 'Secondary' %>
<%= link_to_remove_association 'Remove', f, class: "pl-2 pt-1 text-danger" %>
</div>
<% end %>
</fieldset>
13 changes: 13 additions & 0 deletions test/system/admin/site_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@ class AdminSiteTest < ApplicationSystemTestCase
@neighbourhood_one = neighbourhoods[1].to_s.gsub('w', 'W')
@neighbourhood_two = neighbourhoods[2].to_s.gsub('w', 'W')

@sites_neighbourhood = create(:sites_neighbourhood,
site: @site,
neighbourhood: neighbourhoods[1])

# logging in as root user
visit '/users/sign_in'
fill_in 'Email', with: '[email protected]'
Expand Down Expand Up @@ -70,4 +74,13 @@ class AdminSiteTest < ApplicationSystemTestCase
tags = select2_node 'site_tags'
assert_select2_multiple [@tag.name, @tag_pub.name], tags
end
test 'primary neighbourhood not rendering on other neighbourhoods section' do
click_sidebar 'sites'
await_datatables
click_link @site.name
await_select2
service_areas = all_cocoon_select2_nodes 'sites_neighbourhoods'
msg = '@site should only have a primary neighbourhood, if this fails either this is now rendering where it should\'t or another neighborhood has been added at setup and the test should be adjusted'
assert service_areas.length.zero?, msg
end
end

0 comments on commit 5f7d211

Please sign in to comment.