Mise à jour des tests

This commit is contained in:
Kara Diaby 2024-10-03 14:40:41 +02:00
parent 1c651b4c93
commit 953ccbcfb6
No known key found for this signature in database
GPG key ID: C4D1B0CF9F24D759
2 changed files with 27 additions and 26 deletions

View file

@ -15,7 +15,8 @@ describe Administrateurs::ProceduresController, type: :controller do
let(:lien_site_web) { 'http://mon-site.gouv.fr' }
let(:zone) { create(:zone) }
let(:zone_ids) { [zone.id] }
let(:tags) { ["planete", "environnement"] }
let!(:tag1) { ProcedureTag.create(name: 'Aao') }
let!(:tag2) { ProcedureTag.create(name: 'Accompagnement') }
describe '#apercu' do
subject { get :apercu, params: { id: procedure.id } }
@ -64,7 +65,7 @@ describe Administrateurs::ProceduresController, type: :controller do
monavis_embed: monavis_embed,
zone_ids: zone_ids,
lien_site_web: lien_site_web,
tags: tags
procedure_tag_names: ['Aao', 'Accompagnement']
}
}
@ -278,21 +279,29 @@ describe Administrateurs::ProceduresController, type: :controller do
end
context 'with specific tag' do
let!(:tags_procedure) { create(:procedure, :published, tags: ['environnement', 'diplomatie']) }
let!(:tag_environnement) { ProcedureTag.create(name: 'environnement') }
let!(:tag_diplomatie) { ProcedureTag.create(name: 'diplomatie') }
let!(:tag_football) { ProcedureTag.create(name: 'football') }
let!(:procedure) do
procedure = create(:procedure, :published)
procedure.procedure_tags << [tag_environnement, tag_diplomatie]
procedure
end
it 'returns procedure who contains at least one tag included in params' do
get :all, params: { tags: ['environnement'] }
expect(assigns(:procedures).any? { |p| p.id == tags_procedure.id }).to be_truthy
get :all, params: { procedure_tag_names: ['environnement'] }
expect(assigns(:procedures).any? { |p| p.id == procedure.id }).to be_truthy
end
it 'returns procedures who contains all tags included in params' do
get :all, params: { tags: ['environnement', 'diplomatie'] }
expect(assigns(:procedures).any? { |p| p.id == tags_procedure.id }).to be_truthy
get :all, params: { procedure_tag_names: ['environnement', 'diplomatie'] }
expect(assigns(:procedures).any? { |p| p.id == procedure.id }).to be_truthy
end
it 'does not returns the procedure' do
get :all, params: { tags: ['environnement', 'diplomatie', 'football'] }
expect(assigns(:procedures).any? { |p| p.id == tags_procedure.id }).to be_falsey
it 'returns the procedure when at least one tag is include' do
get :all, params: { procedure_tag_names: ['environnement', 'diplomatie', 'football'] }
expect(assigns(:procedures).any? { |p| p.id == procedure.id }).to be_truthy
end
end
@ -495,8 +504,7 @@ describe Administrateurs::ProceduresController, type: :controller do
expect(subject.organisation).to eq(organisation)
expect(subject.administrateurs).to eq([admin])
expect(subject.duree_conservation_dossiers_dans_ds).to eq(duree_conservation_dossiers_dans_ds)
expect(subject.tags).to eq(["planete", "environnement"])
expect(subject.procedure_tags.pluck(:name)).to match_array(['Aao', 'Accompagnement'])
expect(response).to redirect_to(champs_admin_procedure_path(Procedure.last))
expect(flash[:notice]).to be_present
end

View file

@ -58,23 +58,16 @@ describe 'Administrateurs can edit procedures', js: true do
end
context 'when we associate tags' do
scenario 'the administrator can edit and persist the tags' do
procedure.update!(tags: ['social'])
let!(:social_tag) { ProcedureTag.create(name: 'social') }
let!(:planete_tag) { ProcedureTag.create(name: 'planete') }
scenario 'the tags are persisted when not interacting with the tags combobox' do
procedure.procedure_tags << social_tag
visit edit_admin_procedure_path(procedure)
select_combobox('procedure_tags_combo', 'planete', custom_value: true)
click_on 'Enregistrer'
expect(procedure.reload.tags).to eq(['social', 'planete'])
end
scenario 'the tags are persisted when non interacting with the tags combobox' do
procedure.update!(tags: ['social'])
visit edit_admin_procedure_path(procedure)
click_on 'Enregistrer'
expect(procedure.reload.tags).to eq(['social'])
expect(procedure.procedure_tags.pluck(:name)).to match_array(['social'])
end
end