Commit cf2e06aa authored by Denys Mishunov's avatar Denys Mishunov

Introduced the snippets_vue feature flag

Moved pushing the FE feature flag

Now, instead of doing ot from Snippets controller, we do it from
gon_helper to make it shared between all types of snippets
parent b178a781
...@@ -5,9 +5,11 @@ import initNotes from '~/init_notes'; ...@@ -5,9 +5,11 @@ import initNotes from '~/init_notes';
import snippetEmbed from '~/snippet/snippet_embed'; import snippetEmbed from '~/snippet/snippet_embed';
document.addEventListener('DOMContentLoaded', () => { document.addEventListener('DOMContentLoaded', () => {
if (!gon.features.snippetsVue) {
new LineHighlighter(); // eslint-disable-line no-new new LineHighlighter(); // eslint-disable-line no-new
new BlobViewer(); // eslint-disable-line no-new new BlobViewer(); // eslint-disable-line no-new
initNotes(); initNotes();
new ZenMode(); // eslint-disable-line no-new new ZenMode(); // eslint-disable-line no-new
snippetEmbed(); snippetEmbed();
}
}); });
...@@ -4,9 +4,12 @@ ...@@ -4,9 +4,12 @@
- breadcrumb_title @snippet.to_reference - breadcrumb_title @snippet.to_reference
- page_title "#{@snippet.title} (#{@snippet.to_reference})", _("Snippets") - page_title "#{@snippet.title} (#{@snippet.to_reference})", _("Snippets")
= render 'shared/snippets/header' - if Feature.enabled?(:snippets_vue)
#js-snippet-view{ 'data-qa-selector': 'snippet_view' }
- else
= render 'shared/snippets/header'
.personal-snippets .personal-snippets
%article.file-holder.snippet-file-content %article.file-holder.snippet-file-content
= render 'shared/snippets/blob' = render 'shared/snippets/blob'
......
...@@ -42,6 +42,7 @@ module Gitlab ...@@ -42,6 +42,7 @@ module Gitlab
# Initialize gon.features with any flags that should be # Initialize gon.features with any flags that should be
# made globally available to the frontend # made globally available to the frontend
push_frontend_feature_flag(:suppress_ajax_navigation_errors, default_enabled: true) push_frontend_feature_flag(:suppress_ajax_navigation_errors, default_enabled: true)
push_frontend_feature_flag(:snippets_vue, default_enabled: false)
end end
# Exposes the state of a feature flag to the frontend code. # Exposes the state of a feature flag to the frontend code.
......
...@@ -5,6 +5,10 @@ require 'spec_helper' ...@@ -5,6 +5,10 @@ require 'spec_helper'
describe 'Internal Snippets', :js do describe 'Internal Snippets', :js do
let(:internal_snippet) { create(:personal_snippet, :internal) } let(:internal_snippet) { create(:personal_snippet, :internal) }
before do
stub_feature_flags(snippets_vue: false)
end
describe 'normal user' do describe 'normal user' do
before do before do
sign_in(create(:user)) sign_in(create(:user))
......
...@@ -16,6 +16,7 @@ describe 'Comments on personal snippets', :js do ...@@ -16,6 +16,7 @@ describe 'Comments on personal snippets', :js do
let!(:other_note) { create(:note_on_personal_snippet) } let!(:other_note) { create(:note_on_personal_snippet) }
before do before do
stub_feature_flags(snippets_vue: false)
sign_in user sign_in user
visit snippet_path(snippet) visit snippet_path(snippet)
......
...@@ -6,6 +6,7 @@ describe 'Private Snippets', :js do ...@@ -6,6 +6,7 @@ describe 'Private Snippets', :js do
let(:user) { create(:user) } let(:user) { create(:user) }
before do before do
stub_feature_flags(snippets_vue: false)
sign_in(user) sign_in(user)
end end
......
...@@ -3,6 +3,10 @@ ...@@ -3,6 +3,10 @@
require 'spec_helper' require 'spec_helper'
describe 'Public Snippets', :js do describe 'Public Snippets', :js do
before do
stub_feature_flags(snippets_vue: false)
end
it 'Unauthenticated user should see public snippets' do it 'Unauthenticated user should see public snippets' do
public_snippet = create(:personal_snippet, :public) public_snippet = create(:personal_snippet, :public)
......
...@@ -6,6 +6,10 @@ describe 'Snippet', :js do ...@@ -6,6 +6,10 @@ describe 'Snippet', :js do
let(:project) { create(:project, :repository) } let(:project) { create(:project, :repository) }
let(:snippet) { create(:personal_snippet, :public, file_name: file_name, content: content) } let(:snippet) { create(:personal_snippet, :public, file_name: file_name, content: content) }
before do
stub_feature_flags(snippets_vue: false)
end
context 'Ruby file' do context 'Ruby file' do
let(:file_name) { 'popen.rb' } let(:file_name) { 'popen.rb' }
let(:content) { project.repository.blob_at('master', 'files/ruby/popen.rb').data } let(:content) { project.repository.blob_at('master', 'files/ruby/popen.rb').data }
......
...@@ -7,6 +7,7 @@ describe 'User creates snippet', :js do ...@@ -7,6 +7,7 @@ describe 'User creates snippet', :js do
before do before do
stub_feature_flags(allow_possible_spam: false) stub_feature_flags(allow_possible_spam: false)
stub_feature_flags(snippets_vue: false)
stub_env('IN_MEMORY_APPLICATION_SETTINGS', 'false') stub_env('IN_MEMORY_APPLICATION_SETTINGS', 'false')
Gitlab::CurrentSettings.update!( Gitlab::CurrentSettings.update!(
......
...@@ -8,6 +8,7 @@ describe 'User creates snippet', :js do ...@@ -8,6 +8,7 @@ describe 'User creates snippet', :js do
let(:user) { create(:user) } let(:user) { create(:user) }
before do before do
stub_feature_flags(snippets_vue: false)
sign_in(user) sign_in(user)
visit new_snippet_path visit new_snippet_path
end end
......
...@@ -10,6 +10,8 @@ describe 'User deletes snippet' do ...@@ -10,6 +10,8 @@ describe 'User deletes snippet' do
before do before do
sign_in(user) sign_in(user)
stub_feature_flags(snippets_vue: false)
visit snippet_path(snippet) visit snippet_path(snippet)
end end
......
...@@ -12,6 +12,7 @@ describe 'User edits snippet', :js do ...@@ -12,6 +12,7 @@ describe 'User edits snippet', :js do
let(:snippet) { create(:personal_snippet, :public, file_name: file_name, content: content, author: user) } let(:snippet) { create(:personal_snippet, :public, file_name: file_name, content: content, author: user) }
before do before do
stub_feature_flags(snippets_vue: false)
sign_in(user) sign_in(user)
visit edit_snippet_path(snippet) visit edit_snippet_path(snippet)
......
...@@ -13,4 +13,34 @@ describe 'Snippets' do ...@@ -13,4 +13,34 @@ describe 'Snippets' do
it_behaves_like 'paginated snippets' it_behaves_like 'paginated snippets'
end end
describe 'when feature flag is enabled' do
let(:user) { create(:user) }
let!(:snippets) { create(:personal_snippet, :public, author: user) }
before do
stub_feature_flags(snippets_vue: true)
visit snippet_path(1)
end
it 'should render Vue application' do
expect(page).to have_selector('#js-snippet-view')
expect(page).not_to have_selector('.personal-snippets')
end
end
describe 'when feature flag is disabled' do
let(:user) { create(:user) }
let!(:snippets) { create(:personal_snippet, :public, author: user) }
before do
stub_feature_flags(snippets_vue: false)
visit snippet_path(1)
end
it 'should render HAML application and not Vue' do
expect(page).not_to have_selector('#js-snippet-view')
expect(page).to have_selector('.personal-snippets')
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