Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #157 from yast/sort_addons
Sort displayed addons (bnc#888567)
- Loading branch information
Showing
14 changed files
with
610 additions
and
181 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
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
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,30 @@ | ||
|
||
module Registration | ||
|
||
# Sorter for sorting Addons in required display order | ||
# (first paid extensions, then free extensions, modules at the end | ||
# see https://bugzilla.novell.com/show_bug.cgi?id=888567#c21) | ||
ADDON_SORTER = Proc.new do |x, y| | ||
if x.product_type != y.product_type | ||
begin | ||
# if empty or nil move at the end | ||
if !x.product_type || x.product_type.empty? | ||
1 | ||
elsif !y.product_type || y.product_type.empty? | ||
-1 | ||
else | ||
# simplification: "extension" is lexicographically before "module" | ||
# as requested in the display order so take advantage of this... | ||
x.product_type <=> y.product_type | ||
end | ||
end | ||
elsif x.free != y.free | ||
# paid (non-free) first | ||
x.free ? 1 : -1 | ||
else | ||
# sort the groups by name | ||
x.name <=> y.name | ||
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
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,30 @@ | ||
#! /usr/bin/env rspec | ||
|
||
require_relative "spec_helper" | ||
|
||
require "yaml" | ||
require "registration/addon" | ||
require "registration/addon_sorter" | ||
|
||
describe "Registration::ADDON_SORTER" do | ||
let(:available_addons) { YAML.load_file(fixtures_file("available_addons.yml")) } | ||
let(:unknown_addons) { YAML.load_file(fixtures_file("available_unknown_addons.yml")) } | ||
|
||
it "sorts the addons in display order" do | ||
expected = ["sle-ha", "sle-ha-geo", "sle-sdk", "sle-we", | ||
"sle-module-adv-systems-management", "sle-module-legacy", | ||
"sle-module-public-cloud", "sle-module-web-scripting"] | ||
|
||
expect(available_addons.sort(&Registration::ADDON_SORTER).map(&:identifier)).to eql(expected) | ||
end | ||
|
||
it "moves the unknown product types at the end" do | ||
# AdvMgmt and Legacy have undefined type => at the end | ||
expected = ["sle-sdk", "sle-we", "sle-module-public-cloud", | ||
"sle-module-web-scripting", "sle-module-legacy", | ||
"sle-module-adv-systems-management"] | ||
|
||
expect(unknown_addons.sort(&Registration::ADDON_SORTER).map(&:identifier)).to eql(expected) | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
#! /usr/bin/env rspec | ||
|
||
require_relative "spec_helper" | ||
|
||
require "registration/exceptions" | ||
|
||
describe Registration::ServiceError do | ||
|
||
it "is a PkgError exception" do | ||
expect(Registration::ServiceError.new("failed", "ServiceFoo")).to be_a(Registration::PkgError) | ||
end | ||
|
||
end |
Oops, something went wrong.