Files
fizzy/test/controllers/searches_controller_test.rb
T
Mike Dalessio 99fe5ff934 Make sure that comments show up in search properly
when the search term appears in both the comment and the card description
2025-11-19 18:02:36 -05:00

44 lines
2.0 KiB
Ruby

require "test_helper"
class SearchesControllerTest < ActionDispatch::IntegrationTest
include SearchTestHelper
setup do
@board.update!(all_access: true)
@card = @board.cards.create!(title: "Layout is broken", description: "Look at this mess.", creator: @user)
@comment_card = @board.cards.create!(title: "Some card", creator: @user)
@comment_card.comments.create!(body: "overflowing text issue", creator: @user)
@comment2_card = @board.cards.create!(title: "Just haggis", description: "More haggis", creator: @user)
@comment2_card.comments.create!(body: "I love haggis", creator: @user)
untenanted { sign_in_as @user }
end
test "search" do
# Searching by card title
get search_path(q: "broken", script_name: "/#{@account.external_account_id}")
assert_select "li .search__title", text: /Layout is broken/
assert_select "li .search__excerpt", text: /Look at this mess/
# Searching by comment
get search_path(q: "overflowing", script_name: "/#{@account.external_account_id}")
assert_select "li .search__title", text: /Some card/
assert_select "li .search__excerpt--comment", text: /overflowing text issue/
# Searching for a term that appears in a card and in a comment
get search_path(q: "haggis", script_name: "/#{@account.external_account_id}")
assert_select "li .search__title", text: /Just haggis/, count: 2 # card title shows up in two entries
assert_select "li .search__excerpt", text: /More haggis/ # one entry for the card description
assert_select "li .search__excerpt--comment", text: /I love haggis/ # one entry for the comment
# Searching by card id
get search_path(q: @card.id, script_name: "/#{@account.external_account_id}")
assert_select "form[data-controller='auto-submit']"
# Searching with non-existent card id
get search_path(q: "999999", script_name: "/#{@account.external_account_id}")
assert_select "form[data-controller='auto-submit']", count: 0
assert_select ".search__empty", text: "No matches"
end
end