Skip to content

Commit

Permalink
Display dependencies when enabling an addon
Browse files Browse the repository at this point in the history
  • Loading branch information
imobachgs committed Jan 29, 2020
1 parent c1c7e12 commit 2d88bd7
Show file tree
Hide file tree
Showing 4 changed files with 74 additions and 15 deletions.
11 changes: 11 additions & 0 deletions src/lib/registration/addon.rb
Original file line number Diff line number Diff line change
Expand Up @@ -356,6 +356,17 @@ def eula_acceptance_needed?
!eula_url.to_s.strip.empty?
end

# Returns all the dependencies
#
# Includes all dependencies in a recursive way.
#
# @return [Array<Addon>]
def dependencies
return [] if depends_on.nil?

[depends_on] + depends_on.dependencies
end

def self.dump_addons
# dump the downloaded data to a file for easier debugging,
# avoid write failures when running as an unprivileged user (rspec tests)
Expand Down
39 changes: 32 additions & 7 deletions src/lib/registration/widgets/package_search.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
require "yast2/popup"

Yast.import "Popup"
Yast.import "HTML"

module Registration
module Widgets
Expand Down Expand Up @@ -248,24 +249,40 @@ def update_details
#
# @param addon [Addon] Addon to ask about
def enable_addon?(addon)
message = format(
_("'%{name}' module/extension is not enabled for this system.\n" \
"Do you want to enable it?"),
name: addon.name
description = Yast::HTML.Para(
format(
_("The selected package is provided by the '%{name}' module/extension, " \
"which is not enabled on this system yet."),
name: addon.name
)
)

unselected_deps = addon.dependencies.reject { |d| d.selected? || d.registered? }
if !unselected_deps.empty?
description << Yast::HTML.Para(
format(
_("Additionally, '%{name}' depends on the following modules/extensions:"),
name: addon.name
)
)
description << Yast::HTML.List(unselected_deps.map(&:name))
end
question = n_(
"Do you want to enable it?", "Do you want to enable them?", unselected_deps.size + 1
)
Yast::Popup.YesNo(message)
yes_no_popup(description + question)
end

# Asks the user to disable the addon
#
# @param addon [Addon] Addon to ask about
def disable_addon?(addon)
message = format(
_("'%{name}' module/extension is not needed anymore.\n" \
_("The '%{name}' module/extension is not needed anymore.\n" \
"Do you want to unselect it?"),
name: addon.name
)
Yast::Popup.YesNo(message)
yes_no_popup(message)
end

MINIMAL_SEARCH_TEXT_SIZE = 2
Expand All @@ -289,6 +306,14 @@ def valid_search_text?(text)
def needed_addon?(addon)
selected_packages.any? { |pkg| pkg.addon == addon }
end

# Asks a yes/no question
#
# @return [Boolean] true if the answer is affirmative; false otherwise
def yes_no_popup(message)
ret = Yast2::Popup.show(message, richtext: true, buttons: :yes_no)
ret == :yes
end
end
end
end
22 changes: 22 additions & 0 deletions test/addon_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -374,4 +374,26 @@
expect(addon.to_h).to be_a(Hash)
end
end

describe "#dependencies" do
let(:registration) do
instance_double(
Registration::Registration,
activated_products: load_yaml_fixture("activated_products.yml"),
get_addon_list: load_yaml_fixture("pure_addons.yml")
)
end

let(:addons) do
Registration::Addon.find_all(registration)
end

subject(:addon) do
addons.find { |a| a.identifier == "sle-ha-geo" }
end

it "returns all addon dependencies" do
expect(addon.dependencies.map(&:identifier)).to eq(["sle-ha"])
end
end
end
17 changes: 9 additions & 8 deletions test/registration/widgets/package_search_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@
end

it "unselects the package" do
allow(Yast2::Popup).to receive(:show).and_return(:yes)
expect(package).to receive(:unselect!)
subject.handle(event)
end
Expand All @@ -129,19 +130,18 @@
end

it "does not unselect the addon" do
expect(Yast::Popup).to_not receive(:YesNo)
expect(addon).to_not receive(:unselected)
subject.handle(event)
end
end

context "and the addon is not needed anymore" do
before do
allow(Yast::Popup).to receive(:YesNo).and_return(unselect?)
allow(Yast2::Popup).to receive(:show).and_return(unselect?)
end

context "and the user agrees to unselect it" do
let(:unselect?) { true }
let(:unselect?) { :yes }

it "unselects the addon" do
expect(addon).to receive(:unselected)
Expand All @@ -150,7 +150,7 @@
end

context "and the user wants to keep the addon" do
let(:unselect?) { false }
let(:unselect?) { :no }

it "does not unselect the addon" do
expect(addon).to_not receive(:unselected)
Expand All @@ -173,7 +173,7 @@

context "when the addon is not registered" do
before do
allow(Yast::Popup).to receive(:YesNo).and_return(register?)
allow(Yast2::Popup).to receive(:show).and_return(register?)
end

let(:addon) do
Expand All @@ -182,7 +182,7 @@
end

context "but the user accepts to register the addon" do
let(:register?) { true }
let(:register?) { :yes }

it "adds the package to the list of packages to install" do
subject.handle(event)
Expand All @@ -196,7 +196,7 @@
end

context "and the user refuses to register the addon" do
let(:register?) { false }
let(:register?) { :no }

it "does not add the package to the list of packages to install" do
subject.handle(event)
Expand All @@ -216,7 +216,7 @@
end

it "does not ask about registering the addon" do
expect(Yast::Popup).to_not receive(:YesNo)
expect(Yast2::Popup).to_not receive(:show)
subject.handle(event)
end

Expand All @@ -227,6 +227,7 @@
end

it "updates the table and the package details" do
allow(Yast2::Popup).to receive(:show)
expect(packages_table).to receive(:update_item).with(package)
expect(package_details).to receive(:update).with(package)
subject.handle(event)
Expand Down

0 comments on commit 2d88bd7

Please sign in to comment.