Skip to content

Commit

Permalink
Skip the role selection dialog when there is only one
Browse files Browse the repository at this point in the history
Part of fate#324713
  • Loading branch information
dgdavid committed Sep 25, 2018
1 parent 82c6909 commit 8c74687
Show file tree
Hide file tree
Showing 2 changed files with 111 additions and 22 deletions.
58 changes: 38 additions & 20 deletions src/lib/installation/select_system_role.rb
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,10 @@ def run
direction = run_clients(clients, going_back: true)
# ... and only run the main dialog (super) if we are *still* going back
return direction unless direction == :back
elsif single_role?
# Apply the role and skip the dialog when there is only one (fate#324713)
clear_role
return select_role(roles.first.id)
end

super
Expand Down Expand Up @@ -92,26 +96,7 @@ def create_dialog
end

def next_handler
role_id = @selected_role_id

if role_id.nil? # no role selected (bsc#1078809)
# An Error popup
msg = _("Select one of the available roles to continue.")
Yast::Popup.Error(msg)
return
end

orig_role_id = self.class.original_role_id
if !orig_role_id.nil? && orig_role_id != role_id
# A Continue-Cancel popup
msg = _("Changing the system role may undo adjustments you may have done.")
return unless Yast::Popup.ContinueCancel(msg)
end
self.class.original_role_id = role_id

apply_role(SystemRole.find(role_id))

result = run_clients(additional_clients_for(role_id))
result = select_role(@selected_role_id)
# We show the main role dialog; but the additional clients have
# drawn over it, so draw it again and go back to input loop.
# create_dialog do not create new dialog if it already exist like in this
Expand Down Expand Up @@ -139,6 +124,39 @@ def handle_event(id)

private

# checks if there is only one role available
def single_role?
roles.size == 1
end

# Applies the role with given id and run its additional clients, if any
#
# @param role_id [Integer] The role to be applied
#
# @see run_clients
#
# @return [:next,:back,:abort] which direction the additional dialogs exited
def select_role(role_id)
if role_id.nil? # no role selected (bsc#1078809)
# An Error popup
msg = _("Select one of the available roles to continue.")
Yast::Popup.Error(msg)
return :back
end

orig_role_id = self.class.original_role_id
if !orig_role_id.nil? && orig_role_id != role_id
# A Continue-Cancel popup
msg = _("Changing the system role may undo adjustments you may have done.")
return :back unless Yast::Popup.ContinueCancel(msg)
end
self.class.original_role_id = role_id

apply_role(SystemRole.find(role_id))

run_clients(additional_clients_for(role_id))
end

# gets array of clients to run for given role
def additional_clients_for(role_id)
role = SystemRole.find(role_id)
Expand Down
75 changes: 73 additions & 2 deletions test/select_system_role_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
subject.class.original_role_id = nil

allow(Yast::ProductFeatures).to receive(:ClearOverlay)
allow(Yast::ProductFeatures).to receive(:SetOverlay) # .with
allow(Yast::ProductFeatures).to receive(:SetOverlay)
allow(Yast::Packages).to receive(:SelectSystemPatterns)
end

Expand All @@ -41,6 +41,77 @@
end
end

context "when single role is defined" do
let(:additional_dialogs) { "" }
let(:control_file_roles) do
[
{ "id" => "bar", "order" => "200",
"software" => { "desktop" => "knome" }, "additional_dialogs" => additional_dialogs }
]
end

before do
allow(Yast::ProductControl).to receive(:system_roles)
.and_return(control_file_roles)
allow(Yast::WFM).to receive(:CallFunction).and_return(:next)
end

it "does not display dialog" do
expect(Yast::Wizard).to_not receive(:SetContents)
expect(Yast::UI).to_not receive(:UserInput)
expect(Yast::UI).to_not receive(:QueryWidget)

subject.run
end

context "and going forward" do
before do
allow(Yast::UI).to receive(:UserInput).and_return(:next)
end

it "sets ProductFeatures" do
expect(Yast::ProductFeatures).to receive(:ClearOverlay)
expect(Yast::ProductFeatures).to receive(:SetOverlay)

subject.run
end
end

context "and going back" do
before do
subject.class.original_role_id = "bar"
allow(Yast::GetInstArgs).to receive(:going_back).and_return(true)
allow(Yast::UI).to receive(:UserInput).and_return(:back)
end

it "leaves ProductFeatures" do
expect(Yast::ProductFeatures).to receive(:ClearOverlay)
expect(Yast::ProductFeatures).to_not receive(:SetOverlay)

subject.run
end
end

context "and it contains additional dialogs" do
let(:additional_dialogs) { "a,b" }

it "shows the first dialog when going forward" do
expect(Yast::WFM).to receive(:CallFunction).with("a", anything).and_return(:next)

subject.run
end

it "shows the last dialog when going back" do
subject.class.original_role_id = "bar"

allow(Yast::GetInstArgs).to receive(:going_back).and_return(true)
expect(Yast::WFM).to receive(:CallFunction).with("b", anything).and_return(:next)

subject.run
end
end
end

context "when some roles are defined" do
let(:control_file_roles) do
[
Expand All @@ -61,7 +132,7 @@
.and_return("foo", :next)

expect(Yast::ProductFeatures).to receive(:ClearOverlay)
expect(Yast::ProductFeatures).to receive(:SetOverlay) # .with
expect(Yast::ProductFeatures).to receive(:SetOverlay)

expect(subject.run).to eq(:next)
end
Expand Down

0 comments on commit 8c74687

Please sign in to comment.