diff --git a/library/packages/src/lib/packages/file_conflict_callbacks.rb b/library/packages/src/lib/packages/file_conflict_callbacks.rb index 11fde28d5..d2f805b7c 100644 --- a/library/packages/src/lib/packages/file_conflict_callbacks.rb +++ b/library/packages/src/lib/packages/file_conflict_callbacks.rb @@ -62,6 +62,10 @@ def register_file_conflict_callbacks nil end + def delayed_progress_popup + @@delayed_progress_popup ||= Yast::DelayedProgressPopup.new + end + # Handle the file conflict detection start callback. def start log.info "Starting the file conflict check..." @@ -71,7 +75,7 @@ def start if Yast::Mode.commandline Yast::CommandLine.PrintVerbose(label) else - @@delayed_progress_popup = Yast::DelayedProgressPopup.new(heading: label) + @@delayed_progress_popup ||= Yast::DelayedProgressPopup.new(heading: label) end end @@ -84,7 +88,7 @@ def progress(progress) if Yast::Mode.commandline Yast::CommandLine.PrintVerboseNoCR("#{Yast::PackageCallbacksClass::CLEAR_PROGRESS_TEXT}#{progress}%") else - @@delayed_progress_popup.progress(progress) + delayed_progress_popup.progress(progress) end ui = Yast::UI.PollInput unless Yast::Mode.commandline @@ -131,9 +135,10 @@ def report(excluded_packages, conflicts) # Handle the file conflict detection finish callback. def finish log.info "File conflict check finished" - return if Yast::Mode.commandline || @@delayed_progress_popup.nil? + return if Yast::Mode.commandline || @@delayed_progress_popup.nil? - @@delayed_progress_popup.progress.close + @@delayed_progress_popup.close + @@delayed_progress_popup = nil end # Construct the file conflicts dialog. diff --git a/library/packages/test/file_conflict_callbacks_test.rb b/library/packages/test/file_conflict_callbacks_test.rb index bd889488e..3978b762a 100755 --- a/library/packages/test/file_conflict_callbacks_test.rb +++ b/library/packages/test/file_conflict_callbacks_test.rb @@ -162,17 +162,8 @@ def CallbackFileConflictFinish(func) allow(Yast::Mode).to receive(:commandline).and_return(false) end - it "reuses the package installation progress" do - expect(Yast::UI).to receive(:WidgetExists).and_return(true) - expect(Yast::UI).to receive(:ChangeWidget).twice - - start_cb.call - end - - it "opens a new progress if installation progress was not displayed" do - expect(Yast::UI).to receive(:WidgetExists).and_return(false) - expect(Yast::Wizard).to receive(:CreateDialog) - expect(Yast::Progress).to receive(:Simple) + it "uses a delayed progress popup" do + expect(Yast::DelayedProgressPopup).to receive(:new) start_cb.call end @@ -180,6 +171,11 @@ def CallbackFileConflictFinish(func) end describe "the registered progress callback handler" do + let(:start_cb) do + Packages::FileConflictCallbacks.register + dummy_pkg.fc_start + end + let(:progress_cb) do Packages::FileConflictCallbacks.register dummy_pkg.fc_progress @@ -216,6 +212,13 @@ def CallbackFileConflictFinish(func) allow(Yast::Mode).to receive(:commandline).and_return(false) end + it "receives the progress call" do + expect_any_instance_of(Yast::DelayedProgressPopup).to receive(:progress) + + start_cb.call + progress_cb.call(progress) + end + it "returns false to abort if user clicks Abort" do expect(Yast::UI).to receive(:PollInput).and_return(:abort) @@ -233,20 +236,6 @@ def CallbackFileConflictFinish(func) expect(progress_cb.call(progress)).to eq(true) end - - it "uses the existing widget if package installation progress was displayed" do - expect(Yast::UI).to receive(:WidgetExists).and_return(true) - expect(Yast::UI).to receive(:ChangeWidget) - - progress_cb.call(progress) - end - - it "sets the progress if package installation progress was not displayed" do - expect(Yast::UI).to receive(:WidgetExists).and_return(false) - expect(Yast::Progress).to receive(:Step).with(progress) - - progress_cb.call(progress) - end end end @@ -357,6 +346,11 @@ def CallbackFileConflictFinish(func) end describe "the registered finish callback handler" do + let(:start_cb) do + Packages::FileConflictCallbacks.register + dummy_pkg.fc_start + end + let(:finish_cb) do Packages::FileConflictCallbacks.register dummy_pkg.fc_finish @@ -387,14 +381,12 @@ def CallbackFileConflictFinish(func) finish_cb.call end - it "closes progress if installation progress was not displayed" do - allow(Yast::UI).to receive(:WidgetExists).and_return(false) - expect(Yast::Wizard).to receive(:CloseDialog) - expect(Yast::Progress).to receive(:Finish) + it "closes the delayed progress popup" do + expect_any_instance_of(Yast::DelayedProgressPopup).to receive(:close) + start_cb.call finish_cb.call end - end end end