-
-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactor conditional rendering for primary neighbourhood in site admin (
- Loading branch information
1 parent
ecdc157
commit 5f7d211
Showing
4 changed files
with
26 additions
and
25 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
25 changes: 13 additions & 12 deletions
25
app/views/admin/sites/_sites_neighbourhood_fields.html.erb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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]' | ||
|
@@ -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 |