require "rails_helper" RSpec.describe SearchResultCaptionComponent, type: :component do let(:searched) { "search item" } let(:count) { 2 } let(:item_label) { "user" } let(:total_count) { 3 } let(:item) { "schemes" } let(:filters_count) { 1 } let(:result) { render_inline(described_class.new(searched:, count:, item_label:, total_count:, item:, filters_count:)) } context "when search and filter results are found" do it "renders table caption including the search results and total" do expect(result.to_html).to eq("\n 2 users matching search and filters
\n
\n") end end context "when search results are found" do let(:filters_count) { nil } it "renders table caption including the search results and total" do expect(result.to_html).to eq("\n 2 users matching search
\n
\n") end end context "when filter results are found" do let(:searched) { nil } it "renders table caption including the search results and total" do expect(result.to_html).to eq("\n 2 users matching filters
\n
\n") end end context "when no search/filter is applied" do let(:searched) { nil } let(:filters_count) { nil } it "renders table caption with total count only" do expect(result.to_html).to eq("\n \n 2 total schemes\n \n\n") end end context "when nothing is found" do let(:count) { 0 } it "renders table caption with total count only" do expect(result.to_html).to eq("\n 0 users matching search and filters
\n
\n") end end context "when 1 record is found" do let(:count) { 1 } it "renders table caption with total count only" do expect(result.to_html).to eq("\n 1 user matching search and filters
\n
\n") end end end