-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
71 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
RSpec.describe ContentItem do | ||
describe "#initialize" do | ||
it "leaves ordered_related_items if set" do | ||
subject = described_class.new( | ||
{ | ||
"links" => { | ||
"ordered_related_items" => [1, 2], | ||
"suggested_ordered_related_items" => [3, 4], | ||
}, | ||
}, | ||
) | ||
|
||
expect(subject.to_h["links"]["ordered_related_items"]).to eq([1, 2]) | ||
end | ||
|
||
it "uses suggested_ordered_related_items if no ordered_related_items" do | ||
subject = described_class.new( | ||
{ | ||
"links" => { | ||
"suggested_ordered_related_items" => [3, 4], | ||
}, | ||
}, | ||
) | ||
|
||
expect(subject.to_h["links"]["ordered_related_items"]).to eq([3, 4]) | ||
end | ||
|
||
it "returns an empty set if neither key is set" do | ||
subject = described_class.new( | ||
{ | ||
"links" => {}, | ||
}, | ||
) | ||
|
||
expect(subject.to_h["links"]["ordered_related_items"]).to eq([]) | ||
end | ||
|
||
it "returns an empty set if ordered_related_items_overrides is present" do | ||
subject = described_class.new( | ||
{ | ||
"links" => { | ||
"ordered_related_items" => [1, 2], | ||
"ordered_related_items_overrides" => "true", | ||
}, | ||
}, | ||
) | ||
|
||
expect(subject.to_h["links"]["ordered_related_items"]).to eq([]) | ||
end | ||
end | ||
|
||
describe "#available_translations" do | ||
it "returns sorted translations with default translation at the top" do | ||
subject = described_class.new( | ||
{ | ||
"links" => { | ||
"available_translations" => [ | ||
{ "locale" => "cy" }, | ||
{ "locale" => "en" }, | ||
], | ||
}, | ||
}, | ||
) | ||
|
||
expect(subject.available_translations).to eq([ | ||
{ "locale" => "en" }, | ||
{ "locale" => "cy" }, | ||
]) | ||
end | ||
end | ||
end |