Skip to content

Commit

Permalink
Improve dialog shown when system is already resgistered
Browse files Browse the repository at this point in the history
* Disable the "Register Again" button if the system cannot be
  re-registered.
* Adapt the help text display according the status of available actions.
  I.e, does not state "You can re-register" when the system cannot be
  re-registered.
* Add unit test.
  • Loading branch information
dgdavid committed Mar 5, 2021
1 parent 8b48c98 commit a0cb45e
Show file tree
Hide file tree
Showing 3 changed files with 218 additions and 24 deletions.
5 changes: 4 additions & 1 deletion src/lib/registration/clients/inst_scc.rb
Expand Up @@ -230,13 +230,16 @@ def registration_check
return :cancel if init_registration == :cancel

extensions_enabled = true

success = Registration::ConnectHelpers.catch_registration_errors do
extensions_enabled = !Registration::Addon.find_all(@registration).empty?
end

return :abort unless success

::Registration::UI::RegisteredSystemDialog.run(
extensions_enabled: extensions_enabled
extensions: extensions_enabled,
registration: ::Registration::Registration.allowed?
)
end

Expand Down
83 changes: 60 additions & 23 deletions src/lib/registration/ui/registered_system_dialog.rb
Expand Up @@ -17,46 +17,46 @@ class RegisteredSystemDialog
Yast.import "Label"
Yast.import "UI"

# displays and run the status dialog for an already registered system
# Displays and run the status dialog for an already registered system
#
# @param extensions [Boolean] Whether "Select extensions" button shoudl be enabled
# @param registration [Boolean] Whether the "Register Again" button should be enabled
#
# @param extensions_enabled [Boolean] select extension button enabled
# @return [Symbol] user input
def self.run(extensions_enabled: true)
dialog = RegisteredSystemDialog.new
dialog.run(extensions_enabled: extensions_enabled)
def self.run(extensions: true, registration: true)
RegisteredSystemDialog.new(extensions: extensions, registration: registration).run
end

# the constructor
def initialize
# Constructor
#
# @param extensions [Boolean] Whether "Select extensions" button shoudl be enabled
# @param registration [Boolean] Whether the "Register Again" button should be enabled
def initialize(extensions: true, registration: true)
textdomain "registration"

@extensions = extensions
@registration = registration
end

# display and run the dialog
# Display and run the dialog
#
# @param extensions_enabled [Boolean] select extension button enabled
# @return [Symbol] user input
def run(extensions_enabled: true)
def run
Wizard.SetContents(
# dialog title
_("Registration"),
dialog_content,
# help text
_("<p>The system is already registered.</p>") +
_("<p>You can re-register it again or you can register additional "\
"extension or modules to enhance the functionality of the system.</p>") +
_("<p>If you want to deregister your system you need to log "\
"into the SUSE Customer Center and remove the system manually there.</p>"),
help_text,
true,
true
)

Yast::UI.ChangeWidget(Id(:extensions), :Enabled, extensions_enabled)
Yast::UI.ChangeWidget(Id(:extensions), :Enabled, extensions)
Yast::UI.ChangeWidget(Id(:register), :Enabled, registration)
Wizard.SetNextButton(:next, Label.FinishButton) if Mode.normal

continue_buttons = [:next, :back, :cancel, :abort, :register, :extensions]

ret = nil
ret = Yast::UI.UserInput until continue_buttons.include?(ret)
ret = Yast::UI.UserInput until available_actions.include?(ret)

Wizard.RestoreNextButton

Expand All @@ -65,19 +65,56 @@ def run(extensions_enabled: true)

private

# the main dialog content
attr_reader :extensions, :registration

# Available dialog actions
#
# @returns [Symbol]
def available_actions
[:next, :back, :cancel, :abort, :register, :extensions]
end

# The dialog content
#
# @return [Yast::Term] UI term
def dialog_content
VBox(
Heading(_("The system is already registered.")),
VSpacing(2),
# button label
PushButton(Id(:extensions), _("Select Extensions")),
VSpacing(1),
# button label
PushButton(Id(:register), _("Register Again"))
)
end

# The dialog's help text
#
# @return [String]
def help_text
text = [_("<p>The system is already registered.</p>")]
text << actions_help
text << _("<p>If you want to deregister your system you need to log "\
"into the SUSE Customer Center and remove the system manually there.</p>")
text.join
end

# The help text for enabled actions
#
# @return [String]
def actions_help
if extensions && registration
_("<p>You can re-register it again or register additional "\
"extension or modules to enhance the functionality of the system.</p>")
elsif extensions
_("<p>You can register additional extension or modules "\
"to enhance the functionality of the system.</p>")
elsif registration
_("<p>You can re-register it again.")
else
_("<p>At this moment, you can neither re-register it again " \
"nor register additional extensions</p>")
end
end
end
end
end
154 changes: 154 additions & 0 deletions test/registration/ui/registered_system_dialog_test.rb
@@ -0,0 +1,154 @@
#!/usr/bin/env rspec
# ------------------------------------------------------------------------------
# Copyright (c) 2018 SUSE LLC, All Rights Reserved.
#
# This program is free software; you can redistribute it and/or modify it under
# the terms of version 2 of the GNU General Public License as published by the
# Free Software Foundation.
#
# This program is distributed in the hope that it will be useful, but WITHOUT
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
# FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
# ------------------------------------------------------------------------------

require_relative "../../spec_helper"
require "registration/ui/registered_system_dialog"

describe Registration::UI::RegisteredSystemDialog do
include Yast::UIShortcuts

subject(:dialog) { described_class.new(extensions: extensions, registration: registration) }

let(:extensions) { true }
let(:registration) { true }

describe ".run" do
let(:dialog) { double(Registration::UI::RegisteredSystemDialog, run: true) }

before do
allow(described_class).to receive(:new).and_return(dialog)
end

it "creates an instance of the dialog" do
expect(described_class).to receive(:new)

described_class.run
end

it "runs the dialog" do
expect(dialog).to receive(:run)

described_class.run
end
end

describe "#run" do
let(:mode) { "installation" }
let(:user_input) { :cancel }

before do
allow(Yast::Wizard).to receive(:SetContents)
allow(Yast::Wizard).to receive(:SetNextButton)
allow(Yast::Wizard).to receive(:RestoreNextButton)

allow(Yast::Mode).to receive(:mode).and_return(mode)

allow(Yast::UI).to receive(:ChangeWidget)
allow(Yast::UI).to receive(:UserInput).and_return(user_input)
end

it "returns the user input" do
expect(subject.run).to eq(:cancel)
end

it "does not change the next button label" do
expect(Yast::Wizard).to_not receive(:SetNextButton)
end

it "keeps 'Select Extensions' button enabled" do
expect(Yast::UI).to_not receive(:ChangeWidget).with(Id(:extensions), :Enabled, false)

subject.run
end

it "includes help for 'Select Extensions' button" do
expect(Yast::Wizard).to receive(:SetContents).with(
anything,
anything,
/register additional extension/,
any_args
)

subject.run
end

it "keeps 'Register Again' button enabled" do
expect(Yast::UI).to_not receive(:ChangeWidget).with(Id(:register), :Enabled, false)

subject.run
end

it "includes help for 'Register Again' button" do
expect(Yast::Wizard).to receive(:SetContents).with(
anything,
anything,
/re-register it again/,
any_args
)

subject.run
end

context "when running in normal mode" do
let(:mode) { "normal" }

it "changes the next button label" do
expect(Yast::Wizard).to receive(:SetNextButton)

subject.run
end
end

context "when extensions are not enabled" do
let(:extensions) { false }

it "disables 'Select Extensions' button" do
expect(Yast::UI).to receive(:ChangeWidget).with(Id(:extensions), :Enabled, false)

subject.run
end

it "does not include help for it" do
expect(Yast::Wizard).to_not receive(:SetContents).with(
anything,
anything,
/register additional extension/,
any_args
)

subject.run
end
end

context "when register is not enabled" do
let(:registration) { false }

it "disables 'Register Again' button" do
expect(Yast::UI).to receive(:ChangeWidget).with(Id(:register), :Enabled, false)

subject.run
end

it "does not include help for it" do
expect(Yast::Wizard).to_not receive(:SetContents).with(
anything,
anything,
/re-register it again/,
any_args
)

subject.run
end
end
end
end

0 comments on commit a0cb45e

Please sign in to comment.