Skip to content

Commit

Permalink
ProductLicense relies on ProductLicenseContent
Browse files Browse the repository at this point in the history
  • Loading branch information
imobachgs committed Feb 14, 2018
1 parent 8279fa6 commit 0cefcfa
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 37 deletions.
67 changes: 31 additions & 36 deletions src/lib/y2packager/widgets/product_license.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
require "yast"
require "cwm"
require "y2packager/widgets/product_license_confirmation"
require "y2packager/widgets/license_translations_button"
require "y2packager/widgets/product_license_content"

module Y2Packager
module Widgets
Expand Down Expand Up @@ -50,59 +52,52 @@ def label
def contents
VBox(
Left(Label(_("License Agreement"))),
license_content,
confirmation_checkbox
product_license_content,
VSpacing(0.5),
HBox(
confirmation_checkbox,
HStretch(),
translations_button
)
)
end

# Translate the license content to the given language
#
# @param language [String] Language code (en_US, de_DE, etc.).
def translate(new_language)
self.language = new_language
product_license_content.translate(language)
end

private

# @return [String] Language code (en_US, es_ES, etc.).
attr_accessor :language

# Return the UI for the license content
# Widget containing the license translated to the language determined by #language
#
# @return [Yast::Term] UI for the license content
def license_content
MinWidth(
80,
RichText(Id(:license_content), formatted_license_text)
)
# @return [CWM::ProductLicenseContent]
def product_license_content
@product_license_content ||= ProductLicenseContent.new(product, language)
end

# Regexp to determine whether the text is formatted as richtext
RICHTEXT_REGEXP = /<\/.*>/

# Return the license text
#
# It detects whether license text is richtext or not and format it
# accordingly.
#
# @return [String] Formatted license text
def formatted_license_text
text = product.license(language)
if RICHTEXT_REGEXP =~ text
text
else
"<pre>#{CGI.escapeHTML(text)}</pre>"
end
end

# Return the UI for the confirmation checkbox
# Return the license confirmation widget if required
#
# It returns Empty() if confirmation is not needed.
#
# @return [Yast::Term] Product confirmation license widget or Empty() if
# confirmation is not needed.
# @return [Yast::Term,ProductLicenseConfirmation] Product confirmation license widget
# or Empty() if confirmation is not needed.
def confirmation_checkbox
return Empty() unless product.license_confirmation_required?
ProductLicenseConfirmation.new(product, skip_validation: skip_validation)
end

VBox(
VSpacing(0.5),
Left(
ProductLicenseConfirmation.new(product, skip_validation: skip_validation)
)
)
# Return the UI for the translation confirmation button
#
# @return [LicenseTranslationButton] License translations button
def translations_button
LicenseTranslationsButton.new(product)
end
end
end
Expand Down
18 changes: 17 additions & 1 deletion test/lib/widgets/product_license_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@
end

it "shows the license in the given language" do
expect(product).to receive(:license).with(language).and_return("de_DE license")
expect(Y2Packager::Widgets::ProductLicenseContent).to receive(:new)
.with(product, language).and_return("de_DE license")
expect(widget.contents.to_s).to include("de_DE license")
end

Expand Down Expand Up @@ -62,4 +63,19 @@
end
end
end

describe "#translate" do
let(:license_content) { instance_double(Y2Packager::Widgets::ProductLicenseContent) }

before do
allow(Y2Packager::Widgets::ProductLicenseContent).to receive(:new)
.and_return(license_content)
end

it "translate the license to the given language" do
widget.contents
expect(license_content).to receive(:translate).with("es_ES")
widget.translate("es_ES")
end
end
end

0 comments on commit 0cefcfa

Please sign in to comment.