diff --git a/app/views/searches/_result.html.erb b/app/views/searches/_result.html.erb index 9463e9802..b2b131910 100644 --- a/app/views/searches/_result.html.erb +++ b/app/views/searches/_result.html.erb @@ -1,25 +1,21 @@
  • <%= link_to result.source, class: "search__result", data: { turbo_frame: "_top", action: "bar#reset" } do %> -
    -

    - # <%= result.card.number %> <%= result.card_title %> -

    +
    +

    + # <%= result.card.number %> <%= result.card_title %> +

    - <% if result.card_description.present? %> -
    - <%= result.card_description %> -
    - <% else - if result.comment_body.present? %> -
    - <%= avatar_preview_tag result.card.creator %> -
    - <%= result.comment_body %> -
    -
    - <% end %> - <% end %> -
    -
    <%= result.card.board.name %>
    + <% if result.comment.present? %> +
    + <%= avatar_preview_tag result.card.creator %> +
    <%= result.comment_body %>
    +
    + <% elsif result.card_id.present? %> +
    <%= result.card_description %>
    + <% end %> +
    +
    + <%= result.card.board.name %> +
    <% end %>
  • diff --git a/test/controllers/searches_controller_test.rb b/test/controllers/searches_controller_test.rb index 0cc0bceee..12c191567 100644 --- a/test/controllers/searches_controller_test.rb +++ b/test/controllers/searches_controller_test.rb @@ -5,9 +5,11 @@ class SearchesControllerTest < ActionDispatch::IntegrationTest setup do @board.update!(all_access: true) - @card = @board.cards.create!(title: "Layout is broken", creator: @user) + @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 @@ -15,11 +17,19 @@ class SearchesControllerTest < ActionDispatch::IntegrationTest test "search" do # Searching by card title get search_path(q: "broken", script_name: "/#{@account.external_account_id}") - assert_select "li", text: /Layout is broken/ + 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", text: /Some card/ + 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}")