Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add tests for addon selection dialogs and bunch of small fixes
- Loading branch information
1 parent
11282af
commit 0d5d7fe
Showing
5 changed files
with
96 additions
and
57 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
require_relative "spec_helper" | ||
require "registration/ui/addon_selection_dialog" | ||
|
||
describe Registration::UI::AddonSelectionDialog do | ||
subject { Registration::UI::AddonSelectionDialog } | ||
|
||
before(:each) do | ||
# generic UI stubs for the wizard dialog | ||
stub_const("Yast::UI", double()) | ||
allow(Yast::UI).to receive(:WizardCommand) | ||
allow(Yast::UI).to receive(:WidgetExists).and_return(true) | ||
allow(Yast::UI).to receive(:ChangeWidget) | ||
allow(Yast::UI).to receive(:SetFocus) | ||
allow(Yast::UI).to receive(:ReplaceWidget) | ||
allow(Yast::UI).to receive(:TextMode).and_return(false) | ||
|
||
addon_reset_cache | ||
end | ||
|
||
describe ".run" do | ||
it "returns response from addon selection according to pressed button" do | ||
expect(Yast::UI).to receive(:UserInput).and_return(:abort) | ||
registration = double(:get_addon_list => []) | ||
expect(subject.run(registration)).to eq :abort | ||
end | ||
|
||
it "returns `:skip` if no addon is selected and user click next" do | ||
expect(Yast::UI).to receive(:UserInput).and_return(:next) | ||
registration = double(:get_addon_list => []) | ||
expect(subject.run(registration)).to eq :skip | ||
end | ||
|
||
it "returns `:next` if some addons are selected and user click next" do | ||
test_addon = addon_generator | ||
expect(Yast::UI).to receive(:UserInput).and_return(test_addon.product_ident, :next) | ||
# mock that widget is selected | ||
expect(Yast::UI).to receive(:QueryWidget). | ||
with(Yast::Term.new(:id, test_addon.product_ident), :Value). | ||
and_return(true) | ||
registration = double(:get_addon_list => [test_addon]) | ||
expect(subject.run(registration)).to eq :next | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
require "registration/addon" | ||
require "suse/connect" | ||
|
||
def suse_connect_product_generator(attrs={}) | ||
params = {} | ||
params['name'] = attrs['name'] || "Product#{rand(100000)}" | ||
params['long_name'] = attrs['long_name'] || "The best cool #{params['name']}" | ||
params['description'] = attrs['description'] || "Bla bla bla bla!" | ||
params['zypper_name'] = attrs['zypper_name'] || "prod#{rand(100000)}" | ||
params['zypper_version'] = attrs['version'] || "#{rand(13)}" | ||
params['arch'] = attrs['arch'] || "x86_64" | ||
params['free'] = attrs.fetch('free', true) | ||
params['eula_url'] = attrs['eula_url'] | ||
params["extensions"] = attrs['extensions'] || [] | ||
|
||
return params | ||
end | ||
|
||
def addon_generator(params={}) | ||
SUSE::Connect::Product.new(suse_connect_product_generator(params)) | ||
end | ||
|
||
def addon_with_child_generator(parent_params={}) | ||
prod_child = suse_connect_product_generator | ||
SUSE::Connect::Product.new(suse_connect_product_generator(parent_params.merge('extensions' => [prod_child]))) | ||
end | ||
|
||
# add cache reset, which is not needed in runtime, but for test it is critical | ||
class Registration::Addon | ||
class << self | ||
def reset_cache | ||
@cached_addons = nil | ||
@registereds = nil | ||
@selecteds = nil | ||
end | ||
end | ||
end | ||
|
||
def addon_reset_cache | ||
Registration::Addon.reset_cache | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters