Skip to content

Commit

Permalink
The OnlineSearch injects the controller into its widget
Browse files Browse the repository at this point in the history
  • Loading branch information
imobachgs committed Jan 31, 2020
1 parent e8c9c9b commit a02bd2a
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 6 deletions.
12 changes: 10 additions & 2 deletions src/lib/registration/dialogs/online_search.rb
Expand Up @@ -19,6 +19,7 @@

require "yast"
require "cwm/dialog"
require "registration/controllers/package_search"
require "registration/widgets/package_search"

module Registration
Expand Down Expand Up @@ -57,7 +58,7 @@ def contents
# @macro seeAbstractWidget
def run
ret = super
@selected_packages = ret == :next ? package_search_widget.selected_packages : []
@selected_packages = ret == :next ? controller.selected_packages : []
ret
end

Expand All @@ -72,7 +73,14 @@ def back_button
#
# @return [Registration::Widgets::PackageSearch]
def package_search_widget
@package_search_widget ||= ::Registration::Widgets::PackageSearch.new
@package_search_widget ||= ::Registration::Widgets::PackageSearch.new(controller)
end

# Package search controller
#
# @return [Registration::Controllers::PackageSearch]
def controller
@controller ||= ::Registration::Controllers::PackageSearch.new
end
end
end
Expand Down
5 changes: 3 additions & 2 deletions src/lib/registration/widgets/package_search.rb
Expand Up @@ -19,7 +19,6 @@

require "yast"
require "cwm/custom_widget"
require "registration/controllers/package_search"
require "registration/widgets/package_search_form"
require "registration/widgets/remote_packages_table"
require "registration/widgets/remote_package_details"
Expand All @@ -40,7 +39,9 @@ class PackageSearch < CWM::CustomWidget
include Yast::Logger

# Constructor
def initialize(controller = ::Registration::Controllers::PackageSearch.new)
#
# @param controller [Registration::Controllers::PackageSearch] Package search controller
def initialize(controller)
textdomain "registration"
self.handle_all_events = true
@controller = controller
Expand Down
10 changes: 8 additions & 2 deletions test/registration/dialogs/online_search_test.rb
Expand Up @@ -26,7 +26,11 @@

describe "#selected_packages" do
let(:search_widget) do
Registration::Widgets::PackageSearch.new
Registration::Widgets::PackageSearch.new(controller)
end

let(:controller) do
Registration::Controllers::PackageSearch.new
end

let(:package) do
Expand All @@ -36,7 +40,9 @@
before do
allow(Registration::Widgets::PackageSearch).to receive(:new)
.and_return(search_widget)
allow(search_widget).to receive(:selected_packages).and_return([package])
allow(Registration::Controllers::PackageSearch).to receive(:new)
.and_return(controller)
allow(controller).to receive(:selected_packages).and_return([package])
allow(subject).to receive(:cwm_show).and_return(result)
end

Expand Down

0 comments on commit a02bd2a

Please sign in to comment.