From e9a52d769cd274f434c2c20e569b14721b6b0566 Mon Sep 17 00:00:00 2001 From: Mathieu Magnin Date: Fri, 29 Sep 2017 13:05:02 +0200 Subject: [PATCH] Add some tests on dossier filtering --- .../procedure_filters_spec.rb | 54 +++++++++++++++++-- 1 file changed, 51 insertions(+), 3 deletions(-) diff --git a/spec/features/new_gestionnaire/procedure_filters_spec.rb b/spec/features/new_gestionnaire/procedure_filters_spec.rb index 091e0db0e..69ef54da1 100644 --- a/spec/features/new_gestionnaire/procedure_filters_spec.rb +++ b/spec/features/new_gestionnaire/procedure_filters_spec.rb @@ -5,7 +5,8 @@ feature "procedure filters" do let(:gestionnaire) { create(:gestionnaire, procedures: [procedure]) } let!(:type_de_champ) { procedure.types_de_champ.first } let!(:new_unfollow_dossier) { create(:dossier, procedure: procedure, state: "received") } - let(:champ) { Champ.find_by(type_de_champ_id: type_de_champ.id) } + let!(:champ) { Champ.find_by(type_de_champ_id: type_de_champ.id, dossier_id: new_unfollow_dossier.id) } + let!(:new_unfollow_dossier_2) { create(:dossier, procedure: procedure, state: "received") } before do champ.update_attributes(value: "Mon champ rempli") @@ -14,8 +15,20 @@ feature "procedure filters" do end scenario "should display demandeur by default" do - expect(page).to have_content("Demandeur") - expect(page).to have_content(new_unfollow_dossier.user.email) + within ".dossiers-table" do + expect(page).to have_link("Demandeur") + expect(page).to have_link(new_unfollow_dossier.user.email) + end + end + + scenario "should list all dossiers" do + within ".dossiers-table" do + expect(page).to have_link(new_unfollow_dossier.id) + expect(page).to have_link(new_unfollow_dossier.user.email) + + expect(page).to have_link(new_unfollow_dossier_2.id) + expect(page).to have_link(new_unfollow_dossier_2.user.email) + end end scenario "should add be able to add created_at column", js: true do @@ -40,6 +53,41 @@ feature "procedure filters" do end end + scenario "should be able to add and remove filter", js: true do + add_filter(type_de_champ.libelle, champ.value) + + expect(page).to have_content("#{type_de_champ.libelle} : #{champ.value}") + + within ".dossiers-table" do + expect(page).to have_link(new_unfollow_dossier.id) + expect(page).to have_link(new_unfollow_dossier.user.email) + + expect(page).not_to have_link(new_unfollow_dossier_2.id) + expect(page).not_to have_link(new_unfollow_dossier_2.user.email) + end + + remove_filter + + within ".dossiers-table" do + expect(page).to have_link(new_unfollow_dossier.id) + expect(page).to have_link(new_unfollow_dossier.user.email) + + expect(page).to have_link(new_unfollow_dossier_2.id) + expect(page).to have_link(new_unfollow_dossier_2.user.email) + end + end + + def remove_filter + find(:xpath, "//span[contains(@class, 'filter')]/a").click + end + + def add_filter(column_name, filter_value) + find(:xpath, "//span[contains(text(), 'Filtrer')]").click + select column_name, from: "Colonne" + fill_in "Valeur", with: filter_value + click_button "Ajouter le filtre" + end + def add_column(column_name) find(:xpath, "//span[contains(text(), 'Personnaliser')]").click find("span.select2-container").click