Commit 4237065f authored by Shinya Maeda's avatar Shinya Maeda

Merge branch 'ff-sort-strategies-in-ui' into 'master'

Sort Feature Flag Strategies by ID for Display in UI

See merge request gitlab-org/gitlab!29629
parents 5436f298 9a56febd
...@@ -28,7 +28,9 @@ class FeatureFlagEntity < Grape::Entity ...@@ -28,7 +28,9 @@ class FeatureFlagEntity < Grape::Entity
feature_flag.scopes.sort_by(&:id) feature_flag.scopes.sort_by(&:id)
end end
expose :strategies, with: FeatureFlags::StrategyEntity expose :strategies, with: FeatureFlags::StrategyEntity do |feature_flag|
feature_flag.strategies.sort_by(&:id)
end
private private
......
...@@ -358,6 +358,15 @@ describe Projects::FeatureFlagsController do ...@@ -358,6 +358,15 @@ describe Projects::FeatureFlagsController do
expect(response).to have_gitlab_http_status(:not_found) expect(response).to have_gitlab_http_status(:not_found)
end end
it 'returns strategies ordered by id' do
first_strategy = create(:operations_strategy, feature_flag: new_version_feature_flag)
second_strategy = create(:operations_strategy, feature_flag: new_version_feature_flag)
subject
expect(json_response['strategies'].map { |s| s['id'] }).to eq([first_strategy.id, second_strategy.id])
end
end end
end end
......
...@@ -31,6 +31,25 @@ describe 'User creates feature flag', :js do ...@@ -31,6 +31,25 @@ describe 'User creates feature flag', :js do
expect(page).to have_text('test_feature') expect(page).to have_text('test_feature')
end end
it 'user creates a flag with default environment scopes' do
visit(new_project_feature_flag_path(project))
set_feature_flag_info('test_flag', 'Test flag')
within_strategy_row(1) do
select 'All users', from: 'Type'
end
click_button 'Create feature flag'
expect_user_to_see_feature_flags_index_page
expect(page).to have_text('test_flag')
edit_feature_flag_button.click
within_strategy_row(1) do
expect(page).to have_text('All users')
expect(page).to have_text('All environments')
end
end
context 'with new version flags disabled' do context 'with new version flags disabled' do
before do before do
stub_feature_flags(feature_flags_new_version: false) stub_feature_flags(feature_flags_new_version: false)
......
...@@ -8,6 +8,52 @@ describe 'User updates feature flag', :js do ...@@ -8,6 +8,52 @@ describe 'User updates feature flag', :js do
let(:user) { create(:user) } let(:user) { create(:user) }
let(:project) { create(:project, namespace: user.namespace) } let(:project) { create(:project, namespace: user.namespace) }
before do
project.add_developer(user)
stub_licensed_features(feature_flags: true)
stub_feature_flags(feature_flag_permissions: false)
sign_in(user)
end
context 'with a new version feature flag' do
let!(:feature_flag) do
create_flag(project, 'test_flag', true, version: Operations::FeatureFlag.versions['new_version_flag'],
description: 'For testing')
end
let!(:strategy) do
create(:operations_strategy, feature_flag: feature_flag,
name: 'default', parameters: {})
end
let!(:scope) do
create(:operations_scope, strategy: strategy, environment_scope: '*')
end
it 'user adds a second strategy' do
visit(edit_project_feature_flag_path(project, feature_flag))
click_button 'Add strategy'
within_strategy_row(2) do
select 'Percent rollout (logged in users)', from: 'Type'
fill_in 'Percentage', with: '15'
end
click_button 'Save changes'
edit_feature_flag_button.click
within_strategy_row(1) do
expect(page).to have_text 'All users'
expect(page).to have_text 'All environments'
end
within_strategy_row(2) do
expect(page).to have_text 'Percent rollout (logged in users)'
expect(page).to have_field 'Percentage', with: '15'
expect(page).to have_text 'All environments'
end
end
end
context 'with a legacy feature flag' do
let!(:feature_flag) do let!(:feature_flag) do
create_flag(project, 'ci_live_trace', true, create_flag(project, 'ci_live_trace', true,
description: 'For live trace feature') description: 'For live trace feature')
...@@ -16,11 +62,6 @@ describe 'User updates feature flag', :js do ...@@ -16,11 +62,6 @@ describe 'User updates feature flag', :js do
let!(:scope) { create_scope(feature_flag, 'review/*', true) } let!(:scope) { create_scope(feature_flag, 'review/*', true) }
before do before do
project.add_developer(user)
stub_licensed_features(feature_flags: true)
stub_feature_flags(feature_flag_permissions: false)
sign_in(user)
visit(edit_project_feature_flag_path(project, feature_flag)) visit(edit_project_feature_flag_path(project, feature_flag))
end end
...@@ -128,4 +169,5 @@ describe 'User updates feature flag', :js do ...@@ -128,4 +169,5 @@ describe 'User updates feature flag', :js do
) )
end end
end end
end
end end
# frozen_string_literal: true # frozen_string_literal: true
module FeatureFlagHelpers module FeatureFlagHelpers
def create_flag(project, name, active = true, description: nil) def create_flag(project, name, active = true, description: nil, version: Operations::FeatureFlag.versions['legacy_flag'])
create(:operations_feature_flag, name: name, active: active, create(:operations_feature_flag, name: name, active: active, version: version,
description: description, project: project) description: description, project: project)
end end
...@@ -56,6 +56,10 @@ module FeatureFlagHelpers ...@@ -56,6 +56,10 @@ module FeatureFlagHelpers
end end
end end
def edit_feature_flag_button
find('.js-feature-flag-edit-button')
end
def expect_user_to_see_feature_flags_index_page def expect_user_to_see_feature_flags_index_page
expect(page).to have_css('h3.page-title', text: 'Feature Flags') expect(page).to have_css('h3.page-title', text: 'Feature Flags')
expect(page).to have_text('All') expect(page).to have_text('All')
......
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