debian-mirror-gitlab/spec/helpers/ide_helper_spec.rb

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

125 lines
4.8 KiB
Ruby
Raw Normal View History

2021-04-17 20:07:23 +05:30
# frozen_string_literal: true
require 'spec_helper'
2023-03-04 22:38:38 +05:30
RSpec.describe IdeHelper, feature_category: :web_ide do
2021-04-17 20:07:23 +05:30
describe '#ide_data' do
let_it_be(:project) { create(:project) }
2022-11-25 23:54:43 +05:30
let_it_be(:user) { project.creator }
2021-04-17 20:07:23 +05:30
before do
2022-11-25 23:54:43 +05:30
allow(helper).to receive(:current_user).and_return(user)
allow(helper).to receive(:content_security_policy_nonce).and_return('test-csp-nonce')
2021-04-17 20:07:23 +05:30
end
2022-11-25 23:54:43 +05:30
context 'with vscode_web_ide=true and instance vars set' do
before do
stub_feature_flags(vscode_web_ide: true)
end
2021-04-17 20:07:23 +05:30
2022-11-25 23:54:43 +05:30
it 'returns hash' do
2023-04-23 21:23:45 +05:30
expect(helper.ide_data(project: project, branch: 'master', path: 'foo/README.md', merge_request: '7',
fork_info: nil))
.to match(
2022-11-25 23:54:43 +05:30
'can-use-new-web-ide' => 'true',
'use-new-web-ide' => 'true',
'user-preferences-path' => profile_preferences_path,
2023-01-13 00:05:48 +05:30
'new-web-ide-help-page-path' =>
help_page_path('user/project/web_ide/index.md', anchor: 'vscode-reimplementation'),
2021-04-17 20:07:23 +05:30
'branch-name' => 'master',
2022-11-25 23:54:43 +05:30
'project-path' => project.path_with_namespace,
2023-03-04 22:38:38 +05:30
'csp-nonce' => 'test-csp-nonce',
'ide-remote-path' => ide_remote_path(remote_host: ':remote_host', remote_path: ':remote_path'),
'file-path' => 'foo/README.md',
2023-04-23 21:23:45 +05:30
'editor-font-family' => 'JetBrains Mono',
'editor-font-format' => 'woff2',
'editor-font-src-url' => a_string_matching(%r{jetbrains-mono/JetBrainsMono}),
2023-03-04 22:38:38 +05:30
'merge-request' => '7',
'fork-info' => nil
2021-04-17 20:07:23 +05:30
)
end
2022-11-25 23:54:43 +05:30
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)
2023-04-23 21:23:45 +05:30
expect(helper.ide_data(project: project, branch: nil, path: nil, merge_request: nil,
fork_info: nil)).to include('use-new-web-ide' => 'false')
2022-11-25 23:54:43 +05:30
end
2021-04-17 20:07:23 +05:30
end
2021-06-08 01:23:25 +05:30
2022-11-25 23:54:43 +05:30
context 'with vscode_web_ide=false' do
2021-06-08 01:23:25 +05:30
before do
2022-11-25 23:54:43 +05:30
stub_feature_flags(vscode_web_ide: false)
2021-06-08 01:23:25 +05:30
end
2023-04-23 21:23:45 +05:30
context 'when instance vars and parameters are not set' do
2022-11-25 23:54:43 +05:30
it 'returns instance data in the hash as nil' do
2023-04-23 21:23:45 +05:30
expect(helper.ide_data(project: nil, branch: nil, path: nil, merge_request: nil, fork_info: nil))
2022-11-25 23:54:43 +05:30
.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
)
2021-06-08 01:23:25 +05:30
end
2022-11-25 23:54:43 +05:30
end
2021-06-08 01:23:25 +05:30
2022-11-25 23:54:43 +05:30
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
2023-04-23 21:23:45 +05:30
expect(helper.ide_data(project: project, branch: 'master', path: 'foo/bar', merge_request: '1',
fork_info: fork_info))
2022-11-25 23:54:43 +05:30
.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)
)
2021-06-08 01:23:25 +05:30
end
end
2022-11-25 23:54:43 +05:30
context 'environments guidance experiment', :experiment do
before do
stub_experiments(in_product_guidance_environments_webide: :candidate)
end
context 'when project has no enviornments' do
it 'enables environment guidance' do
2023-04-23 21:23:45 +05:30
expect(helper.ide_data(project: project, branch: nil, path: nil, merge_request: nil,
fork_info: nil)).to include('enable-environments-guidance' => 'true')
2022-11-25 23:54:43 +05:30
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))
2023-04-23 21:23:45 +05:30
expect(helper.ide_data(project: project, branch: nil, path: nil, merge_request: nil,
fork_info: nil)).to include('enable-environments-guidance' => 'false')
2022-11-25 23:54:43 +05:30
end
end
end
2021-06-08 01:23:25 +05:30
2022-11-25 23:54:43 +05:30
context 'when the project has environments' do
it 'disables environment guidance' do
create(:environment, project: project)
2023-04-23 21:23:45 +05:30
expect(helper.ide_data(project: project, branch: nil, path: nil, merge_request: nil,
fork_info: nil)).to include('enable-environments-guidance' => 'false')
2022-11-25 23:54:43 +05:30
end
2021-06-08 01:23:25 +05:30
end
end
end
2021-04-17 20:07:23 +05:30
end
end