Skip to content

Commit

Permalink
tech(review): implement some pair review suggestions
Browse files Browse the repository at this point in the history
  • Loading branch information
Martin committed Jan 12, 2024
1 parent e7eee7b commit 69346ad
Show file tree
Hide file tree
Showing 9 changed files with 17 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@ def procedure

def button_title
if annotations?
"Ajouter une annotation"
"Ajouter une annotation"
else
"Ajouter un champ"
"Ajouter un champ"
end
end

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
%li.type-de-champ.flex.column.justify-start.fr-mb-6w{ html_options }
.type-de-champ-container
.flex.justify-between.section.head
.position.flex.align-center= "##{@coordinate.position}"
.position.flex.align-center= @coordinate.position.to_s
.fr-btn.fr-btn--tertiary-no-outline.handle.fr-icon-drag-move-2-line{ title: "Déplacer le champ vers le haut ou vers le bas" }
%button.fr-btn.fr-btn--tertiary-no-outline.fr-icon-arrow-up-line.move-up{ move_button_options(:up) }
%button.fr-btn.fr-btn--tertiary-no-outline.fr-icon-arrow-down-line.move-down{ move_button_options(:down) }
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
= form_with(url: move_and_morph_admin_procedure_type_de_champ_path(@coordinate.revision.procedure, @coordinate.type_de_champ.stable_id), class: 'fr-ml-3w flex', method: :patch, data: { turbo: true }) do |f|
= label_tag :target_stable_id, "Déplacer le champ", for: describedby_id, class: 'flex align-center flex-no-shrink fr-mr-3w'
= label_tag :target_stable_id, "Déplacer ce champ à la place de ", for: describedby_id, class: 'flex align-center flex-no-shrink fr-mr-3w'
= select_tag :target_stable_id, options_for_select(options), id: describedby_id, class: 'fr-select', aria: { discribedby: describedby_id }, data: { 'select-champ-position-template-target': 'select', selected: @coordinate.stable_id }
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
%div{ id: block_id, data: { 'select-champ-position-template-target': 'template', turbo_force: :server } }
%select
%option{ disabled: :disabled } Selectionner une option
- @coordinates.each do |coordinate|
%option{ value: coordinate.stable_id }= "#{coordinate.position} #{coordinate.libelle}"
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ def move
def move_and_morph
source_type_de_champ = draft.find_and_ensure_exclusive_use(params[:stable_id])
target_type_de_champ = draft.find_and_ensure_exclusive_use(params[:target_stable_id])
@coordinate = @source_coordinate = draft.coordinate_for(source_type_de_champ)
@coordinate = draft.coordinate_for(source_type_de_champ)
from = @coordinate.position
to = draft.coordinate_for(target_type_de_champ).position
@coordinate = draft.move_type_de_champ(@coordinate.stable_id, to)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ export class SelectChampPositionTemplateController extends ApplicationController
.map((option) => {
if (option.value == focusedSelectStableId) {
option.setAttribute('selected', 'selected');
option.setAttribute('disabled', 'disabled');
}

return option.outerHTML;
Expand Down
4 changes: 2 additions & 2 deletions spec/support/system_helpers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -71,11 +71,11 @@ def click_reset_password_link_for(email)

# Add a new type de champ in the procedure editor
def add_champ
click_on 'Ajouter un champ'
click_on 'Ajouter un champ'
end

def remove_flash_message
expect(page).to have_button('Ajouter un champ', disabled: false)
expect(page).to have_button('Ajouter un champ', disabled: false)
expect(page).to have_content('Formulaire enregistré')
execute_script("document.querySelector('#flash_message').remove();")
execute_script("document.querySelector('#autosave-notice').remove();")
Expand Down
2 changes: 1 addition & 1 deletion spec/system/administrateurs/annotations_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
end

scenario "adding a new champ" do
click_on 'Ajouter une annotation'
click_on 'Ajouter une annotation'

select('Carte', from: 'Type de champ')
# ensure UI update is ok
Expand Down
16 changes: 8 additions & 8 deletions spec/system/administrateurs/types_de_champ_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
}

# Champs are automatically saved
expect(page).to have_button('Ajouter un champ', disabled: false)
expect(page).to have_button('Ajouter un champ', disabled: false)
page.refresh
expect(page).to have_selector('.type-de-champ', count: 3)

Expand Down Expand Up @@ -111,7 +111,7 @@
page.refresh

within '.type-de-champ .editor-block' do
click_on 'Ajouter un champ'
click_on 'Ajouter un champ'

fill_in 'Libellé du champ', with: 'libellé de champ 1'
end
Expand Down Expand Up @@ -259,17 +259,17 @@
scenario 'when select is focused, it seeds its options' do
# once clicked, the select is updated with root champs options only, preselected on coordinates and have nice libelles
page.find(initial_first_coordinate_selector).click
expect(page).to have_selector("#{initial_first_coordinate_selector} option", count: 4)
expect(page).to have_selector("#{initial_first_coordinate_selector} option", count: 3)
expect(page.find(initial_first_coordinate_selector).find("option[selected]").value.to_s).to eq(initial_first_coordinate.stable_id.to_s)
expect(page.find(initial_first_coordinate_selector).all("option").map(&:text)).to match_array(["Selectionner une option", '0 first_tdc', '1 middle_tdc', '2 last_tdc'])
expect(page.find(initial_first_coordinate_selector).all("option").map(&:text)).to match_array(['0 first_tdc', '1 middle_tdc', '2 last_tdc'])

# renaming a tdc renames it's option
within "##{dom_id(initial_first_coordinate, :type_de_champ_editor)}" do
fill_in 'Libellé du champ', with: 'renamed'
end
wait_until { initial_first_coordinate.reload.libelle == 'renamed' }
page.find(initial_first_coordinate_selector).click
expect(page.find(initial_first_coordinate_selector).all("option").map(&:text)).to match_array(["Selectionner une option", '0 renamed', '1 middle_tdc', '2 last_tdc'])
expect(page.find(initial_first_coordinate_selector).all("option").map(&:text)).to match_array(['0 renamed', '1 middle_tdc', '2 last_tdc'])
end

scenario 'when select is changed, it move the coordinates' do
Expand All @@ -287,7 +287,7 @@

# check reorder rerendered champ component between target->destination
reordered_coordinates.map(&:reload).map do |coordinate|
expect(page).to have_selector("##{ActionView::RecordIdentifier.dom_id(coordinate, :type_de_champ_editor)} .position", text: "##{coordinate.position}")
expect(page).to have_selector("##{ActionView::RecordIdentifier.dom_id(coordinate, :type_de_champ_editor)} .position", text: coordinate.position)
end
end
end
Expand Down Expand Up @@ -317,10 +317,10 @@

scenario 'when first child select is focused, seed with repetition only tdcs' do
page.find(first_child_coordinate_selector).click
expect(page).to have_selector("#{first_child_coordinate_selector} option", count: 3)
expect(page).to have_selector("#{first_child_coordinate_selector} option", count: 2)

opts = page.find(first_child_coordinate_selector).all("option").map(&:text)
expect(opts).to match_array(["Selectionner une option"] + children_coordinates.map { "#{_1.position} #{_1.libelle}" })
expect(opts).to match_array(children_coordinates.map { "#{_1.position} #{_1.libelle}" })
end

scenario 'when first child select is changed, move champ in repetition' do
Expand Down

0 comments on commit 69346ad

Please sign in to comment.