Skip to content

Commit

Permalink
Fix "ignore case" behaviour
Browse files Browse the repository at this point in the history
  • Loading branch information
imobachgs committed Feb 6, 2020
1 parent 8edd364 commit 719f47b
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 10 deletions.
5 changes: 3 additions & 2 deletions src/lib/registration/controllers/package_search.rb
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,10 @@ def initialize
# Performs a package search
#
# @param text [String] Term to search for
# @param ignore_case [Boolean] Whether the search is case sensitive or not
# @return [Array<Registration::RemotePackage>] List of packages
def search(text)
@search = ::Registration::PackageSearch.new(text: text)
def search(text, ignore_case)
@search = ::Registration::PackageSearch.new(text: text, ignore_case: ignore_case)
@search.packages
end

Expand Down
9 changes: 5 additions & 4 deletions src/lib/registration/widgets/package_search.rb
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ def contents
# @macro seeAbstractWidget
def handle(event)
if start_search_event?(event)
search_package(search_form.text)
search_package(search_form.text, search_form.ignore_case)
elsif event["WidgetID"] == "remote_packages_table"
handle_packages_table_event(event)
end
Expand Down Expand Up @@ -139,12 +139,13 @@ def start_search_event?(event)

# Performs the search and updates the packages table
#
# @param text [String] Text to search for
def search_package(text)
# @param text [String] Text to search for
# @param ignore_case [Boolean] Whether the search is case sensitive or not
def search_package(text, ignore_case)
return unless valid_search_text?(text)
# TRANSLATORS: searching for packages
Yast::Popup.Feedback(_("Searching..."), _("Searching for packages")) do
@packages = controller.search(text)
@packages = controller.search(text, ignore_case)
selected_package_ids = controller.selected_packages.map(&:id)
@packages.each do |pkg|
pkg.select! if selected_package_ids.include?(pkg.id)
Expand Down
6 changes: 4 additions & 2 deletions test/registration/controllers/package_search_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -45,14 +45,16 @@

let(:text) { "gnome" }

let(:ignore_case) { true }

before do
allow(Registration::PackageSearch).to receive(:new)
.with(text: text).and_return(search)
.with(text: text, ignore_case: ignore_case).and_return(search)
end

describe "#search" do
it "returns the list of packages from SCC" do
expect(controller.search(text)).to eq([package])
expect(controller.search(text, ignore_case)).to eq([package])
end
end

Expand Down
5 changes: 3 additions & 2 deletions test/registration/widgets/package_search_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -68,12 +68,13 @@

describe "#handle" do
let(:text) { "gnome" }
let(:ignore_case) { true }

context "when the user asks for a package" do
let(:event) { { "WidgetID" => "search_form_button" } }

let(:search_form) do
instance_double(Registration::Widgets::PackageSearchForm, text: text)
instance_double(Registration::Widgets::PackageSearchForm, text: text, ignore_case: ignore_case)
end

before do
Expand All @@ -82,7 +83,7 @@
end

it "searches for the package in SCC" do
expect(controller).to receive(:search).with(text)
expect(controller).to receive(:search).with(text, ignore_case)
subject.handle(event)
end

Expand Down

0 comments on commit 719f47b

Please sign in to comment.