Skip to content

Commit

Permalink
Display a confirmation popup when no add-on is selected (bsc#1062356)
Browse files Browse the repository at this point in the history
...from a multi-repository medium

- 4.0.11
  • Loading branch information
lslezak committed Oct 16, 2017
1 parent fcf73f5 commit 83206f3
Show file tree
Hide file tree
Showing 4 changed files with 111 additions and 2 deletions.
7 changes: 7 additions & 0 deletions package/yast2-packager.changes
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
-------------------------------------------------------------------
Mon Oct 16 07:41:53 UTC 2017 - lslezak@suse.cz

- Display a confirmation popup when no add-on is selected from
a multi-repository medium (bsc#1062356)
- 4.0.11

-------------------------------------------------------------------
Thu Oct 12 08:55:58 UTC 2017 - lslezak@suse.cz

Expand Down
4 changes: 2 additions & 2 deletions package/yast2-packager.spec
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,13 @@


Name: yast2-packager
Version: 4.0.10
Version: 4.0.11
Release: 0

BuildRoot: %{_tmppath}/%{name}-%{version}-build
Source0: %{name}-%{version}.tar.bz2

Url: https://github.com/kobliha/yast-packager
Url: https://github.com/yast/yast-packager
BuildRequires: update-desktop-files
BuildRequires: yast2-devtools >= 3.1.10
BuildRequires: rubygem(rspec)
Expand Down
12 changes: 12 additions & 0 deletions src/lib/y2packager/dialogs/addon_selector.rb
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,9 @@ def initialize(products)
# This action happens when the user clicks the 'Next' button
def next_handler
read_user_selection

return if selected_products.empty? && !Yast::Popup.ContinueCancel(continue_msg)

finish_dialog(:next)
end

Expand Down Expand Up @@ -109,6 +112,15 @@ def dialog_title
# TODO: does it make sense also for the 3rd party addons?
_("Extension and Module Selection")
end

# A message for asking the user whether to continue without adding any addon.
#
# @return [String] translated message
def continue_msg
# TRANSLATORS: Popup with [Continue] [Cancel] buttons
_("No product has been selected.\n\n" \
"Do you really want to continue without adding any product?")
end
end
end
end
90 changes: 90 additions & 0 deletions test/addon_selector_test.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
#! /usr/bin/env rspec

require_relative "./test_helper"

require "y2packager/product_location"
require "y2packager/dialogs/addon_selector"

describe Y2Packager::Dialogs::AddonSelector do
let(:media_products) do
prods = [["SLE-15-Module-Basesystem 15.0-0", "/Basesystem"],
["SLE-15-Module-Legacy 15.0-0", "/Legacy"]]
prods.map { |r| Y2Packager::ProductLocation.new(r[0], r[1]) }
end

subject { described_class.new(media_products) }

describe "#help_text" do
it "returns a String" do
expect(subject.help_text).to be_a(String)
end
end

describe "#abort_handler" do
it "returns :abort" do
allow(Yast::Stage).to receive(:initial).and_return(false)
expect(subject.abort_handler).to eq(:abort)
end

context "in installation" do
before do
expect(Yast::Stage).to receive(:initial).and_return(true)
end

it "asks for confirmation" do
expect(Yast::Popup).to receive(:ConfirmAbort).and_return(true)
subject.abort_handler
end

it "returns :abort when confirmed" do
expect(Yast::Popup).to receive(:ConfirmAbort).and_return(true)
expect(subject.abort_handler).to eq(:abort)
end

it "returns nil when not confirmed" do
expect(Yast::Popup).to receive(:ConfirmAbort).and_return(false)
expect(subject.abort_handler).to be_nil
end
end
end

describe "#next_handler" do
context "an addon is selected" do
before do
expect(Yast::UI).to receive(:QueryWidget).with(Id("addon_repos"), :SelectedItems)
.and_return(["SLE-15-Module-Basesystem 15.0-0"])
end

it "returns :next if an addon is selected" do
expect(subject.next_handler).to eq(:next)
end

it "does not display any popup" do
expect(Yast::Popup).to_not receive(:anything)
subject.next_handler
end
end

context "no addon is selected" do
before do
expect(Yast::UI).to receive(:QueryWidget).with(Id("addon_repos"), :SelectedItems)
.and_return([])
end

it "displays a popup asking for confirmation" do
expect(Yast::Popup).to receive(:ContinueCancel).with(/no add-on/i)
subject.next_handler
end

it "returns :next if the popup is confirmed" do
expect(Yast::Popup).to receive(:ContinueCancel).with(/no add-on/i).and_return(true)
expect(subject.next_handler).to eq(:next)
end

it "returns nil if the popup is not confirmed" do
expect(Yast::Popup).to receive(:ContinueCancel).with(/no add-on/i).and_return(false)
expect(subject.next_handler).to be_nil
end
end
end
end

0 comments on commit 83206f3

Please sign in to comment.