Skip to content

Commit

Permalink
Do not perform an online search when the text is not enough
Browse files Browse the repository at this point in the history
  • Loading branch information
imobachgs committed Jan 27, 2020
1 parent 988727a commit 1a6af8c
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 2 deletions.
19 changes: 19 additions & 0 deletions src/lib/registration/widgets/package_search.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
require "registration/widgets/remote_packages_table"
require "registration/widgets/remote_package_details"
require "registration/package_search"
require "yast2/popup"

Yast.import "Popup"

Expand Down Expand Up @@ -138,6 +139,7 @@ def start_search_event?(event)
#
# @param text [String] Text to search for
def search_package(text)
return unless valid_search_text?(text)
@search = ::Registration::PackageSearch.new(text: text)
# TRANSLATORS: searching for packages
Yast::Popup.Feedback(_("Searching..."), _("Searching for packages")) do
Expand Down Expand Up @@ -228,6 +230,23 @@ def disable_addon?(addon)
Yast::Popup.YesNo(message)
end

MINIMAL_SEARCH_TEXT_SIZE = 2

# Determines whether the search text is valid or not
#
# @param text [String] Text to search for
def valid_search_text?(text)
return true if text.to_s.size >= MINIMAL_SEARCH_TEXT_SIZE
Yast2::Popup.show(
format(
# TRANSLATORS: the minimal size of the text to search for package names
_("Please, type at least %{minimal_size} characters to search for."),
minimal_size: MINIMAL_SEARCH_TEXT_SIZE
)
)
false
end

# Determines whether the addon is still needed
def needed_addon?(addon)
selected_packages.any? { |pkg| pkg.addon == addon }
Expand Down
15 changes: 13 additions & 2 deletions test/registration/widgets/package_search_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -66,9 +66,10 @@
describe "#handle" do
context "when the user asks for a package" do
let(:event) { { "WidgetID" => "search_form_button" } }
let(:text) { "gnome" }

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

before do
Expand All @@ -79,7 +80,7 @@

it "searches for the package in SCC" do
expect(Registration::PackageSearch).to receive(:new)
.with(text: "gnome").and_return(search)
.with(text: text).and_return(search)
subject.handle(event)
end

Expand All @@ -88,6 +89,16 @@
expect(package_details).to receive(:update).with(package)
subject.handle(event)
end

context "when the search text is not enough" do
let(:text) { "g" }

it "asks the user to introduce some text" do
expect(Yast2::Popup).to receive(:show)
.with(/at least/)
subject.handle(event)
end
end
end

context "when a package is selected for installation" do
Expand Down

0 comments on commit 1a6af8c

Please sign in to comment.