Skip to content

Commit

Permalink
Add unit tests for InstProductLicense client
Browse files Browse the repository at this point in the history
  • Loading branch information
imobachgs committed Aug 21, 2017
1 parent 310e052 commit 8e687d1
Show file tree
Hide file tree
Showing 2 changed files with 64 additions and 3 deletions.
7 changes: 4 additions & 3 deletions src/lib/y2packager/clients/inst_product_license.rb
Expand Up @@ -16,14 +16,15 @@

module Y2Packager
module Clients
# This client shows a license confirmation dialog for the base selected product
class InstProductLicense
def main
dialog = Y2Packager::Dialogs::InstProductLicense.new(selected_product)
dialog.run
return :next unless selected_product.license?
Y2Packager::Dialogs::InstProductLicense.new(selected_product).run
end

def selected_product
@selected_product ||= Y2Packager::Product.available_base_products.find(&:selected?)
@selected_product ||= Y2Packager::Product.selected_base
end
end
end
Expand Down
60 changes: 60 additions & 0 deletions test/lib/clients/inst_product_license_test.rb
@@ -0,0 +1,60 @@
#!/usr/bin/env rspec

require_relative "../../test_helper"
require "y2packager/clients/inst_product_license"

describe Y2Packager::Clients::InstProductLicense do
subject(:client) { described_class.new }

let(:dialog) { instance_double(Y2Packager::Dialogs::InstProductLicense, run: :next) }
let(:product) { instance_double(Y2Packager::Product, license?: license?) }
let(:license?) { true }

before do
allow(Y2Packager::Dialogs::InstProductLicense).to receive(:new)
.and_return(dialog)
allow(Y2Packager::Product).to receive(:selected_base).and_return(product)
end

describe "#main" do
it "opens the license dialog with the selected product" do
expect(Y2Packager::Dialogs::InstProductLicense).to receive(:new)
.with(product)
client.main
end

context "when the user accepts the license" do
before do
allow(dialog).to receive(:run).and_return(:next)
end

it "returns :next" do
expect(client.main).to eq(:next)
end
end

context "when the user clicks the 'Back' button" do
before do
allow(dialog).to receive(:run).and_return(:back)
end

it "returns :back" do
expect(client.main).to eq(:back)
end
end

context "when no license is found for the selected base product" do
let(:license?) { false }

it "does not open the license dialog" do
expect(Y2Packager::Dialogs::InstProductLicense).to_not receive(:new)
.with(product)
client.main
end

it "returns :next" do
expect(client.main).to eq(:next)
end
end
end
end

0 comments on commit 8e687d1

Please sign in to comment.