diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2020-02-28 18:09:13 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2020-02-28 18:09:13 +0300 |
commit | 736d36d8597d0d1ec1b47644e6d091c3f4a78f45 (patch) | |
tree | a38f6fef2b7147416b31f8294a9389b3bb472c87 /spec | |
parent | 5426ca9908085087d465fa52800335f408eb965a (diff) |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec')
-rw-r--r-- | spec/features/projects/snippets/create_snippet_spec.rb | 32 | ||||
-rw-r--r-- | spec/features/snippets/spam_snippets_spec.rb | 24 | ||||
-rw-r--r-- | spec/features/snippets/user_creates_snippet_spec.rb | 31 | ||||
-rw-r--r-- | spec/frontend/snippet/snippet_bundle_spec.js | 94 | ||||
-rw-r--r-- | spec/lib/gitlab/profiler_spec.rb | 26 | ||||
-rw-r--r-- | spec/requests/api/projects_spec.rb | 2 | ||||
-rw-r--r-- | spec/services/deployments/link_merge_requests_service_spec.rb | 28 |
7 files changed, 208 insertions, 29 deletions
diff --git a/spec/features/projects/snippets/create_snippet_spec.rb b/spec/features/projects/snippets/create_snippet_spec.rb index 40c54b2f873..ee312a5811d 100644 --- a/spec/features/projects/snippets/create_snippet_spec.rb +++ b/spec/features/projects/snippets/create_snippet_spec.rb @@ -2,11 +2,10 @@ require 'spec_helper' -describe 'Projects > Snippets > Create Snippet', :js do - include DropzoneHelper - - let_it_be(:user) { create(:user) } - let_it_be(:project) { create(:project, :public) } +shared_examples_for 'snippet editor' do + before do + stub_feature_flags(monaco_snippets: flag) + end def description_field find('.js-description-input').find('input,textarea') @@ -20,7 +19,8 @@ describe 'Projects > Snippets > Create Snippet', :js do fill_in 'project_snippet_description', with: 'My Snippet **Description**' page.within('.file-editor') do - find('.ace_text-input', visible: false).send_keys('Hello World!') + el = flag == true ? find('.inputarea') : find('.ace_text-input', visible: false) + el.send_keys 'Hello World!' end end @@ -33,6 +33,7 @@ describe 'Projects > Snippets > Create Snippet', :js do visit project_snippets_path(project) click_on('New snippet') + wait_for_requests end it 'shows collapsible description input' do @@ -111,3 +112,22 @@ describe 'Projects > Snippets > Create Snippet', :js do end end end + +describe 'Projects > Snippets > Create Snippet', :js do + include DropzoneHelper + + let_it_be(:user) { create(:user) } + let_it_be(:project) { create(:project, :public) } + + context 'when using Monaco' do + it_behaves_like "snippet editor" do + let(:flag) { true } + end + end + + context 'when using ACE' do + it_behaves_like "snippet editor" do + let(:flag) { false } + end + end +end diff --git a/spec/features/snippets/spam_snippets_spec.rb b/spec/features/snippets/spam_snippets_spec.rb index 02b807ce071..efe1bdc963d 100644 --- a/spec/features/snippets/spam_snippets_spec.rb +++ b/spec/features/snippets/spam_snippets_spec.rb @@ -2,9 +2,7 @@ require 'spec_helper' -describe 'User creates snippet', :js do - let(:user) { create(:user) } - +shared_examples_for 'snippet editor' do def description_field find('.js-description-input').find('input,textarea') end @@ -12,6 +10,7 @@ describe 'User creates snippet', :js do before do stub_feature_flags(allow_possible_spam: false) stub_feature_flags(snippets_vue: false) + stub_feature_flags(monaco_snippets: flag) stub_env('IN_MEMORY_APPLICATION_SETTINGS', 'false') Gitlab::CurrentSettings.update!( @@ -33,7 +32,8 @@ describe 'User creates snippet', :js do find('#personal_snippet_visibility_level_20').set(true) page.within('.file-editor') do - find('.ace_text-input', visible: false).send_keys 'Hello World!' + el = flag == true ? find('.inputarea') : find('.ace_text-input', visible: false) + el.send_keys 'Hello World!' end end @@ -80,3 +80,19 @@ describe 'User creates snippet', :js do end end end + +describe 'User creates snippet', :js do + let_it_be(:user) { create(:user) } + + context 'when using Monaco' do + it_behaves_like "snippet editor" do + let(:flag) { true } + end + end + + context 'when using ACE' do + it_behaves_like "snippet editor" do + let(:flag) { false } + end + end +end diff --git a/spec/features/snippets/user_creates_snippet_spec.rb b/spec/features/snippets/user_creates_snippet_spec.rb index 69a44513e7f..88f7896bfa6 100644 --- a/spec/features/snippets/user_creates_snippet_spec.rb +++ b/spec/features/snippets/user_creates_snippet_spec.rb @@ -2,13 +2,10 @@ require 'spec_helper' -describe 'User creates snippet', :js do - include DropzoneHelper - - let(:user) { create(:user) } - +shared_examples_for 'snippet editor' do before do stub_feature_flags(snippets_vue: false) + stub_feature_flags(monaco_snippets: flag) sign_in(user) visit new_snippet_path end @@ -25,7 +22,8 @@ describe 'User creates snippet', :js do fill_in 'personal_snippet_description', with: 'My Snippet **Description**' page.within('.file-editor') do - find('.ace_text-input', visible: false).send_keys 'Hello World!' + el = flag == true ? find('.inputarea') : find('.ace_text-input', visible: false) + el.send_keys 'Hello World!' end end @@ -109,7 +107,8 @@ describe 'User creates snippet', :js do fill_in 'personal_snippet_title', with: 'My Snippet Title' page.within('.file-editor') do find(:xpath, "//input[@id='personal_snippet_file_name']").set 'snippet+file+name' - find('.ace_text-input', visible: false).send_keys 'Hello World!' + el = flag == true ? find('.inputarea') : find('.ace_text-input', visible: false) + el.send_keys 'Hello World!' end click_button 'Create snippet' @@ -120,3 +119,21 @@ describe 'User creates snippet', :js do expect(page).to have_content('Hello World!') end end + +describe 'User creates snippet', :js do + include DropzoneHelper + + let_it_be(:user) { create(:user) } + + context 'when using Monaco' do + it_behaves_like "snippet editor" do + let(:flag) { true } + end + end + + context 'when using ACE' do + it_behaves_like "snippet editor" do + let(:flag) { false } + end + end +end diff --git a/spec/frontend/snippet/snippet_bundle_spec.js b/spec/frontend/snippet/snippet_bundle_spec.js new file mode 100644 index 00000000000..af98e8d665d --- /dev/null +++ b/spec/frontend/snippet/snippet_bundle_spec.js @@ -0,0 +1,94 @@ +import Editor from '~/editor/editor_lite'; +import { initEditor } from '~/snippet/snippet_bundle'; +import { setHTMLFixture } from 'helpers/fixtures'; + +jest.mock('~/editor/editor_lite', () => jest.fn()); + +describe('Snippet editor', () => { + describe('Monaco editor for Snippets', () => { + let oldGon; + let editorEl; + let contentEl; + let fileNameEl; + let form; + + const mockName = 'foo.bar'; + const mockContent = 'Foo Bar'; + const updatedMockContent = 'New Foo Bar'; + + const mockEditor = { + createInstance: jest.fn(), + updateModelLanguage: jest.fn(), + getValue: jest.fn().mockReturnValueOnce(updatedMockContent), + }; + Editor.mockImplementation(() => mockEditor); + + function setUpFixture(name, content) { + setHTMLFixture(` + <div class="snippet-form-holder"> + <form> + <input class="snippet-file-name" type="text" value="${name}"> + <input class="snippet-file-content" type="hidden" value="${content}"> + <pre id="editor"></pre> + </form> + </div> + `); + } + + function bootstrap(name = '', content = '') { + setUpFixture(name, content); + editorEl = document.getElementById('editor'); + contentEl = document.querySelector('.snippet-file-content'); + fileNameEl = document.querySelector('.snippet-file-name'); + form = document.querySelector('.snippet-form-holder form'); + + initEditor(); + } + + function createEvent(name) { + return new Event(name, { + view: window, + bubbles: true, + cancelable: true, + }); + } + + beforeEach(() => { + oldGon = window.gon; + window.gon = { features: { monacoSnippets: true } }; + bootstrap(mockName, mockContent); + }); + + afterEach(() => { + window.gon = oldGon; + }); + + it('correctly initializes Editor', () => { + expect(mockEditor.createInstance).toHaveBeenCalledWith({ + el: editorEl, + blobPath: mockName, + blobContent: mockContent, + }); + }); + + it('listens to file name changes and updates syntax highlighting of code', () => { + expect(mockEditor.updateModelLanguage).not.toHaveBeenCalled(); + + const event = createEvent('change'); + + fileNameEl.value = updatedMockContent; + fileNameEl.dispatchEvent(event); + + expect(mockEditor.updateModelLanguage).toHaveBeenCalledWith(updatedMockContent); + }); + + it('listens to form submit event and populates the hidden field with most recent version of the content', () => { + expect(contentEl.value).toBe(mockContent); + + const event = createEvent('submit'); + + form.dispatchEvent(event); + expect(contentEl.value).toBe(updatedMockContent); + }); + }); +}); diff --git a/spec/lib/gitlab/profiler_spec.rb b/spec/lib/gitlab/profiler_spec.rb index 603417c5532..6440f74a49a 100644 --- a/spec/lib/gitlab/profiler_spec.rb +++ b/spec/lib/gitlab/profiler_spec.rb @@ -195,6 +195,7 @@ describe Gitlab::Profiler do describe '.print_by_total_time' do let(:stdout) { StringIO.new } + let(:regexp) { /^\s+\d+\.\d+\s+(\d+\.\d+)/ } let(:output) do stdout.rewind @@ -202,6 +203,8 @@ describe Gitlab::Profiler do end let_it_be(:result) do + Thread.new { sleep 1 } + RubyProf.profile do sleep 0.1 1.to_s @@ -212,23 +215,22 @@ describe Gitlab::Profiler do stub_const('STDOUT', stdout) end - it 'prints a profile result sorted by total time', quarantine: 'https://gitlab.com/gitlab-org/gitlab/issues/206907' do + it 'prints a profile result sorted by total time' do described_class.print_by_total_time(result) - total_times = - output - .scan(/^\s+\d+\.\d+\s+(\d+\.\d+)/) - .map { |(total)| total.to_f } - expect(output).to include('Kernel#sleep') - if total_times != total_times.sort.reverse - warn "Profiler test failed, output is:" - warn output - end + thread_profiles = output.split('Sort by: total_time').select { |x| x =~ regexp } - expect(total_times).to eq(total_times.sort.reverse) - expect(total_times).not_to eq(total_times.uniq) + thread_profiles.each do |profile| + total_times = + profile + .scan(regexp) + .map { |(total)| total.to_f } + + expect(total_times).to eq(total_times.sort.reverse) + expect(total_times).not_to eq(total_times.uniq) + end end it 'accepts a max_percent option' do diff --git a/spec/requests/api/projects_spec.rb b/spec/requests/api/projects_spec.rb index 38543e1efe5..2f1760a570e 100644 --- a/spec/requests/api/projects_spec.rb +++ b/spec/requests/api/projects_spec.rb @@ -1250,6 +1250,8 @@ describe API::Projects do expect(json_response['alt']).to eq("dk") expect(json_response['url']).to start_with("/uploads/") expect(json_response['url']).to end_with("/dk.png") + + expect(json_response['full_path']).to start_with("/#{project.namespace.path}/#{project.path}/uploads") end end diff --git a/spec/services/deployments/link_merge_requests_service_spec.rb b/spec/services/deployments/link_merge_requests_service_spec.rb index 605f2cfdc51..2f635c7ad62 100644 --- a/spec/services/deployments/link_merge_requests_service_spec.rb +++ b/spec/services/deployments/link_merge_requests_service_spec.rb @@ -133,6 +133,34 @@ describe Deployments::LinkMergeRequestsService do expect(deploy.merge_requests).to include(mr1, picked_mr) end + it "doesn't link the same merge_request twice" do + create(:merge_request, :merged, merge_commit_sha: mr1_merge_commit_sha, + source_project: project) + + picked_mr = create(:merge_request, :merged, merge_commit_sha: '123abc', + source_project: project) + + # the first MR includes c1c67abba which is a cherry-pick of the fake picked_mr merge request + create(:track_mr_picking_note, noteable: picked_mr, project: project, commit_id: 'c1c67abbaf91f624347bb3ae96eabe3a1b742478') + + environment = create(:environment, project: project) + old_deploy = + create(:deployment, :success, project: project, environment: environment) + + # manually linking all the MRs to the old_deploy + old_deploy.link_merge_requests(project.merge_requests) + + deploy = + create(:deployment, :success, project: project, environment: environment) + + described_class.new(deploy).link_merge_requests_for_range( + first_deployment_sha, + mr1_merge_commit_sha + ) + + expect(deploy.merge_requests).to be_empty + end + context 'when :track_mr_picking feature flag is disabled' do before do stub_feature_flags(track_mr_picking: false) |