From 46e14f403319765b3ce399694150f8f72f0562a5 Mon Sep 17 00:00:00 2001 From: clemkeirua Date: Mon, 6 Apr 2020 18:06:38 +0200 Subject: [PATCH] add test for users/list_dossiers_spec --- spec/features/users/list_dossiers_spec.rb | 31 ++++++++++++++++++++++- 1 file changed, 30 insertions(+), 1 deletion(-) diff --git a/spec/features/users/list_dossiers_spec.rb b/spec/features/users/list_dossiers_spec.rb index a601eb2fb..445f5b12a 100644 --- a/spec/features/users/list_dossiers_spec.rb +++ b/spec/features/users/list_dossiers_spec.rb @@ -1,7 +1,7 @@ describe 'user access to the list of their dossiers' do let(:user) { create(:user) } let!(:dossier_brouillon) { create(:dossier, user: user) } - let!(:dossier_en_construction) { create(:dossier, :en_construction, user: user) } + let!(:dossier_en_construction) { create(:dossier, :with_all_champs, :en_construction, user: user) } let!(:dossier_en_instruction) { create(:dossier, :en_instruction, user: user) } let!(:dossier_archived) { create(:dossier, :en_instruction, :archived, user: user) } let(:dossiers_per_page) { 25 } @@ -119,5 +119,34 @@ describe 'user access to the list of their dossiers' do expect(current_path).to eq(dossier_path(dossier_en_construction)) end end + + context "when user search for something inside the dossier" do + let(:dossier_en_construction2) { create(:dossier, :with_all_champs, :en_construction, user: user) } + before do + page.find_by_id('q').set(dossier_en_construction.champs.first.value) + end + + context 'when it only matches one dossier' do + before do + click_button("Rechercher") + end + it "redirects to the dossier page" do + expect(current_path).to eq(dossier_path(dossier_en_construction)) + end + end + + context 'when it matches multiple dossier' do + before do + dossier_en_construction2.champs.first.update(value: dossier_en_construction.champs.first.value) + click_button("Rechercher") + end + + it "redirects to the search results" do + expect(current_path).to eq(recherche_dossiers_path) + expect(page).to have_content(dossier_en_construction.id) + expect(page).to have_content(dossier_en_construction2.id) + end + end + end end end