Skip to content

Commit

Permalink
testcases
Browse files Browse the repository at this point in the history
  • Loading branch information
schubi2 committed Apr 4, 2018
1 parent e787c0c commit f2e6f27
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 10 deletions.
7 changes: 5 additions & 2 deletions src/lib/installation/inst_confirm.rb
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,10 @@ def run(show_license = false)
)
when :ok
# Check whether the license has been accepted only if required
if license_required? && !InstData.product_license_accepted
if show_license &&
license_required? &&
!InstData.product_license_accepted

warn_license_required
next
end
Expand All @@ -128,7 +131,7 @@ def run(show_license = false)
# @param confirm_button_label [String] button layout install/update
# @return [Yast::Term] layout
def layout_without_license(heading, body, confirm_button_label)
display_info = UI.GetDisplayInfo
display_info = UI.GetDisplayInfo || {}
size_x = display_info["Width"] || 800
size_y = display_info["Height"] || 600

Expand Down
64 changes: 56 additions & 8 deletions test/lib/inst_confirm_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,27 +9,75 @@
describe "#run" do
before do
allow(Yast::Pkg).to receive(:SourceGetCurrent).and_return([])
allow(Yast::ProductLicense).to receive(:info_seen!).with(0)
allow(Yast::Storage).to receive(:GetCommitInfos).and_return([{:destructive => true}])
end

context "Installation mode" do
context "installation mode" do
before do
allow(Yast::Mode).to receive(:update).and_return(false)
expect(Yast::Label).to receive(:InstallButton)
end

context "data is already on disk" do
it "reports delete warning" do
expect(Yast::Storage).to receive(:GetCommitInfos).and_return([{:destructive => true}])
confirm.run(false)
end
end
context "no license confirmation UI" do
it "returns true if the user clicks ok" do
expect(Yast::UI).to receive(:UserInput).and_return(:ok)
expect(confirm.run(false)).to eq(true)
end

it "returns false if the user clicks abort" do
expect(Yast::UI).to receive(:UserInput).and_return(:abort)
expect(confirm.run(false)).to eq(false)
end
end

context "license confirmation UI" do
before do
expect(Yast::ProductLicense).to receive(:AcceptanceNeeded).and_return(true)
expect(Yast::ProductLicense).to receive(:ShowLicenseInInstallation).with(
:base_license_rp, 0)
end

context "user clicks ok" do
before do
expect(Yast::UI).to receive(:UserInput).and_return(:ok)
end

it "returns true if the user has accepted license" do
allow(Yast::InstData).to receive(:product_license_accepted).and_return(true)
expect(confirm.run(true)).to eq(true)
end
end

context "user clicks abort" do
before do
expect(Yast::UI).to receive(:UserInput).and_return(:abort)
end

it "returns false if the user has not accepted license" do
allow(Yast::InstData).to receive(:product_license_accepted).and_return(false)
expect(confirm.run(true)).to eq(false)
end

it "returns false even if the user has accepted license" do
allow(Yast::InstData).to receive(:product_license_accepted).and_return(true)
expect(confirm.run(true)).to eq(false)
end
end
end

end

context "Update mode" do
context "update mode" do
before do
allow(Yast::Mode).to receive(:update).and_return(true)
end

it "shows the upgrade button" do
expect(Yast::Label).not_to receive(:InstallButton)
expect(Yast::UI).to receive(:UserInput).and_return(:ok)
expect(confirm.run(false)).to eq(true)
end
end
end
end

0 comments on commit f2e6f27

Please sign in to comment.