diff options
Diffstat (limited to 'spec/helpers/ide_helper_spec.rb')
-rw-r--r-- | spec/helpers/ide_helper_spec.rb | 190 |
1 files changed, 104 insertions, 86 deletions
diff --git a/spec/helpers/ide_helper_spec.rb b/spec/helpers/ide_helper_spec.rb index e2ee4f33eee..e5a39f6a24e 100644 --- a/spec/helpers/ide_helper_spec.rb +++ b/spec/helpers/ide_helper_spec.rb @@ -6,117 +6,135 @@ RSpec.describe IdeHelper, feature_category: :web_ide do describe '#ide_data' do let_it_be(:project) { create(:project) } let_it_be(:user) { project.creator } + let_it_be(:fork_info) { { ide_path: '/test/ide/path' } } + + let_it_be(:params) do + { + branch: 'master', + path: 'foo/bar', + merge_request_id: '1' + } + end + + let(:base_data) do + { + 'can-use-new-web-ide' => 'false', + 'use-new-web-ide' => 'false', + 'user-preferences-path' => profile_preferences_path, + 'project' => nil, + 'preview-markdown-path' => nil + } + end before do allow(helper).to receive(:current_user).and_return(user) allow(helper).to receive(:content_security_policy_nonce).and_return('test-csp-nonce') end - context 'with vscode_web_ide=true and instance vars set' do - before do - stub_feature_flags(vscode_web_ide: true) - end + it 'returns hash' do + expect(helper.ide_data(project: nil, fork_info: fork_info, params: params)) + .to include(base_data) + end - it 'returns hash' do - expect(helper.ide_data(project: project, branch: 'master', path: 'foo/README.md', merge_request: '7', -fork_info: nil)) - .to match( - 'can-use-new-web-ide' => 'true', - 'use-new-web-ide' => 'true', - 'user-preferences-path' => profile_preferences_path, - 'new-web-ide-help-page-path' => - help_page_path('user/project/web_ide/index.md', anchor: 'vscode-reimplementation'), - 'branch-name' => 'master', - 'project-path' => project.path_with_namespace, - 'csp-nonce' => 'test-csp-nonce', - 'ide-remote-path' => ide_remote_path(remote_host: ':remote_host', remote_path: ':remote_path'), - 'file-path' => 'foo/README.md', - 'editor-font-family' => 'JetBrains Mono', - 'editor-font-format' => 'woff2', - 'editor-font-src-url' => a_string_matching(%r{jetbrains-mono/JetBrainsMono}), - 'merge-request' => '7', - 'fork-info' => nil - ) + context 'with project' do + it 'returns hash with parameters' do + serialized_project = API::Entities::Project.represent(project, current_user: user).to_json + + expect( + helper.ide_data(project: project, fork_info: nil, params: params) + ).to include(base_data.merge( + 'fork-info' => nil, + 'branch-name' => params[:branch], + 'file-path' => params[:path], + 'merge-request' => params[:merge_request_id], + 'project' => serialized_project, + 'preview-markdown-path' => Gitlab::Routing.url_helpers.preview_markdown_project_path(project) + )) end - it 'does not use new web ide if user.use_legacy_web_ide' do - allow(user).to receive(:use_legacy_web_ide).and_return(true) - - expect(helper.ide_data(project: project, branch: nil, path: nil, merge_request: nil, -fork_info: nil)).to include('use-new-web-ide' => 'false') + context 'with fork info' do + it 'returns hash with fork info' do + expect(helper.ide_data(project: project, fork_info: fork_info, params: params)) + .to include('fork-info' => fork_info.to_json) + end end end - context 'with vscode_web_ide=false' do + context 'with environments guidance experiment', :experiment do before do - stub_feature_flags(vscode_web_ide: false) + stub_experiments(in_product_guidance_environments_webide: :candidate) end - context 'when instance vars and parameters are not set' do - it 'returns instance data in the hash as nil' do - expect(helper.ide_data(project: nil, branch: nil, path: nil, merge_request: nil, fork_info: nil)) - .to include( - 'can-use-new-web-ide' => 'false', - 'use-new-web-ide' => 'false', - 'user-preferences-path' => profile_preferences_path, - 'branch-name' => nil, - 'file-path' => nil, - 'merge-request' => nil, - 'fork-info' => nil, - 'project' => nil, - 'preview-markdown-path' => nil - ) + context 'when project has no enviornments' do + it 'enables environment guidance' do + expect(helper.ide_data(project: project, fork_info: fork_info, params: params)) + .to include('enable-environments-guidance' => 'true') end - end - context 'when instance vars are set' do - it 'returns instance data in the hash' do - fork_info = { ide_path: '/test/ide/path' } - - serialized_project = API::Entities::Project.represent(project, current_user: project.creator).to_json - - expect(helper.ide_data(project: project, branch: 'master', path: 'foo/bar', merge_request: '1', -fork_info: fork_info)) - .to include( - 'branch-name' => 'master', - 'file-path' => 'foo/bar', - 'merge-request' => '1', - 'fork-info' => fork_info.to_json, - 'project' => serialized_project, - 'preview-markdown-path' => Gitlab::Routing.url_helpers.preview_markdown_project_path(project) - ) + context 'and the callout has been dismissed' do + it 'disables environment guidance' do + callout = create(:callout, feature_name: :web_ide_ci_environments_guidance, user: user) + callout.update!(dismissed_at: Time.now - 1.week) + allow(helper).to receive(:current_user).and_return(User.find(user.id)) + + expect(helper.ide_data(project: project, fork_info: fork_info, params: params)) + .to include('enable-environments-guidance' => 'false') + end end end - context 'environments guidance experiment', :experiment do - before do - stub_experiments(in_product_guidance_environments_webide: :candidate) + context 'when the project has environments' do + it 'disables environment guidance' do + create(:environment, project: project) + + expect(helper.ide_data(project: project, fork_info: fork_info, params: params)) + .to include('enable-environments-guidance' => 'false') end + end + end - context 'when project has no enviornments' do - it 'enables environment guidance' do - expect(helper.ide_data(project: project, branch: nil, path: nil, merge_request: nil, -fork_info: nil)).to include('enable-environments-guidance' => 'true') - end + context 'with vscode_web_ide=true' do + let(:base_data) do + { + 'can-use-new-web-ide' => 'true', + 'use-new-web-ide' => 'true', + 'user-preferences-path' => profile_preferences_path, + 'new-web-ide-help-page-path' => + help_page_path('user/project/web_ide/index.md', anchor: 'vscode-reimplementation'), + 'csp-nonce' => 'test-csp-nonce', + 'ide-remote-path' => ide_remote_path(remote_host: ':remote_host', remote_path: ':remote_path'), + 'editor-font-family' => 'JetBrains Mono', + 'editor-font-format' => 'woff2', + 'editor-font-src-url' => a_string_matching(%r{jetbrains-mono/JetBrainsMono}) + } + end - context 'and the callout has been dismissed' do - it 'disables environment guidance' do - callout = create(:callout, feature_name: :web_ide_ci_environments_guidance, user: project.creator) - callout.update!(dismissed_at: Time.now - 1.week) - allow(helper).to receive(:current_user).and_return(User.find(project.creator.id)) - expect(helper.ide_data(project: project, branch: nil, path: nil, merge_request: nil, -fork_info: nil)).to include('enable-environments-guidance' => 'false') - end - end - end + before do + stub_feature_flags(vscode_web_ide: true) + end - context 'when the project has environments' do - it 'disables environment guidance' do - create(:environment, project: project) + it 'returns hash' do + expect(helper.ide_data(project: nil, fork_info: fork_info, params: params)) + .to include(base_data) + end - expect(helper.ide_data(project: project, branch: nil, path: nil, merge_request: nil, -fork_info: nil)).to include('enable-environments-guidance' => 'false') - end + it 'does not use new web ide if user.use_legacy_web_ide' do + allow(user).to receive(:use_legacy_web_ide).and_return(true) + + expect(helper.ide_data(project: nil, fork_info: fork_info, params: params)) + .to include('use-new-web-ide' => 'false') + end + + context 'with project' do + it 'returns hash with parameters' do + expect( + helper.ide_data(project: project, fork_info: nil, params: params) + ).to include(base_data.merge( + 'branch-name' => params[:branch], + 'file-path' => params[:path], + 'merge-request' => params[:merge_request_id], + 'fork-info' => nil + )) end end end |