Merge pull request #4573 from consul/locale_switcher_list
Simplify language selection with a few languages
This commit is contained in:
@@ -17,7 +17,7 @@
|
|||||||
App.Datepicker = {
|
App.Datepicker = {
|
||||||
initialize: function() {
|
initialize: function() {
|
||||||
var locale;
|
var locale;
|
||||||
locale = $("#js-locale").data("current-locale");
|
locale = document.documentElement.lang;
|
||||||
$(".js-calendar").datepicker({
|
$(".js-calendar").datepicker({
|
||||||
maxDate: "+0d"
|
maxDate: "+0d"
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -486,24 +486,6 @@ body > header,
|
|||||||
border-bottom: 1px solid #fff;
|
border-bottom: 1px solid #fff;
|
||||||
}
|
}
|
||||||
|
|
||||||
.locale {
|
|
||||||
float: left;
|
|
||||||
height: $line-height * 1.5;
|
|
||||||
margin-left: $line-height / 2;
|
|
||||||
position: relative;
|
|
||||||
|
|
||||||
&::after {
|
|
||||||
color: #808080;
|
|
||||||
content: "\61";
|
|
||||||
font-family: "icons" !important;
|
|
||||||
font-size: $small-font-size;
|
|
||||||
pointer-events: none;
|
|
||||||
position: absolute;
|
|
||||||
right: 2px;
|
|
||||||
top: 9px;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
.remote-translations-button {
|
.remote-translations-button {
|
||||||
|
|
||||||
&.callout {
|
&.callout {
|
||||||
@@ -654,7 +636,10 @@ body > header,
|
|||||||
.top-links {
|
.top-links {
|
||||||
background: $dark;
|
background: $dark;
|
||||||
font-size: $small-font-size;
|
font-size: $small-font-size;
|
||||||
padding-right: $line-height / 2;
|
|
||||||
|
> :first-child {
|
||||||
|
@include grid-column-gutter;
|
||||||
|
}
|
||||||
|
|
||||||
a {
|
a {
|
||||||
color: inherit;
|
color: inherit;
|
||||||
@@ -982,45 +967,6 @@ footer {
|
|||||||
// 06. Forms
|
// 06. Forms
|
||||||
// ---------
|
// ---------
|
||||||
|
|
||||||
.locale-form {
|
|
||||||
display: inline-block;
|
|
||||||
position: relative;
|
|
||||||
|
|
||||||
label {
|
|
||||||
color: #fff;
|
|
||||||
font-size: $tiny-font-size;
|
|
||||||
font-weight: normal;
|
|
||||||
}
|
|
||||||
|
|
||||||
select {
|
|
||||||
|
|
||||||
option {
|
|
||||||
background: $body-background;
|
|
||||||
color: $text;
|
|
||||||
border: 0;
|
|
||||||
outline: none;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
.locale-switcher {
|
|
||||||
background: #001d33;
|
|
||||||
border: 0;
|
|
||||||
border-radius: rem-calc(4);
|
|
||||||
color: #fff;
|
|
||||||
font-size: $small-font-size;
|
|
||||||
height: $line-height;
|
|
||||||
margin-bottom: 0;
|
|
||||||
margin-top: $line-height / 4;
|
|
||||||
outline: none;
|
|
||||||
padding: 0 $line-height / 4;
|
|
||||||
width: auto;
|
|
||||||
|
|
||||||
&:focus {
|
|
||||||
outline: $outline-focus;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
form {
|
form {
|
||||||
|
|
||||||
label {
|
label {
|
||||||
|
|||||||
81
app/assets/stylesheets/layout/locale_switcher.scss
Normal file
81
app/assets/stylesheets/layout/locale_switcher.scss
Normal file
@@ -0,0 +1,81 @@
|
|||||||
|
.locale {
|
||||||
|
float: left;
|
||||||
|
margin-bottom: $line-height / 4;
|
||||||
|
margin-top: $line-height / 4;
|
||||||
|
position: relative;
|
||||||
|
|
||||||
|
.locale-form {
|
||||||
|
@include has-fa-icon(angle-down, solid, after);
|
||||||
|
display: inline-block;
|
||||||
|
position: relative;
|
||||||
|
|
||||||
|
&::after {
|
||||||
|
color: $light-gray;
|
||||||
|
font-size: $small-font-size;
|
||||||
|
margin-right: 0;
|
||||||
|
pointer-events: none;
|
||||||
|
position: absolute;
|
||||||
|
right: 2px;
|
||||||
|
top: 50%;
|
||||||
|
transform: translateY(-50%);
|
||||||
|
}
|
||||||
|
|
||||||
|
label {
|
||||||
|
color: #fff;
|
||||||
|
font-size: $tiny-font-size;
|
||||||
|
font-weight: normal;
|
||||||
|
}
|
||||||
|
|
||||||
|
select {
|
||||||
|
background: #001d33;
|
||||||
|
border: 0;
|
||||||
|
border-radius: rem-calc(4);
|
||||||
|
color: #fff;
|
||||||
|
font-size: $small-font-size;
|
||||||
|
height: $line-height;
|
||||||
|
margin-bottom: 0;
|
||||||
|
outline: none;
|
||||||
|
padding-left: $line-height / 4;
|
||||||
|
padding-right: calc(#{$line-height / 4} + 1em);
|
||||||
|
width: auto;
|
||||||
|
|
||||||
|
&:focus {
|
||||||
|
outline: $outline-focus;
|
||||||
|
}
|
||||||
|
|
||||||
|
option {
|
||||||
|
background: $body-background;
|
||||||
|
color: $text;
|
||||||
|
border: 0;
|
||||||
|
outline: none;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
p {
|
||||||
|
@include element-invisible;
|
||||||
|
}
|
||||||
|
|
||||||
|
ul {
|
||||||
|
$gap: 0.75em;
|
||||||
|
display: flex;
|
||||||
|
flex-wrap: wrap;
|
||||||
|
margin-left: -$gap;
|
||||||
|
|
||||||
|
> * {
|
||||||
|
margin-left: $gap;
|
||||||
|
}
|
||||||
|
|
||||||
|
li::after {
|
||||||
|
content: none;
|
||||||
|
}
|
||||||
|
|
||||||
|
a {
|
||||||
|
margin-left: 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
[aria-current] {
|
||||||
|
font-weight: bold;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
14
app/components/layout/locale_switcher_component.html.erb
Normal file
14
app/components/layout/locale_switcher_component.html.erb
Normal file
@@ -0,0 +1,14 @@
|
|||||||
|
<div class="locale">
|
||||||
|
<% if many_locales? %>
|
||||||
|
<form class="locale-form">
|
||||||
|
<label class="inline-block" for="locale-switcher"><%= label %></label>
|
||||||
|
<select class="js-location-changer locale-switcher inline-block" name="locale-switcher" id="locale-switcher">
|
||||||
|
<%= options_for_select(language_options, current_path_with_query_params(locale: I18n.locale)) %>
|
||||||
|
</select>
|
||||||
|
</form>
|
||||||
|
<% else %>
|
||||||
|
<p id="<%= label_id %>"><%= label %></p>
|
||||||
|
|
||||||
|
<%= link_list(*language_links, "aria-labelledby": label_id) %>
|
||||||
|
<% end %>
|
||||||
|
</div>
|
||||||
42
app/components/layout/locale_switcher_component.rb
Normal file
42
app/components/layout/locale_switcher_component.rb
Normal file
@@ -0,0 +1,42 @@
|
|||||||
|
class Layout::LocaleSwitcherComponent < ApplicationComponent
|
||||||
|
delegate :name_for_locale, :link_list, :current_path_with_query_params, to: :helpers
|
||||||
|
|
||||||
|
def render?
|
||||||
|
locales.size > 1
|
||||||
|
end
|
||||||
|
|
||||||
|
private
|
||||||
|
|
||||||
|
def many_locales?
|
||||||
|
locales.size > 4
|
||||||
|
end
|
||||||
|
|
||||||
|
def locales
|
||||||
|
I18n.available_locales
|
||||||
|
end
|
||||||
|
|
||||||
|
def label
|
||||||
|
t("layouts.header.locale")
|
||||||
|
end
|
||||||
|
|
||||||
|
def label_id
|
||||||
|
"locale_switcher_label"
|
||||||
|
end
|
||||||
|
|
||||||
|
def language_links
|
||||||
|
locales.map do |locale|
|
||||||
|
[
|
||||||
|
name_for_locale(locale),
|
||||||
|
current_path_with_query_params(locale: locale),
|
||||||
|
locale == I18n.locale,
|
||||||
|
lang: locale
|
||||||
|
]
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def language_options
|
||||||
|
language_links.map do |text, path, _, options|
|
||||||
|
[text, path, options]
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
1
app/components/shared/link_list_component.html.erb
Normal file
1
app/components/shared/link_list_component.html.erb
Normal file
@@ -0,0 +1 @@
|
|||||||
|
<%= tag.ul(options) { safe_join(list_items, "\n") } %>
|
||||||
30
app/components/shared/link_list_component.rb
Normal file
30
app/components/shared/link_list_component.rb
Normal file
@@ -0,0 +1,30 @@
|
|||||||
|
class Shared::LinkListComponent < ApplicationComponent
|
||||||
|
attr_reader :links, :options
|
||||||
|
|
||||||
|
def initialize(*links, **options)
|
||||||
|
@links = links
|
||||||
|
@options = options
|
||||||
|
end
|
||||||
|
|
||||||
|
def render?
|
||||||
|
present_links.any?
|
||||||
|
end
|
||||||
|
|
||||||
|
private
|
||||||
|
|
||||||
|
def present_links
|
||||||
|
links.select(&:present?)
|
||||||
|
end
|
||||||
|
|
||||||
|
def list_items
|
||||||
|
present_links.map do |text, url, current = false, **link_options|
|
||||||
|
tag.li(({ "aria-current": true } if current)) do
|
||||||
|
if url
|
||||||
|
link_to text, url, link_options
|
||||||
|
else
|
||||||
|
text
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
@@ -1,17 +1,5 @@
|
|||||||
module LinkListHelper
|
module LinkListHelper
|
||||||
def link_list(*links, **options)
|
def link_list(*links, **options)
|
||||||
return "" if links.select(&:present?).empty?
|
render Shared::LinkListComponent.new(*links, **options)
|
||||||
|
|
||||||
tag.ul(options) do
|
|
||||||
safe_join(links.select(&:present?).map do |text, url, current = false, **link_options|
|
|
||||||
tag.li(({ "aria-current": true } if current)) do
|
|
||||||
if url
|
|
||||||
link_to text, url, link_options
|
|
||||||
else
|
|
||||||
text
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end, "\n")
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -1,19 +1 @@
|
|||||||
<% if I18n.available_locales.size > 1 %>
|
<%= render Layout::LocaleSwitcherComponent.new %>
|
||||||
<div class="locale" id="js-locale" data-current-locale="<%= I18n.locale %>">
|
|
||||||
<form class="locale-form">
|
|
||||||
<label class="inline-block" for="locale-switcher">
|
|
||||||
<%= t("layouts.header.locale") %>
|
|
||||||
</label>
|
|
||||||
<select class="js-location-changer locale-switcher inline-block" name="locale-switcher" id="locale-switcher">
|
|
||||||
<optgroup label="<%= t("layouts.header.available_locales") %>">
|
|
||||||
<% I18n.available_locales.map do |loc| %>
|
|
||||||
<option <%= "selected" if loc == I18n.locale %>
|
|
||||||
value="<%= current_path_with_query_params(locale: loc) %>">
|
|
||||||
<%= name_for_locale(loc) %>
|
|
||||||
</option>
|
|
||||||
<% end %>
|
|
||||||
</optgroup>
|
|
||||||
</select>
|
|
||||||
</form>
|
|
||||||
</div>
|
|
||||||
<% end %>
|
|
||||||
|
|||||||
@@ -226,7 +226,6 @@ en:
|
|||||||
header:
|
header:
|
||||||
administration_menu: Menu
|
administration_menu: Menu
|
||||||
administration: Administration
|
administration: Administration
|
||||||
available_locales: Available languages
|
|
||||||
collaborative_legislation: Collaborative legislation
|
collaborative_legislation: Collaborative legislation
|
||||||
debates: Debates
|
debates: Debates
|
||||||
locale: "Language:"
|
locale: "Language:"
|
||||||
|
|||||||
@@ -226,7 +226,6 @@ es:
|
|||||||
header:
|
header:
|
||||||
administration_menu: Menú
|
administration_menu: Menú
|
||||||
administration: Administración
|
administration: Administración
|
||||||
available_locales: Idiomas disponibles
|
|
||||||
collaborative_legislation: Legislación colaborativa
|
collaborative_legislation: Legislación colaborativa
|
||||||
debates: Debates
|
debates: Debates
|
||||||
locale: "Idioma:"
|
locale: "Idioma:"
|
||||||
|
|||||||
80
spec/components/layout/locale_switcher_component_spec.rb
Normal file
80
spec/components/layout/locale_switcher_component_spec.rb
Normal file
@@ -0,0 +1,80 @@
|
|||||||
|
require "rails_helper"
|
||||||
|
|
||||||
|
describe Layout::LocaleSwitcherComponent, type: :component do
|
||||||
|
let(:component) { Layout::LocaleSwitcherComponent.new }
|
||||||
|
|
||||||
|
before do
|
||||||
|
allow(request).to receive(:path_parameters).and_return(
|
||||||
|
Rails.application.routes.recognize_path("/")
|
||||||
|
)
|
||||||
|
end
|
||||||
|
|
||||||
|
context "with only one language" do
|
||||||
|
before { allow(I18n).to receive(:available_locales).and_return([:en]) }
|
||||||
|
|
||||||
|
it "doesn't render anything" do
|
||||||
|
render_inline component
|
||||||
|
|
||||||
|
expect(page.text).to be_empty
|
||||||
|
expect(page).not_to have_css ".locale"
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
context "with many languages" do
|
||||||
|
before { allow(I18n).to receive(:available_locales).and_return(%i[de en es fr nl]) }
|
||||||
|
|
||||||
|
it "renders a form to select the language" do
|
||||||
|
render_inline component
|
||||||
|
|
||||||
|
expect(page).to have_css "form"
|
||||||
|
expect(page).to have_select "Language:", options: %w[Deutsch English Español Français Nederlands]
|
||||||
|
expect(page).not_to have_css "ul"
|
||||||
|
end
|
||||||
|
|
||||||
|
it "selects the current locale" do
|
||||||
|
render_inline component
|
||||||
|
|
||||||
|
expect(page).to have_select "Language:", selected: "English"
|
||||||
|
end
|
||||||
|
|
||||||
|
context "missing language names" do
|
||||||
|
let!(:default_enforce) { I18n.enforce_available_locales }
|
||||||
|
|
||||||
|
before do
|
||||||
|
I18n.enforce_available_locales = false
|
||||||
|
allow(I18n).to receive(:available_locales).and_return(%i[de en es fr nl wl])
|
||||||
|
end
|
||||||
|
|
||||||
|
after { I18n.enforce_available_locales = default_enforce }
|
||||||
|
|
||||||
|
it "renders the locale key" do
|
||||||
|
render_inline component
|
||||||
|
|
||||||
|
expect(page).to have_select "Language:", with_options: ["wl"]
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
context "with a few languages" do
|
||||||
|
before do
|
||||||
|
allow(I18n).to receive(:available_locales).and_return(%i[en es fr])
|
||||||
|
end
|
||||||
|
|
||||||
|
it "renders a list of links" do
|
||||||
|
render_inline component
|
||||||
|
|
||||||
|
expect(page).to have_css "ul"
|
||||||
|
expect(page).to have_link "English", href: "/?locale=en"
|
||||||
|
expect(page).to have_link "Español", href: "/?locale=es"
|
||||||
|
expect(page).to have_link "Français", href: "/?locale=fr"
|
||||||
|
expect(page).not_to have_css "form"
|
||||||
|
end
|
||||||
|
|
||||||
|
it "marks the current locale" do
|
||||||
|
render_inline component
|
||||||
|
|
||||||
|
expect(page).to have_css "[aria-current]", count: 1
|
||||||
|
expect(page).to have_css "[aria-current]", exact_text: "English"
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
93
spec/components/shared/link_list_component_spec.rb
Normal file
93
spec/components/shared/link_list_component_spec.rb
Normal file
@@ -0,0 +1,93 @@
|
|||||||
|
require "rails_helper"
|
||||||
|
|
||||||
|
describe Shared::LinkListComponent, type: :component do
|
||||||
|
it "renders nothing with an empty list" do
|
||||||
|
render_inline Shared::LinkListComponent.new
|
||||||
|
|
||||||
|
expect(page).not_to have_css "ul"
|
||||||
|
end
|
||||||
|
|
||||||
|
it "returns nothing with a list of nil elements" do
|
||||||
|
render_inline Shared::LinkListComponent.new(nil, nil)
|
||||||
|
|
||||||
|
expect(page).not_to have_css "ul"
|
||||||
|
end
|
||||||
|
|
||||||
|
it "generates a list of links" do
|
||||||
|
render_inline Shared::LinkListComponent.new(
|
||||||
|
["Home", "/"], ["Info", "/info"], class: "menu"
|
||||||
|
)
|
||||||
|
list = page.find("body").native.inner_html
|
||||||
|
|
||||||
|
expect(list).to eq '<ul class="menu">' + "\n" +
|
||||||
|
'<li><a href="/">Home</a></li>' + "\n" +
|
||||||
|
'<li><a href="/info">Info</a></li>' + "\n</ul>\n"
|
||||||
|
end
|
||||||
|
|
||||||
|
it "accepts anchor tags" do
|
||||||
|
render_inline Shared::LinkListComponent.new(
|
||||||
|
'<a href="/">Home</a>'.html_safe, ["Info", "/info"], class: "menu"
|
||||||
|
)
|
||||||
|
list = page.find("body").native.inner_html
|
||||||
|
|
||||||
|
expect(list).to eq '<ul class="menu">' + "\n" +
|
||||||
|
'<li><a href="/">Home</a></li>' + "\n" +
|
||||||
|
'<li><a href="/info">Info</a></li>' + "\n</ul>\n"
|
||||||
|
end
|
||||||
|
|
||||||
|
it "accepts options for links" do
|
||||||
|
render_inline Shared::LinkListComponent.new(
|
||||||
|
["Home", "/", class: "root"], ["Info", "/info", id: "info"]
|
||||||
|
)
|
||||||
|
|
||||||
|
expect(page).to have_css "a", count: 2
|
||||||
|
expect(page).to have_css "a.root", count: 1, exact_text: "Home"
|
||||||
|
expect(page).to have_css "a#info", count: 1, exact_text: "Info"
|
||||||
|
end
|
||||||
|
|
||||||
|
it "ignores nil entries" do
|
||||||
|
render_inline Shared::LinkListComponent.new(
|
||||||
|
["Home", "/", class: "root"], nil, ["Info", "/info", id: "info"]
|
||||||
|
)
|
||||||
|
|
||||||
|
expect(page).to have_css "li", count: 2
|
||||||
|
expect(page).to have_css "a.root", count: 1, exact_text: "Home"
|
||||||
|
expect(page).to have_css "a#info", count: 1, exact_text: "Info"
|
||||||
|
end
|
||||||
|
|
||||||
|
it "ignores empty entries" do
|
||||||
|
render_inline Shared::LinkListComponent.new(
|
||||||
|
["Home", "/", class: "root"], "", ["Info", "/info", id: "info"]
|
||||||
|
)
|
||||||
|
|
||||||
|
expect(page).to have_css "li", count: 2
|
||||||
|
expect(page).to have_css "a.root", count: 1, exact_text: "Home"
|
||||||
|
expect(page).to have_css "a#info", count: 1, exact_text: "Info"
|
||||||
|
end
|
||||||
|
|
||||||
|
it "accepts an optional condition to check the active element" do
|
||||||
|
render_inline Shared::LinkListComponent.new(
|
||||||
|
["Home", "/", false],
|
||||||
|
["Info", "/info", true],
|
||||||
|
["Help", "/help"]
|
||||||
|
)
|
||||||
|
|
||||||
|
expect(page).to have_css "li", count: 3
|
||||||
|
expect(page).to have_css "li[aria-current='true']", count: 1, exact_text: "Info"
|
||||||
|
end
|
||||||
|
|
||||||
|
it "allows passing both the active condition and link options" do
|
||||||
|
render_inline Shared::LinkListComponent.new(
|
||||||
|
["Home", "/", false, class: "root"],
|
||||||
|
["Info", "/info", true, id: "info"],
|
||||||
|
["Help", "/help", rel: "help"]
|
||||||
|
)
|
||||||
|
|
||||||
|
expect(page).to have_css "li", count: 3
|
||||||
|
expect(page).to have_css "li[aria-current='true']", count: 1, exact_text: "Info"
|
||||||
|
|
||||||
|
expect(page).to have_css "a.root", count: 1, exact_text: "Home"
|
||||||
|
expect(page).to have_css "a#info", count: 1, exact_text: "Info"
|
||||||
|
expect(page).to have_css "a[rel='help']", count: 1, exact_text: "Help"
|
||||||
|
end
|
||||||
|
end
|
||||||
@@ -1,91 +0,0 @@
|
|||||||
require "rails_helper"
|
|
||||||
|
|
||||||
describe LinkListHelper do
|
|
||||||
describe "#link_list" do
|
|
||||||
it "returns an empty string with an empty list" do
|
|
||||||
expect(helper.link_list).to eq ""
|
|
||||||
end
|
|
||||||
|
|
||||||
it "returns nothing with a list of nil elements" do
|
|
||||||
expect(helper.link_list(nil, nil)).to eq ""
|
|
||||||
end
|
|
||||||
|
|
||||||
it "generates a list of links" do
|
|
||||||
list = helper.link_list(["Home", "/"], ["Info", "/info"], class: "menu")
|
|
||||||
|
|
||||||
expect(list).to eq '<ul class="menu">' +
|
|
||||||
'<li><a href="/">Home</a></li>' + "\n" +
|
|
||||||
'<li><a href="/info">Info</a></li></ul>'
|
|
||||||
expect(list).to be_html_safe
|
|
||||||
end
|
|
||||||
|
|
||||||
it "accepts anchor tags" do
|
|
||||||
list = helper.link_list(link_to("Home", "/"), ["Info", "/info"], class: "menu")
|
|
||||||
|
|
||||||
expect(list).to eq '<ul class="menu">' +
|
|
||||||
'<li><a href="/">Home</a></li>' + "\n" +
|
|
||||||
'<li><a href="/info">Info</a></li></ul>'
|
|
||||||
expect(list).to be_html_safe
|
|
||||||
end
|
|
||||||
|
|
||||||
it "accepts options for links" do
|
|
||||||
render helper.link_list(["Home", "/", class: "root"], ["Info", "/info", id: "info"])
|
|
||||||
|
|
||||||
expect(page).to have_css "a", count: 2
|
|
||||||
expect(page).to have_css "a.root", count: 1, exact_text: "Home"
|
|
||||||
expect(page).to have_css "a#info", count: 1, exact_text: "Info"
|
|
||||||
end
|
|
||||||
|
|
||||||
it "ignores nil entries" do
|
|
||||||
render helper.link_list(["Home", "/", class: "root"], nil, ["Info", "/info", id: "info"])
|
|
||||||
|
|
||||||
expect(page).to have_css "li", count: 2
|
|
||||||
expect(page).to have_css "a.root", count: 1, exact_text: "Home"
|
|
||||||
expect(page).to have_css "a#info", count: 1, exact_text: "Info"
|
|
||||||
end
|
|
||||||
|
|
||||||
it "ignores empty entries" do
|
|
||||||
render helper.link_list(["Home", "/", class: "root"], "", ["Info", "/info", id: "info"])
|
|
||||||
|
|
||||||
expect(page).to have_css "li", count: 2
|
|
||||||
expect(page).to have_css "a.root", count: 1, exact_text: "Home"
|
|
||||||
expect(page).to have_css "a#info", count: 1, exact_text: "Info"
|
|
||||||
end
|
|
||||||
|
|
||||||
it "accepts an optional condition to check the active element" do
|
|
||||||
render helper.link_list(
|
|
||||||
["Home", "/", false],
|
|
||||||
["Info", "/info", true],
|
|
||||||
["Help", "/help"]
|
|
||||||
)
|
|
||||||
|
|
||||||
expect(page).to have_css "li", count: 3
|
|
||||||
expect(page).to have_css "li[aria-current='true']", count: 1, exact_text: "Info"
|
|
||||||
end
|
|
||||||
|
|
||||||
it "allows passing both the active condition and link options" do
|
|
||||||
render helper.link_list(
|
|
||||||
["Home", "/", false, class: "root"],
|
|
||||||
["Info", "/info", true, id: "info"],
|
|
||||||
["Help", "/help", rel: "help"]
|
|
||||||
)
|
|
||||||
|
|
||||||
expect(page).to have_css "li", count: 3
|
|
||||||
expect(page).to have_css "li[aria-current='true']", count: 1, exact_text: "Info"
|
|
||||||
|
|
||||||
expect(page).to have_css "a.root", count: 1, exact_text: "Home"
|
|
||||||
expect(page).to have_css "a#info", count: 1, exact_text: "Info"
|
|
||||||
expect(page).to have_css "a[rel='help']", count: 1, exact_text: "Help"
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
attr_reader :content
|
|
||||||
|
|
||||||
def render(content)
|
|
||||||
@content = content
|
|
||||||
end
|
|
||||||
|
|
||||||
def page
|
|
||||||
Capybara::Node::Simple.new(content)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
@@ -34,7 +34,7 @@ shared_examples "milestoneable" do |factory_name|
|
|||||||
expect(page).to have_content(first_milestone.status.name)
|
expect(page).to have_content(first_milestone.status.name)
|
||||||
end
|
end
|
||||||
|
|
||||||
select("Español", from: "locale-switcher")
|
select "Español", from: "Language:"
|
||||||
|
|
||||||
find("#tab-milestones-label").click
|
find("#tab-milestones-label").click
|
||||||
|
|
||||||
|
|||||||
@@ -25,7 +25,7 @@ shared_examples "remotely_translatable" do |factory_name, path_name, path_argume
|
|||||||
scenario "should be present when current locale translation does not exists" do
|
scenario "should be present when current locale translation does not exists" do
|
||||||
visit path
|
visit path
|
||||||
|
|
||||||
select("Español", from: "locale-switcher")
|
select "Español", from: "Language:"
|
||||||
|
|
||||||
expect(page).to have_button("Traducir página")
|
expect(page).to have_button("Traducir página")
|
||||||
end
|
end
|
||||||
@@ -35,7 +35,7 @@ shared_examples "remotely_translatable" do |factory_name, path_name, path_argume
|
|||||||
visit path
|
visit path
|
||||||
expect(page).not_to have_button("Translate page")
|
expect(page).not_to have_button("Translate page")
|
||||||
|
|
||||||
select("Español", from: "locale-switcher")
|
select "Español", from: "Language:"
|
||||||
|
|
||||||
expect(page).not_to have_button("Traducir página")
|
expect(page).not_to have_button("Traducir página")
|
||||||
end
|
end
|
||||||
@@ -45,7 +45,7 @@ shared_examples "remotely_translatable" do |factory_name, path_name, path_argume
|
|||||||
resource.destroy!
|
resource.destroy!
|
||||||
visit path
|
visit path
|
||||||
|
|
||||||
select("Español", from: "locale-switcher")
|
select "Español", from: "Language:"
|
||||||
|
|
||||||
expect(page).not_to have_button("Traducir página")
|
expect(page).not_to have_button("Traducir página")
|
||||||
end
|
end
|
||||||
@@ -55,7 +55,7 @@ shared_examples "remotely_translatable" do |factory_name, path_name, path_argume
|
|||||||
create(:remote_translation, remote_translatable: resource, locale: :es)
|
create(:remote_translation, remote_translatable: resource, locale: :es)
|
||||||
visit path
|
visit path
|
||||||
|
|
||||||
select("Español", from: "locale-switcher")
|
select "Español", from: "Language:"
|
||||||
|
|
||||||
expect(page).not_to have_button("Traducir página")
|
expect(page).not_to have_button("Traducir página")
|
||||||
expect(page).to have_content("En un breve periodo de tiempo refrescando la página podrá ver todo el contenido en su idioma")
|
expect(page).to have_content("En un breve periodo de tiempo refrescando la página podrá ver todo el contenido en su idioma")
|
||||||
@@ -75,7 +75,7 @@ shared_examples "remotely_translatable" do |factory_name, path_name, path_argume
|
|||||||
visit path
|
visit path
|
||||||
expect(page).not_to have_button("Translate page")
|
expect(page).not_to have_button("Translate page")
|
||||||
|
|
||||||
select("Español", from: "locale-switcher")
|
select "Español", from: "Language:"
|
||||||
|
|
||||||
expect(page).not_to have_button("Traducir página")
|
expect(page).not_to have_button("Traducir página")
|
||||||
end
|
end
|
||||||
@@ -94,7 +94,7 @@ shared_examples "remotely_translatable" do |factory_name, path_name, path_argume
|
|||||||
visit path
|
visit path
|
||||||
expect(page).not_to have_button("Translate page")
|
expect(page).not_to have_button("Translate page")
|
||||||
|
|
||||||
select("Español", from: "locale-switcher")
|
select "Español", from: "Language:"
|
||||||
|
|
||||||
expect(page).to have_button("Traducir página")
|
expect(page).to have_button("Traducir página")
|
||||||
end
|
end
|
||||||
@@ -105,7 +105,7 @@ shared_examples "remotely_translatable" do |factory_name, path_name, path_argume
|
|||||||
visit path
|
visit path
|
||||||
expect(page).not_to have_button("Translate page")
|
expect(page).not_to have_button("Translate page")
|
||||||
|
|
||||||
select("Español", from: "locale-switcher")
|
select "Español", from: "Language:"
|
||||||
|
|
||||||
expect(page).not_to have_button("Traducir página")
|
expect(page).not_to have_button("Traducir página")
|
||||||
end
|
end
|
||||||
@@ -120,7 +120,7 @@ shared_examples "remotely_translatable" do |factory_name, path_name, path_argume
|
|||||||
visit path
|
visit path
|
||||||
expect(page).not_to have_button("Translate page")
|
expect(page).not_to have_button("Translate page")
|
||||||
|
|
||||||
select("Español", from: "locale-switcher")
|
select "Español", from: "Language:"
|
||||||
|
|
||||||
expect(page).to have_button("Traducir página")
|
expect(page).to have_button("Traducir página")
|
||||||
end
|
end
|
||||||
@@ -135,7 +135,7 @@ shared_examples "remotely_translatable" do |factory_name, path_name, path_argume
|
|||||||
visit path
|
visit path
|
||||||
expect(page).not_to have_button("Translate page")
|
expect(page).not_to have_button("Translate page")
|
||||||
|
|
||||||
select("Español", from: "locale-switcher")
|
select "Español", from: "Language:"
|
||||||
|
|
||||||
expect(page).to have_button("Traducir página")
|
expect(page).to have_button("Traducir página")
|
||||||
end
|
end
|
||||||
@@ -146,7 +146,7 @@ shared_examples "remotely_translatable" do |factory_name, path_name, path_argume
|
|||||||
describe "with delayed jobs", :delay_jobs do
|
describe "with delayed jobs", :delay_jobs do
|
||||||
scenario "the remote translation button should not be present" do
|
scenario "the remote translation button should not be present" do
|
||||||
visit path
|
visit path
|
||||||
select("Español", from: "locale-switcher")
|
select "Español", from: "Language:"
|
||||||
|
|
||||||
click_button "Traducir página"
|
click_button "Traducir página"
|
||||||
|
|
||||||
@@ -155,14 +155,14 @@ shared_examples "remotely_translatable" do |factory_name, path_name, path_argume
|
|||||||
|
|
||||||
scenario "the remote translation is pending to translate" do
|
scenario "the remote translation is pending to translate" do
|
||||||
visit path
|
visit path
|
||||||
select("Español", from: "locale-switcher")
|
select "Español", from: "Language:"
|
||||||
|
|
||||||
expect { click_button "Traducir página" }.to change { RemoteTranslation.count }.from(0).to(1)
|
expect { click_button "Traducir página" }.to change { RemoteTranslation.count }.from(0).to(1)
|
||||||
end
|
end
|
||||||
|
|
||||||
scenario "should be present enqueued notice and informative text" do
|
scenario "should be present enqueued notice and informative text" do
|
||||||
visit path
|
visit path
|
||||||
select("Español", from: "locale-switcher")
|
select "Español", from: "Language:"
|
||||||
|
|
||||||
click_button "Traducir página"
|
click_button "Traducir página"
|
||||||
|
|
||||||
@@ -172,12 +172,12 @@ shared_examples "remotely_translatable" do |factory_name, path_name, path_argume
|
|||||||
|
|
||||||
scenario "should be present only informative text when user visit page with all content enqueued" do
|
scenario "should be present only informative text when user visit page with all content enqueued" do
|
||||||
visit path
|
visit path
|
||||||
select("Español", from: "locale-switcher")
|
select "Español", from: "Language:"
|
||||||
click_button "Traducir página"
|
click_button "Traducir página"
|
||||||
expect(page).to have_content("Se han solicitado correctamente las traducciones.")
|
expect(page).to have_content("Se han solicitado correctamente las traducciones.")
|
||||||
|
|
||||||
visit path
|
visit path
|
||||||
select("Español", from: "locale-switcher")
|
select "Español", from: "Idioma:"
|
||||||
|
|
||||||
expect(page).not_to have_button "Traducir página"
|
expect(page).not_to have_button "Traducir página"
|
||||||
expect(page).not_to have_content("Se han solicitado correctamente las traducciones.")
|
expect(page).not_to have_content("Se han solicitado correctamente las traducciones.")
|
||||||
@@ -190,7 +190,7 @@ shared_examples "remotely_translatable" do |factory_name, path_name, path_argume
|
|||||||
microsoft_translate_client_response = generate_response(resource)
|
microsoft_translate_client_response = generate_response(resource)
|
||||||
expect_any_instance_of(RemoteTranslations::Microsoft::Client).to receive(:call).and_return(microsoft_translate_client_response)
|
expect_any_instance_of(RemoteTranslations::Microsoft::Client).to receive(:call).and_return(microsoft_translate_client_response)
|
||||||
visit path
|
visit path
|
||||||
select("Español", from: "locale-switcher")
|
select "Español", from: "Language:"
|
||||||
|
|
||||||
click_button "Traducir página"
|
click_button "Traducir página"
|
||||||
|
|
||||||
@@ -201,7 +201,7 @@ shared_examples "remotely_translatable" do |factory_name, path_name, path_argume
|
|||||||
microsoft_translate_client_response = generate_response(resource)
|
microsoft_translate_client_response = generate_response(resource)
|
||||||
expect_any_instance_of(RemoteTranslations::Microsoft::Client).to receive(:call).and_return(microsoft_translate_client_response)
|
expect_any_instance_of(RemoteTranslations::Microsoft::Client).to receive(:call).and_return(microsoft_translate_client_response)
|
||||||
visit path
|
visit path
|
||||||
select("Español", from: "locale-switcher")
|
select "Español", from: "Language:"
|
||||||
|
|
||||||
click_button "Traducir página"
|
click_button "Traducir página"
|
||||||
|
|
||||||
|
|||||||
@@ -161,7 +161,7 @@ describe "Admin poll questions", :admin do
|
|||||||
|
|
||||||
expect(page).to have_select("poll_question_poll_id", options: ["Select Poll", poll.name_en])
|
expect(page).to have_select("poll_question_poll_id", options: ["Select Poll", poll.name_en])
|
||||||
|
|
||||||
select("Español", from: "locale-switcher")
|
select "Español", from: "Language:"
|
||||||
|
|
||||||
expect(page).to have_select("poll_question_poll_id",
|
expect(page).to have_select("poll_question_poll_id",
|
||||||
options: ["Seleccionar votación", poll.name_es])
|
options: ["Seleccionar votación", poll.name_es])
|
||||||
@@ -180,7 +180,7 @@ describe "Admin poll questions", :admin do
|
|||||||
|
|
||||||
expect(page).to have_select("poll_question_poll_id", options: ["Select Poll", poll.name_en])
|
expect(page).to have_select("poll_question_poll_id", options: ["Select Poll", poll.name_en])
|
||||||
|
|
||||||
select("Français", from: "locale-switcher")
|
select "Français", from: "Language:"
|
||||||
|
|
||||||
expect(page).to have_select("poll_question_poll_id",
|
expect(page).to have_select("poll_question_poll_id",
|
||||||
options: ["Sélectionner un vote", poll.name_es])
|
options: ["Sélectionner un vote", poll.name_es])
|
||||||
|
|||||||
@@ -112,7 +112,7 @@ describe "Admin edit translatable records", :admin do
|
|||||||
click_button "Save changes"
|
click_button "Save changes"
|
||||||
|
|
||||||
visit path
|
visit path
|
||||||
select "Português brasileiro", from: "locale-switcher"
|
select "Português brasileiro", from: "Language:"
|
||||||
|
|
||||||
expect(page).to have_field "Questão", with: "Português"
|
expect(page).to have_field "Questão", with: "Português"
|
||||||
end
|
end
|
||||||
@@ -205,7 +205,7 @@ describe "Admin edit translatable records", :admin do
|
|||||||
|
|
||||||
expect(page).to have_field "Title", with: "Title in English"
|
expect(page).to have_field "Title", with: "Title in English"
|
||||||
|
|
||||||
select("Español", from: "locale-switcher")
|
select "Español", from: "Language:"
|
||||||
|
|
||||||
expect(page).to have_field "Título", with: "Título corregido"
|
expect(page).to have_field "Título", with: "Título corregido"
|
||||||
expect(page).to have_field "Descripción", with: "Descripción corregida"
|
expect(page).to have_field "Descripción", with: "Descripción corregida"
|
||||||
@@ -234,7 +234,7 @@ describe "Admin edit translatable records", :admin do
|
|||||||
|
|
||||||
expect(page).to have_field "Answer", with: "Answer in English"
|
expect(page).to have_field "Answer", with: "Answer in English"
|
||||||
|
|
||||||
select("Español", from: "locale-switcher")
|
select "Español", from: "Language:"
|
||||||
|
|
||||||
expect(page).to have_field "Respuesta", with: "Respuesta corregida"
|
expect(page).to have_field "Respuesta", with: "Respuesta corregida"
|
||||||
expect(page).to have_ckeditor "Descripción", with: "Descripción corregida"
|
expect(page).to have_ckeditor "Descripción", with: "Descripción corregida"
|
||||||
@@ -466,7 +466,7 @@ describe "Admin edit translatable records", :admin do
|
|||||||
|
|
||||||
expect_to_have_language_selected "English"
|
expect_to_have_language_selected "English"
|
||||||
|
|
||||||
select("Español", from: "locale-switcher")
|
select "Español", from: "Language:"
|
||||||
|
|
||||||
expect_to_have_language_selected "Español"
|
expect_to_have_language_selected "Español"
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -22,7 +22,7 @@ describe "Admin Budgets", :admin do
|
|||||||
name_fr: "Budget pour le changement climatique")
|
name_fr: "Budget pour le changement climatique")
|
||||||
|
|
||||||
visit admin_budgets_path
|
visit admin_budgets_path
|
||||||
select("Français", from: "locale-switcher")
|
select "Français", from: "Language:"
|
||||||
|
|
||||||
click_link "Bulletins de l’admin"
|
click_link "Bulletins de l’admin"
|
||||||
|
|
||||||
|
|||||||
@@ -16,79 +16,23 @@ describe "Localization" do
|
|||||||
expect(page).to have_text("Bienvenido a CONSUL")
|
expect(page).to have_text("Bienvenido a CONSUL")
|
||||||
end
|
end
|
||||||
|
|
||||||
scenario "Available locales appear in the locale switcher" do
|
|
||||||
visit "/"
|
|
||||||
|
|
||||||
within(".locale-form .js-location-changer") do
|
|
||||||
expect(page).to have_content "Español"
|
|
||||||
expect(page).to have_content "English"
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
scenario "The current locale is selected" do
|
|
||||||
visit "/"
|
|
||||||
expect(page).to have_select("locale-switcher", selected: "English")
|
|
||||||
end
|
|
||||||
|
|
||||||
scenario "Changing the locale" do
|
scenario "Changing the locale" do
|
||||||
visit "/"
|
visit "/"
|
||||||
expect(page).to have_content("Language")
|
select "Español", from: "Language:"
|
||||||
|
|
||||||
select("Español", from: "locale-switcher")
|
expect(page).not_to have_select "Language:"
|
||||||
expect(page).to have_content("Idioma")
|
expect(page).to have_select "Idioma:", selected: "Español"
|
||||||
expect(page).not_to have_content("Language")
|
|
||||||
expect(page).to have_select("locale-switcher", selected: "Español")
|
|
||||||
end
|
end
|
||||||
|
|
||||||
scenario "Keeps query parameters while using protected redirects" do
|
scenario "Keeps query parameters while using protected redirects" do
|
||||||
visit "/debates?order=created_at&host=evil.dev"
|
visit "/debates?order=created_at&host=evil.dev"
|
||||||
|
|
||||||
select("Español", from: "locale-switcher")
|
select "Español", from: "Language:"
|
||||||
|
|
||||||
expect(current_host).to eq "http://127.0.0.1"
|
expect(current_host).to eq "http://127.0.0.1"
|
||||||
expect(page).to have_current_path "/debates?locale=es&order=created_at"
|
expect(page).to have_current_path "/debates?locale=es&order=created_at"
|
||||||
end
|
end
|
||||||
|
|
||||||
context "Only one locale" do
|
|
||||||
before do
|
|
||||||
allow(I18n).to receive(:available_locales).and_return([:en])
|
|
||||||
I18n.reload!
|
|
||||||
end
|
|
||||||
|
|
||||||
after { I18n.reload! }
|
|
||||||
|
|
||||||
scenario "Locale switcher not present" do
|
|
||||||
visit "/"
|
|
||||||
expect(page).not_to have_content("Language")
|
|
||||||
expect(page).not_to have_css("div.locale")
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
context "Missing language names" do
|
|
||||||
let!(:default_enforce) { I18n.enforce_available_locales }
|
|
||||||
let!(:default_locales) { I18n.available_locales.dup }
|
|
||||||
|
|
||||||
before do
|
|
||||||
I18n.enforce_available_locales = false
|
|
||||||
I18n.available_locales = default_locales + [:wl]
|
|
||||||
I18n.locale = :wl
|
|
||||||
end
|
|
||||||
|
|
||||||
after do
|
|
||||||
I18n.enforce_available_locales = default_enforce
|
|
||||||
I18n.available_locales = default_locales
|
|
||||||
I18n.locale = I18n.default_locale
|
|
||||||
end
|
|
||||||
|
|
||||||
scenario "Available locales without language translation display locale key" do
|
|
||||||
visit "/"
|
|
||||||
|
|
||||||
within(".locale-form .js-location-changer") do
|
|
||||||
expect(page).to have_content "wl"
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
scenario "uses default locale when session locale has disappeared" do
|
scenario "uses default locale when session locale has disappeared" do
|
||||||
default_locales = I18n.available_locales
|
default_locales = I18n.available_locales
|
||||||
|
|
||||||
|
|||||||
@@ -9,36 +9,12 @@ describe "Localization" do
|
|||||||
expect(page).to have_text("Gestión")
|
expect(page).to have_text("Gestión")
|
||||||
end
|
end
|
||||||
|
|
||||||
scenario "Available locales appear in the locale switcher" do
|
|
||||||
login_as_manager
|
|
||||||
|
|
||||||
within(".locale-form .js-location-changer") do
|
|
||||||
expect(page).to have_content "Español"
|
|
||||||
expect(page).to have_content "English"
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
scenario "The current locale is selected" do
|
|
||||||
login_as_manager
|
|
||||||
expect(page).to have_select("locale-switcher", selected: "English")
|
|
||||||
expect(page).to have_text("Management")
|
|
||||||
end
|
|
||||||
|
|
||||||
scenario "Changing the locale" do
|
scenario "Changing the locale" do
|
||||||
login_as_manager
|
login_as_manager
|
||||||
expect(page).to have_content("Language")
|
select "Español", from: "Language:"
|
||||||
|
|
||||||
select("Español", from: "locale-switcher")
|
expect(page).not_to have_select "Language:"
|
||||||
expect(page).to have_content("Idioma")
|
expect(page).to have_select "Idioma:", selected: "Español"
|
||||||
expect(page).not_to have_content("Language")
|
expect(page).to have_content "Gestión"
|
||||||
expect(page).to have_select("locale-switcher", selected: "Español")
|
|
||||||
end
|
|
||||||
|
|
||||||
scenario "Locale switcher not present if only one locale" do
|
|
||||||
allow(I18n).to receive(:available_locales).and_return([:en])
|
|
||||||
|
|
||||||
login_as_manager
|
|
||||||
expect(page).not_to have_content("Language")
|
|
||||||
expect(page).not_to have_css("div.locale")
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -115,7 +115,7 @@ describe "Public area translatable records" do
|
|||||||
scenario "Highlight new locale added" do
|
scenario "Highlight new locale added" do
|
||||||
visit new_proposal_path
|
visit new_proposal_path
|
||||||
|
|
||||||
select "Español", from: "locale-switcher"
|
select "Español", from: "Language:"
|
||||||
|
|
||||||
expect_to_have_language_selected "Español"
|
expect_to_have_language_selected "Español"
|
||||||
end
|
end
|
||||||
@@ -206,7 +206,7 @@ describe "Public area translatable records" do
|
|||||||
|
|
||||||
expect(page).to have_field "Debate title", with: "Title in English"
|
expect(page).to have_field "Debate title", with: "Title in English"
|
||||||
|
|
||||||
select "Español", from: "locale-switcher"
|
select "Español", from: "Language:"
|
||||||
|
|
||||||
expect(page).to have_field "Título del debate", with: "Título corregido"
|
expect(page).to have_field "Título del debate", with: "Título corregido"
|
||||||
expect(page).to have_ckeditor "Texto inicial del debate", with: "Texto corregido"
|
expect(page).to have_ckeditor "Texto inicial del debate", with: "Texto corregido"
|
||||||
|
|||||||
Reference in New Issue
Block a user