|
| 1 | +require "rails_helper" |
| 2 | + |
| 3 | +RSpec.describe "Topics search", type: :system do |
| 4 | + let(:admin) { create(:user, :admin, email: "[email protected]") } |
| 5 | + let(:english) { create(:language, name: "English") } |
| 6 | + let(:spanish) { create(:language, name: "Spanish") } |
| 7 | + let!(:spanish_active_topic) { create(:topic, language: spanish, title: "Tratamiento del resfriado", created_at: Date.new(2025, 02, 03)) } |
| 8 | + let!(:english_active_topic) { create(:topic, language: english, title: "How to treat colds", description: "All the latest information about nasopharyngitis", created_at: Date.new(2025, 03, 04)) } |
| 9 | + let!(:english_archived_topic) { create(:topic, :archived, language: english, title: "Obsolete", created_at: Date.new(2023, 02, 01)) } |
| 10 | + |
| 11 | + before do |
| 12 | + login_as(admin) |
| 13 | + click_link("Topics") |
| 14 | + end |
| 15 | + |
| 16 | + it "shows by default the topics from most to least recently added" do |
| 17 | + expect(page).to have_text(/#{english_active_topic.title}.+#{spanish_active_topic.title}.+#{english_archived_topic.title}/m) |
| 18 | + end |
| 19 | + |
| 20 | + context "searching by title" do |
| 21 | + it "only displays topics matching the search" do |
| 22 | + fill_in "search_query", with: "tratamiento" |
| 23 | + |
| 24 | + expect(page).to have_text(spanish_active_topic.title) |
| 25 | + expect(page).not_to have_text(english_active_topic.title) |
| 26 | + expect(page).not_to have_text(english_archived_topic.title) |
| 27 | + end |
| 28 | + end |
| 29 | + |
| 30 | + context "searching by description" do |
| 31 | + it "only displays topics matching the search" do |
| 32 | + fill_in "search_query", with: "pharyn" |
| 33 | + |
| 34 | + expect(page).to have_text(english_active_topic.title) |
| 35 | + expect(page).not_to have_text(spanish_active_topic.title) |
| 36 | + expect(page).not_to have_text(english_archived_topic.title) |
| 37 | + end |
| 38 | + end |
| 39 | + |
| 40 | + context "searching by language" do |
| 41 | + it "only displays topics matching the search" do |
| 42 | + select "Spanish", from: "search_language_id" |
| 43 | + |
| 44 | + expect(page).to have_text(spanish_active_topic.title) |
| 45 | + expect(page).not_to have_text(english_active_topic.title) |
| 46 | + expect(page).not_to have_text(english_archived_topic.title) |
| 47 | + |
| 48 | + select "English", from: "search_language_id" |
| 49 | + |
| 50 | + expect(page).to have_text(english_active_topic.title) |
| 51 | + expect(page).to have_text(english_archived_topic.title) |
| 52 | + expect(page).not_to have_text(spanish_active_topic.title) |
| 53 | + end |
| 54 | + end |
| 55 | + |
| 56 | + context "searching by year" do |
| 57 | + it "only displays topics matching the search" do |
| 58 | + select "2025", from: "search_year" |
| 59 | + |
| 60 | + expect(page).to have_text(spanish_active_topic.title) |
| 61 | + expect(page).to have_text(english_active_topic.title) |
| 62 | + expect(page).not_to have_text(english_archived_topic.title) |
| 63 | + |
| 64 | + select "2023", from: "search_year" |
| 65 | + |
| 66 | + expect(page).to have_text(english_archived_topic.title) |
| 67 | + expect(page).not_to have_text(spanish_active_topic.title) |
| 68 | + expect(page).not_to have_text(english_active_topic.title) |
| 69 | + end |
| 70 | + end |
| 71 | + |
| 72 | + context "searching by month" do |
| 73 | + it "only displays topics matching the search" do |
| 74 | + select "2", from: "search_month" |
| 75 | + |
| 76 | + expect(page).to have_text(spanish_active_topic.title) |
| 77 | + expect(page).to have_text(english_archived_topic.title) |
| 78 | + expect(page).not_to have_text(english_active_topic.title) |
| 79 | + |
| 80 | + select "3", from: "search_month" |
| 81 | + |
| 82 | + expect(page).to have_text(english_active_topic.title) |
| 83 | + expect(page).not_to have_text(english_archived_topic.title) |
| 84 | + expect(page).not_to have_text(spanish_active_topic.title) |
| 85 | + end |
| 86 | + end |
| 87 | + |
| 88 | + context "searching by state" do |
| 89 | + it "only displays topics matching the search" do |
| 90 | + select "active", from: "search_state" |
| 91 | + |
| 92 | + expect(page).to have_text(spanish_active_topic.title) |
| 93 | + expect(page).to have_text(english_active_topic.title) |
| 94 | + expect(page).not_to have_text(english_archived_topic.title) |
| 95 | + |
| 96 | + select "archived", from: "search_state" |
| 97 | + |
| 98 | + expect(page).to have_text(english_archived_topic.title) |
| 99 | + expect(page).not_to have_text(spanish_active_topic.title) |
| 100 | + expect(page).not_to have_text(english_active_topic.title) |
| 101 | + end |
| 102 | + end |
| 103 | + |
| 104 | + context "sorting" do |
| 105 | + it "displays users in the selected order" do |
| 106 | + select "asc", from: "search_order" |
| 107 | + expect(page).to have_text(/#{english_archived_topic.title}.+#{spanish_active_topic.title}.+#{english_active_topic.title}/m) |
| 108 | + end |
| 109 | + end |
| 110 | +end |
0 commit comments