Skip to content

Commit

Permalink
Display an error when a package is not found
Browse files Browse the repository at this point in the history
  • Loading branch information
imobachgs committed Jan 29, 2020
1 parent 295fe49 commit c1c7e12
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 2 deletions.
14 changes: 13 additions & 1 deletion src/lib/registration/clients/online_search.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
# find current contact information at www.suse.com.

require "yast"
require "yast2/popup"
require "registration/dialogs/online_search"
require "registration/addon"
require "registration/registration"
Expand Down Expand Up @@ -131,7 +132,7 @@ def register_addons
def select_packages
::Registration::SwMgmt.select_addon_products
package_search_dialog.selected_packages.each do |pkg|
Yast::Pkg.PkgInstall(pkg.name)
pkg_install_error_message(pkg.name) unless Yast::Pkg.PkgInstall(pkg.name)
end
:next
end
Expand Down Expand Up @@ -159,6 +160,17 @@ def selected_addons
def reset_selected_addons_cache!
@selected_addons = nil
end

def pkg_install_error_message(name)
Yast2::Popup.show(
format(
# TRANSLATORS: 'name' is the package's name
_("Package %{name} could not be selected for installation."),
name: name
),
headline: :error
)
end
end
end
end
14 changes: 13 additions & 1 deletion test/registration/clients/online_search_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
allow(Registration::SwMgmt).to receive(:select_addon_products)
allow(Registration::UrlHelpers).to receive(:registration_url)
.and_return("https://scc.suse.com") # speed up the test
allow(Yast::Pkg).to receive(:PkgInstall).and_return(true)
end

context "when an addon is selected" do
Expand Down Expand Up @@ -110,9 +111,20 @@

context "when a package is selected" do
it "selects the package for installation" do
expect(Yast::Pkg).to receive(:PkgInstall).with(package.name)
expect(Yast::Pkg).to receive(:PkgInstall).with(package.name).and_return(true)
subject.run
end

context "but the package is not found" do
before do
allow(Yast::Pkg).to receive(:PkgInstall).and_return(false)
end

it "warns the user" do
expect(Yast2::Popup).to receive(:show).with(/could not be selected/, headline: :error)
subject.run
end
end
end

context "when the user aborts the search" do
Expand Down

0 comments on commit c1c7e12

Please sign in to comment.