From 83206f35057c61dc07deeab6f476b79d1de6d2b6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ladislav=20Slez=C3=A1k?= Date: Mon, 16 Oct 2017 13:05:36 +0200 Subject: [PATCH] Display a confirmation popup when no add-on is selected (bsc#1062356) ...from a multi-repository medium - 4.0.11 --- package/yast2-packager.changes | 7 ++ package/yast2-packager.spec | 4 +- src/lib/y2packager/dialogs/addon_selector.rb | 12 +++ test/addon_selector_test.rb | 90 ++++++++++++++++++++ 4 files changed, 111 insertions(+), 2 deletions(-) create mode 100644 test/addon_selector_test.rb diff --git a/package/yast2-packager.changes b/package/yast2-packager.changes index e5c1e7786..71c16cb75 100644 --- a/package/yast2-packager.changes +++ b/package/yast2-packager.changes @@ -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 diff --git a/package/yast2-packager.spec b/package/yast2-packager.spec index 5644d00f0..cf8cee89d 100644 --- a/package/yast2-packager.spec +++ b/package/yast2-packager.spec @@ -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) diff --git a/src/lib/y2packager/dialogs/addon_selector.rb b/src/lib/y2packager/dialogs/addon_selector.rb index ac608a086..2f3240e6d 100644 --- a/src/lib/y2packager/dialogs/addon_selector.rb +++ b/src/lib/y2packager/dialogs/addon_selector.rb @@ -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 @@ -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 diff --git a/test/addon_selector_test.rb b/test/addon_selector_test.rb new file mode 100644 index 000000000..616900ab1 --- /dev/null +++ b/test/addon_selector_test.rb @@ -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