2021-03-05 10:09:12 -05:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
require 'spec_helper'
|
|
|
|
|
|
|
|
RSpec.describe IdeHelper do
|
|
|
|
describe '#ide_data' do
|
|
|
|
let_it_be(:project) { create(:project) }
|
2022-10-18 17:09:37 -04:00
|
|
|
let_it_be(:user) { project.creator }
|
2021-03-05 10:09:12 -05:00
|
|
|
|
|
|
|
before do
|
2022-10-18 17:09:37 -04:00
|
|
|
allow(helper).to receive(:current_user).and_return(user)
|
|
|
|
allow(helper).to receive(:content_security_policy_nonce).and_return('test-csp-nonce')
|
2021-03-05 10:09:12 -05:00
|
|
|
end
|
|
|
|
|
2022-10-18 17:09:37 -04:00
|
|
|
context 'with vscode_web_ide=true and instance vars set' do
|
|
|
|
before do
|
|
|
|
stub_feature_flags(vscode_web_ide: true)
|
2021-03-22 20:09:09 -04:00
|
|
|
|
2021-03-05 10:09:12 -05:00
|
|
|
self.instance_variable_set(:@branch, 'master')
|
|
|
|
self.instance_variable_set(:@project, project)
|
2022-10-18 17:09:37 -04:00
|
|
|
end
|
2021-03-05 10:09:12 -05:00
|
|
|
|
2022-10-18 17:09:37 -04:00
|
|
|
it 'returns hash' do
|
2021-03-05 10:09:12 -05:00
|
|
|
expect(helper.ide_data)
|
2022-10-18 17:09:37 -04:00
|
|
|
.to eq(
|
|
|
|
'can-use-new-web-ide' => 'true',
|
|
|
|
'use-new-web-ide' => 'true',
|
|
|
|
'user-preferences-path' => profile_preferences_path,
|
2021-03-05 10:09:12 -05:00
|
|
|
'branch-name' => 'master',
|
2022-10-18 17:09:37 -04:00
|
|
|
'project-path' => project.path_with_namespace,
|
|
|
|
'csp-nonce' => 'test-csp-nonce'
|
2021-03-05 10:09:12 -05:00
|
|
|
)
|
|
|
|
end
|
2022-10-18 17:09:37 -04:00
|
|
|
|
|
|
|
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).to include('use-new-web-ide' => 'false')
|
|
|
|
end
|
2021-03-05 10:09:12 -05:00
|
|
|
end
|
2021-05-07 17:10:34 -04:00
|
|
|
|
2022-10-18 17:09:37 -04:00
|
|
|
context 'with vscode_web_ide=false' do
|
2021-05-07 17:10:34 -04:00
|
|
|
before do
|
2022-10-18 17:09:37 -04:00
|
|
|
stub_feature_flags(vscode_web_ide: false)
|
2021-05-07 17:10:34 -04:00
|
|
|
end
|
|
|
|
|
2022-10-18 17:09:37 -04:00
|
|
|
context 'when instance vars are not set' do
|
|
|
|
it 'returns instance data in the hash as nil' do
|
|
|
|
expect(helper.ide_data)
|
|
|
|
.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-05-07 17:10:34 -04:00
|
|
|
end
|
2022-10-18 17:09:37 -04:00
|
|
|
end
|
2021-05-07 17:10:34 -04:00
|
|
|
|
2022-10-18 17:09:37 -04:00
|
|
|
context 'when instance vars are set' do
|
|
|
|
it 'returns instance data in the hash' do
|
|
|
|
fork_info = { ide_path: '/test/ide/path' }
|
|
|
|
|
|
|
|
self.instance_variable_set(:@branch, 'master')
|
|
|
|
self.instance_variable_set(:@path, 'foo/bar')
|
|
|
|
self.instance_variable_set(:@merge_request, '1')
|
|
|
|
self.instance_variable_set(:@fork_info, fork_info)
|
|
|
|
self.instance_variable_set(:@project, project)
|
|
|
|
|
|
|
|
serialized_project = API::Entities::Project.represent(project, current_user: project.creator).to_json
|
|
|
|
|
|
|
|
expect(helper.ide_data)
|
|
|
|
.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-05-07 17:10:34 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2022-10-18 17:09:37 -04:00
|
|
|
context 'environments guidance experiment', :experiment do
|
|
|
|
before do
|
|
|
|
stub_experiments(in_product_guidance_environments_webide: :candidate)
|
|
|
|
self.instance_variable_set(:@project, project)
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when project has no enviornments' do
|
|
|
|
it 'enables environment guidance' do
|
|
|
|
expect(helper.ide_data).to include('enable-environments-guidance' => 'true')
|
|
|
|
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).to include('enable-environments-guidance' => 'false')
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2021-05-07 17:10:34 -04:00
|
|
|
|
2022-10-18 17:09:37 -04:00
|
|
|
context 'when the project has environments' do
|
|
|
|
it 'disables environment guidance' do
|
|
|
|
create(:environment, project: project)
|
|
|
|
|
|
|
|
expect(helper.ide_data).to include('enable-environments-guidance' => 'false')
|
|
|
|
end
|
2021-05-07 17:10:34 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2021-03-05 10:09:12 -05:00
|
|
|
end
|
|
|
|
end
|