fix(champ): do not reset data on champs without fetch_external_data
This commit is contained in:
parent
6ef969a7d9
commit
702b9dd8b3
8 changed files with 589 additions and 142 deletions
|
@ -1,3 +1,3 @@
|
|||
= render Dsfr::ComboboxComponent.new form: @form, url: data_sources_data_source_adresse_path, selected: @champ.value, allows_custom_value: true, input_html_options: { name: :value, id: @champ.input_id, class: 'fr-select', describedby: @champ.describedby_id } do
|
||||
= @form.hidden_field :external_id, data: { value_slot: 'value' }
|
||||
= @form.hidden_field :feature, data: { value_slot: 'data' }
|
||||
= @form.hidden_field :feature, value: '', data: { value_slot: 'data' }
|
||||
|
|
|
@ -44,6 +44,8 @@ export class ComboboxUI implements EventListenerObject {
|
|||
#allowsCustomValue: boolean;
|
||||
#limit?: number;
|
||||
|
||||
#selectedData: Option['data'] = null;
|
||||
|
||||
constructor({
|
||||
input,
|
||||
selectedValueInput,
|
||||
|
@ -293,7 +295,8 @@ export class ComboboxUI implements EventListenerObject {
|
|||
private dispatchChange(cb: () => Option['data']): void {
|
||||
const value = this.#selectedValueInput.value;
|
||||
const data = cb();
|
||||
if (value != this.#selectedValueInput.value) {
|
||||
if (value != this.#selectedValueInput.value || data != this.#selectedData) {
|
||||
this.#selectedData = data;
|
||||
for (const input of this.#valueSlots) {
|
||||
switch (input.dataset.valueSlot) {
|
||||
case 'value':
|
||||
|
|
|
@ -282,7 +282,7 @@ class Champ < ApplicationRecord
|
|||
end
|
||||
|
||||
def cleanup_if_empty
|
||||
if persisted? && external_id_changed?
|
||||
if fetch_external_data? && persisted? && external_id_changed?
|
||||
self.data = nil
|
||||
end
|
||||
end
|
||||
|
|
|
@ -3,10 +3,6 @@ class Champs::AddressChamp < Champs::TextChamp
|
|||
data.present?
|
||||
end
|
||||
|
||||
def feature
|
||||
''
|
||||
end
|
||||
|
||||
def feature=(value)
|
||||
return if value.blank?
|
||||
feature = JSON.parse(value)
|
||||
|
|
557
spec/fixtures/cassettes/The_user/fill_a_dossier.yml
vendored
Normal file
557
spec/fixtures/cassettes/The_user/fill_a_dossier.yml
vendored
Normal file
File diff suppressed because one or more lines are too long
113
spec/fixtures/cassettes/communes.yml
vendored
113
spec/fixtures/cassettes/communes.yml
vendored
|
@ -1,113 +0,0 @@
|
|||
---
|
||||
http_interactions:
|
||||
- request:
|
||||
method: get
|
||||
uri: https://geo.api.gouv.fr/communes?boost=population&codePostal=60&limit=20&type=commune-actuelle,arrondissement-municipal
|
||||
body:
|
||||
encoding: US-ASCII
|
||||
string: ''
|
||||
headers:
|
||||
User-Agent:
|
||||
- demarches-simplifiees.fr
|
||||
Expect:
|
||||
- ''
|
||||
response:
|
||||
status:
|
||||
code: 200
|
||||
message: ''
|
||||
headers:
|
||||
Server:
|
||||
- nginx/1.10.3 (Ubuntu)
|
||||
Date:
|
||||
- Tue, 13 Feb 2024 11:25:44 GMT
|
||||
Content-Type:
|
||||
- application/json; charset=utf-8
|
||||
Content-Length:
|
||||
- '2'
|
||||
X-Powered-By:
|
||||
- Express
|
||||
Vary:
|
||||
- Origin
|
||||
Etag:
|
||||
- W/"2-l9Fw4VUO7kr8CvBlt4zaMCqXZ0w"
|
||||
Strict-Transport-Security:
|
||||
- max-age=15552000
|
||||
body:
|
||||
encoding: ASCII-8BIT
|
||||
string: "[]"
|
||||
recorded_at: Tue, 13 Feb 2024 11:25:44 GMT
|
||||
- request:
|
||||
method: get
|
||||
uri: https://geo.api.gouv.fr/communes?boost=population&codePostal=6040&limit=20&type=commune-actuelle,arrondissement-municipal
|
||||
body:
|
||||
encoding: US-ASCII
|
||||
string: ''
|
||||
headers:
|
||||
User-Agent:
|
||||
- demarches-simplifiees.fr
|
||||
Expect:
|
||||
- ''
|
||||
response:
|
||||
status:
|
||||
code: 200
|
||||
message: ''
|
||||
headers:
|
||||
Server:
|
||||
- nginx/1.10.3 (Ubuntu)
|
||||
Date:
|
||||
- Tue, 13 Feb 2024 11:25:44 GMT
|
||||
Content-Type:
|
||||
- application/json; charset=utf-8
|
||||
Content-Length:
|
||||
- '2'
|
||||
X-Powered-By:
|
||||
- Express
|
||||
Vary:
|
||||
- Origin
|
||||
Etag:
|
||||
- W/"2-l9Fw4VUO7kr8CvBlt4zaMCqXZ0w"
|
||||
Strict-Transport-Security:
|
||||
- max-age=15552000
|
||||
body:
|
||||
encoding: ASCII-8BIT
|
||||
string: "[]"
|
||||
recorded_at: Tue, 13 Feb 2024 11:25:44 GMT
|
||||
- request:
|
||||
method: get
|
||||
uri: https://geo.api.gouv.fr/communes?boost=population&codePostal=60400&limit=20&type=commune-actuelle,arrondissement-municipal
|
||||
body:
|
||||
encoding: US-ASCII
|
||||
string: ''
|
||||
headers:
|
||||
User-Agent:
|
||||
- demarches-simplifiees.fr
|
||||
Expect:
|
||||
- ''
|
||||
response:
|
||||
status:
|
||||
code: 200
|
||||
message: ''
|
||||
headers:
|
||||
Server:
|
||||
- nginx/1.10.3 (Ubuntu)
|
||||
Date:
|
||||
- Tue, 13 Feb 2024 11:25:44 GMT
|
||||
Content-Type:
|
||||
- application/json; charset=utf-8
|
||||
Content-Length:
|
||||
- '3234'
|
||||
Vary:
|
||||
- Accept-Encoding
|
||||
- Origin
|
||||
X-Powered-By:
|
||||
- Express
|
||||
Etag:
|
||||
- W/"ca2-8NmtTi6sTg1Smpmu0voZ0sZ2g4c"
|
||||
Strict-Transport-Security:
|
||||
- max-age=15552000
|
||||
body:
|
||||
encoding: ASCII-8BIT
|
||||
string: !binary |-
|
||||
W3sibm9tIjoiQXBwaWxseSIsImNvZGUiOiI2MDAyMSIsImNvZGVEZXBhcnRlbWVudCI6IjYwIiwic2lyZW4iOiIyMTYwMDAyMTYiLCJjb2RlRXBjaSI6IjI0NjAwMDc1NiIsImNvZGVSZWdpb24iOiIzMiIsImNvZGVzUG9zdGF1eCI6WyI2MDQwMCJdLCJwb3B1bGF0aW9uIjo1Mjl9LHsibm9tIjoiQmFixZN1ZiIsImNvZGUiOiI2MDAzNyIsImNvZGVEZXBhcnRlbWVudCI6IjYwIiwic2lyZW4iOiIyMTYwMDAzNjQiLC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YwNDg4IiwiY29kZURlcGFydGVtZW50IjoiNjAiLCJzaXJlbiI6IjIxNjAwNDgyMCIsImNvZGVFcGNpIjoiMjQ2MDAwNzU2IiwiY29kZVJlZ2lvbiI6IjMyIiwiY29kZXNQb3N0YXV4IjpbIjYwNDAwIl0sInBvcHVsYXRpb24iOjI3Mn0seyJub20iOiJQb250LWwnw4l2w6pxdWUiLCJjb2RlIjoiNjA1MDYiLCJjb2RlRGVwYXJ0ZW1lbnQiOiI2MCIsInNpcmVuIjoiMjE2MDA1MDA5IiwiY29kZUVwY2kiOiIyNDYwMDA3NTYiLCJjb2RlUmVnaW9uIjoiMzIiLCJjb2Rlc1Bvc3RhdXgiOlsiNjA0MDAiXSwicG9wdWxhdGlvbiI6Njc5fSx7Im5vbSI6IlBvbnRvaXNlLWzDqHMtTm95b24iLCJjb2RlIjoiNjA1MDciLCJjb2RlRGVwYXJ0ZW1lbnQiOiI2MCIsInNpcmVuIjoiMjE2MDA1MDE3IiwiY29kZUVwY2kiOiIyNDYwMDA3NTYiLCJjb2RlUmVnaW9uIjoiMzIiLCJjb2Rlc1Bvc3RhdXgiOlsiNjA0MDAiXSwicG9wdWxhdGlvbiI6NDUzfSx7Im5vbSI6IlBvcnF1w6lyaWNvdXJ0IiwiY29kZSI6IjYwNTExIiwiY29kZURlcGFydGVtZW50IjoiNjAiLCJzaXJlbiI6IjIxNjAwNTA1OCIsImNvZGVFcGNpIjoiMjQ2MDAwNzU2IiwiY29kZVJlZ2lvbiI6IjMyIiwiY29kZXNQb3N0YXV4IjpbIjYwNDAwIl0sInBvcHVsYXRpb24iOjQwMX1d
|
||||
recorded_at: Tue, 13 Feb 2024 11:25:44 GMT
|
||||
recorded_with: VCR 6.1.0
|
|
@ -551,7 +551,7 @@ describe Champ do
|
|||
end
|
||||
|
||||
describe "fetch_external_data" do
|
||||
let(:champ) { create(:champ_text, data: 'some data') }
|
||||
let(:champ) { create(:champ_rnf, data: 'some data') }
|
||||
|
||||
context "cleanup_if_empty" do
|
||||
it "remove data if external_id changes" do
|
||||
|
@ -565,8 +565,7 @@ describe Champ do
|
|||
let(:data) { 'some other data' }
|
||||
|
||||
it "fill data from external source" do
|
||||
expect(champ).to receive(:fetch_external_data?) { true }
|
||||
expect_any_instance_of(Champs::TextChamp).to receive(:fetch_external_data) { data }
|
||||
expect_any_instance_of(Champs::RNFChamp).to receive(:fetch_external_data) { data }
|
||||
|
||||
perform_enqueued_jobs do
|
||||
champ.update(external_id: 'external_id')
|
||||
|
@ -574,8 +573,9 @@ describe Champ do
|
|||
expect(champ.reload.data).to eq data
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
context "#input_name" do
|
||||
describe "#input_name" do
|
||||
let(:champ) { create(:champ_text) }
|
||||
it { expect(champ.input_name).to eq "dossier[champs_public_attributes][#{champ.id}]" }
|
||||
|
||||
|
@ -594,7 +594,6 @@ describe Champ do
|
|||
it { expect(champ.input_name).to eq "dossier[champs_private_attributes][#{champ.id}]" }
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe '#update_with_external_data!' do
|
||||
let(:champ) { create(:champ_siret) }
|
||||
|
|
|
@ -6,7 +6,7 @@ describe 'The user' do
|
|||
let(:user_dossier) { user.dossiers.first }
|
||||
let!(:dossier_to_link) { create(:dossier) }
|
||||
|
||||
scenario 'fill a dossier', js: true, vcr: { cassette_name: 'communes' } do
|
||||
scenario 'fill a dossier', js: true, vcr: true do
|
||||
log_in(user, procedure)
|
||||
|
||||
fill_individual
|
||||
|
@ -36,12 +36,17 @@ describe 'The user' do
|
|||
select('Australie', from: form_id_for('pays'))
|
||||
select('Martinique', from: form_id_for('regions'))
|
||||
select('02 – Aisne', from: form_id_for('departements'))
|
||||
|
||||
fill_in('communes', with: '60400')
|
||||
find('li', text: 'Brétigny (60400)').click
|
||||
|
||||
# communes needs more time to be updated
|
||||
wait_until { champ_value_for('communes') == "Brétigny" }
|
||||
|
||||
fill_in('address', with: '78 Rue du Grés 30310 Vergè')
|
||||
find('li', text: '78 Rue du Grés 30310 Vergèze').click
|
||||
wait_until { champ_value_for('address') == '78 Rue du Grés 30310 Vergèze' }
|
||||
expect(champ_for('address').full_address?).to be_truthy
|
||||
expect(champ_for('address').departement_code_and_name).to eq('30 – Gard')
|
||||
|
||||
fill_in('dossier_link', with: '123')
|
||||
find('.editable-champ-piece_justificative input[type=file]').attach_file(Rails.root + 'spec/fixtures/files/file.pdf')
|
||||
|
||||
|
|
Loading…
Reference in a new issue