From c51836515c9e38b4a36f6011cf6f17f5d2de8074 Mon Sep 17 00:00:00 2001 From: Henrique <45046146+hmdros@users.noreply.github.com> Date: Wed, 27 Sep 2023 09:27:57 -0300 Subject: [PATCH] DT-244 show ID in row - filter by id (#301) * DT-244 show ID in row - filter by id * Add replace to remove string 'story' from ID value * Update label tag * Add spec case to fill search input and filter elements * DT-244 Spec clause to ensure only 1 row render --- app/assets/javascripts/project.js | 2 +- app/views/projects/show.html.erb | 4 ++-- spec/features/stories_manage_spec.rb | 21 +++++++++++++++++++++ 3 files changed, 24 insertions(+), 3 deletions(-) diff --git a/app/assets/javascripts/project.js b/app/assets/javascripts/project.js index bdfe2dbe..e8eae375 100644 --- a/app/assets/javascripts/project.js +++ b/app/assets/javascripts/project.js @@ -105,7 +105,7 @@ const filterStories = () => { const storyTitle = element .querySelector("td:first-child") .innerText.toLowerCase(); - if (storyTitle.includes(searchTerm)) { + if (storyTitle.includes(searchTerm) || element.id.replace(/\D/g, '').includes(searchTerm)) { cl.remove("hidden"); } else { cl.add("hidden"); diff --git a/app/views/projects/show.html.erb b/app/views/projects/show.html.erb index c6555974..1bb4c6bb 100644 --- a/app/views/projects/show.html.erb +++ b/app/views/projects/show.html.erb @@ -3,7 +3,7 @@

<%= render partial: "shared/project_title", locals: {allow_edit: true, project: @project} %>

- <%= label_tag 'title_contains', "Filter by title" %> + <%= label_tag 'title_contains', "Filter by title or ID" %> <%= search_field_tag 'title_contains', nil, onkeyup: "filterStories()" %>
@@ -28,7 +28,7 @@ - <%= link_to story.title, [story.project, story] %> + <%= link_to "#{story.id} - #{story.title}", [story.project, story] %> <%= story.estimate_for(current_user)&.best_case_points %> diff --git a/spec/features/stories_manage_spec.rb b/spec/features/stories_manage_spec.rb index 6a327295..a5e1a783 100644 --- a/spec/features/stories_manage_spec.rb +++ b/spec/features/stories_manage_spec.rb @@ -318,4 +318,25 @@ expect(page).not_to have_selector(".project-table.sorting") end + + it "filter stories by title or ID", js: true do + story4 = FactoryBot.create(:story, project: project, title: "Deprecation warning XYZ") + story5 = FactoryBot.create(:story, project: project, title: "Dangerous query method") + + visit project_path(id: project.id) + + fill_in "title_contains", with: "XYZ" + + within("#stories") do + expect(find("td:nth-child(1)")).to have_text story4.title + expect(all("#stories > tr").count).to eq(1) + end + + fill_in "title_contains", with: story5.id + + within("#stories") do + expect(find("td:nth-child(1)")).to have_text story5.title + expect(all("#stories > tr").count).to eq(1) + end + end end