Skip to content

Commit

Permalink
Fixed unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
shundhammer committed Mar 31, 2022
1 parent d48398e commit 85d690a
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 34 deletions.
13 changes: 9 additions & 4 deletions library/packages/src/lib/packages/file_conflict_callbacks.rb
Expand Up @@ -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..."
Expand All @@ -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

Expand All @@ -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
Expand Down Expand Up @@ -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.
Expand Down
52 changes: 22 additions & 30 deletions library/packages/test/file_conflict_callbacks_test.rb
Expand Up @@ -162,24 +162,20 @@ 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
end
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
Expand Down Expand Up @@ -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)

Expand All @@ -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

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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

0 comments on commit 85d690a

Please sign in to comment.