Commit 432c58ce authored by James Lopez's avatar James Lopez

Merge branch '323233-fix-translation-of-visibility-levels' into 'master'

Resolve "Fix translation of visibility levels" [RUN ALL RSPEC]

See merge request gitlab-org/gitlab!55721
parents bc3a5ae5 a63ad4e4
...@@ -35,9 +35,7 @@ module VisibilityLevelHelper ...@@ -35,9 +35,7 @@ module VisibilityLevelHelper
end end
def visibility_level_label(level) def visibility_level_label(level)
# The visibility level can be: Project.visibility_levels.key(level)
# 'VisibilityLevel|Private', 'VisibilityLevel|Internal', 'VisibilityLevel|Public'
s_(Project.visibility_levels.key(level))
end end
def restricted_visibility_levels(show_all = false) def restricted_visibility_levels(show_all = false)
......
...@@ -44,9 +44,9 @@ module Gitlab ...@@ -44,9 +44,9 @@ module Gitlab
def options def options
{ {
N_('VisibilityLevel|Private') => PRIVATE, s_('VisibilityLevel|Private') => PRIVATE,
N_('VisibilityLevel|Internal') => INTERNAL, s_('VisibilityLevel|Internal') => INTERNAL,
N_('VisibilityLevel|Public') => PUBLIC s_('VisibilityLevel|Public') => PUBLIC
} }
end end
...@@ -104,12 +104,7 @@ module Gitlab ...@@ -104,12 +104,7 @@ module Gitlab
end end
def level_name(level) def level_name(level)
level_name = N_('VisibilityLevel|Unknown') options.key(level.to_i) || s_('VisibilityLevel|Unknown')
options.each do |name, lvl|
level_name = name if lvl == level.to_i
end
s_(level_name)
end end
def level_value(level) def level_value(level)
......
...@@ -86,7 +86,7 @@ RSpec.describe 'New project', :js do ...@@ -86,7 +86,7 @@ RSpec.describe 'New project', :js do
visit new_project_path visit new_project_path
find('[data-qa-selector="blank_project_link"]').click find('[data-qa-selector="blank_project_link"]').click
choose(s_(key)) choose(key)
click_button('Create project') click_button('Create project')
page.within('#blank-project-pane') do page.within('#blank-project-pane') do
expect(find_field("project_visibility_level_#{level}")).to be_checked expect(find_field("project_visibility_level_#{level}")).to be_checked
......
...@@ -33,6 +33,22 @@ RSpec.describe VisibilityLevelHelper do ...@@ -33,6 +33,22 @@ RSpec.describe VisibilityLevelHelper do
end end
end end
describe 'visibility_level_label' do
using RSpec::Parameterized::TableSyntax
where(:level_value, :level_name) do
Gitlab::VisibilityLevel::PRIVATE | 'Private'
Gitlab::VisibilityLevel::INTERNAL | 'Internal'
Gitlab::VisibilityLevel::PUBLIC | 'Public'
end
with_them do
it 'returns the name of the visibility level' do
expect(visibility_level_label(level_value)).to eq(level_name)
end
end
end
describe 'visibility_level_description' do describe 'visibility_level_description' do
context 'used with a Project' do context 'used with a Project' do
let(:descriptions) do let(:descriptions) do
......
...@@ -131,4 +131,29 @@ RSpec.describe Gitlab::VisibilityLevel do ...@@ -131,4 +131,29 @@ RSpec.describe Gitlab::VisibilityLevel do
end end
end end
end end
describe '.options' do
context 'keys' do
it 'returns the allowed visibility levels' do
expect(described_class.options.keys).to contain_exactly('Private', 'Internal', 'Public')
end
end
end
describe '.level_name' do
using RSpec::Parameterized::TableSyntax
where(:level_value, :level_name) do
described_class::PRIVATE | 'Private'
described_class::INTERNAL | 'Internal'
described_class::PUBLIC | 'Public'
non_existing_record_access_level | 'Unknown'
end
with_them do
it 'returns the name of the visibility level' do
expect(described_class.level_name(level_value)).to eq(level_name)
end
end
end
end end
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment