diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2021-10-20 12:13:26 +0000 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2021-10-20 12:13:26 +0000 |
commit | 3ce7340b2ae954b6b449bfba5720fa356b803c51 (patch) | |
tree | ab1cc089c519d0f94993142071556aa6027f0589 /spec | |
parent | c2afac6a378d1aaaa7448892d042cdb59ee2c290 (diff) | |
download | gitlab-ce-3ce7340b2ae954b6b449bfba5720fa356b803c51.tar.gz |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec')
10 files changed, 298 insertions, 20 deletions
diff --git a/spec/frontend/__mocks__/@gitlab/ui.js b/spec/frontend/__mocks__/@gitlab/ui.js index 4c491a87fcb..6b3f1f01e6a 100644 --- a/spec/frontend/__mocks__/@gitlab/ui.js +++ b/spec/frontend/__mocks__/@gitlab/ui.js @@ -14,7 +14,9 @@ export * from '@gitlab/ui'; */ jest.mock('@gitlab/ui/dist/directives/tooltip.js', () => ({ - bind() {}, + GlTooltipDirective: { + bind() {}, + }, })); jest.mock('@gitlab/ui/dist/components/base/tooltip/tooltip.js', () => ({ diff --git a/spec/frontend/diffs/components/diff_line_note_form_spec.js b/spec/frontend/diffs/components/diff_line_note_form_spec.js index a192f7e2e9a..5132cfd7622 100644 --- a/spec/frontend/diffs/components/diff_line_note_form_spec.js +++ b/spec/frontend/diffs/components/diff_line_note_form_spec.js @@ -26,8 +26,9 @@ describe('DiffLineNoteForm', () => { propsData: { diffFileHash: diffFile.file_hash, diffLines, - line: diffLines[0], - noteTargetLine: diffLines[0], + line: diffLines[1], + range: { start: diffLines[0], end: diffLines[1] }, + noteTargetLine: diffLines[1], }, }); }; @@ -67,7 +68,7 @@ describe('DiffLineNoteForm', () => { expect(window.confirm).not.toHaveBeenCalled(); wrapper.vm.$nextTick(() => { expect(wrapper.vm.cancelCommentForm).toHaveBeenCalledWith({ - lineCode: diffLines[0].line_code, + lineCode: diffLines[1].line_code, fileHash: wrapper.vm.diffFileHash, }); @@ -88,13 +89,13 @@ describe('DiffLineNoteForm', () => { start: { line_code: wrapper.vm.commentLineStart.line_code, type: wrapper.vm.commentLineStart.type, - new_line: 1, + new_line: 2, old_line: null, }, end: { line_code: wrapper.vm.line.line_code, type: wrapper.vm.line.type, - new_line: 1, + new_line: 2, old_line: null, }, }; @@ -120,7 +121,7 @@ describe('DiffLineNoteForm', () => { describe('mounted', () => { it('should init autosave', () => { - const key = 'autosave/Note/Issue/98//DiffNote//1c497fbb3a46b78edf04cc2a2fa33f67e3ffbe2a_1_1'; + const key = 'autosave/Note/Issue/98//DiffNote//1c497fbb3a46b78edf04cc2a2fa33f67e3ffbe2a_1_2'; wrapper = createComponent(); expect(wrapper.vm.autosave).toBeDefined(); diff --git a/spec/frontend/diffs/utils/diff_line_spec.js b/spec/frontend/diffs/utils/diff_line_spec.js new file mode 100644 index 00000000000..adcb4a4433c --- /dev/null +++ b/spec/frontend/diffs/utils/diff_line_spec.js @@ -0,0 +1,30 @@ +import { pickDirection } from '~/diffs/utils/diff_line'; + +describe('diff_line utilities', () => { + describe('pickDirection', () => { + const left = { + line_code: 'left', + }; + const right = { + line_code: 'right', + }; + const defaultLine = { + left, + right, + }; + + it.each` + code | pick | line | pickDescription + ${'left'} | ${left} | ${defaultLine} | ${'the left line'} + ${'right'} | ${right} | ${defaultLine} | ${'the right line'} + ${'junk'} | ${left} | ${defaultLine} | ${'the default: the left line'} + ${'junk'} | ${right} | ${{ right }} | ${"the right line if there's no left line to default to"} + ${'right'} | ${left} | ${{ left }} | ${"the left line when there isn't a right line to match"} + `( + 'when provided a line and a line code `$code`, picks $pickDescription', + ({ code, line, pick }) => { + expect(pickDirection({ line, code })).toBe(pick); + }, + ); + }); +}); diff --git a/spec/frontend/ide/components/shared/commit_message_field_spec.js b/spec/frontend/ide/components/shared/commit_message_field_spec.js new file mode 100644 index 00000000000..f4f9b95b233 --- /dev/null +++ b/spec/frontend/ide/components/shared/commit_message_field_spec.js @@ -0,0 +1,149 @@ +import { shallowMount } from '@vue/test-utils'; +import { nextTick } from 'vue'; +import { extendedWrapper } from 'helpers/vue_test_utils_helper'; +import CommitMessageField from '~/ide/components/shared/commit_message_field.vue'; + +const DEFAULT_PROPS = { + text: 'foo text', + placeholder: 'foo placeholder', +}; + +describe('CommitMessageField', () => { + let wrapper; + + const createComponent = (props = {}) => { + wrapper = extendedWrapper( + shallowMount(CommitMessageField, { + propsData: { + ...DEFAULT_PROPS, + ...props, + }, + attachTo: document.body, + }), + ); + }; + + afterEach(() => { + wrapper.destroy(); + }); + + const findTextArea = () => wrapper.find('textarea'); + const findHighlights = () => wrapper.findByTestId('highlights'); + const findHighlightsText = () => wrapper.findByTestId('highlights-text'); + const findHighlightsMark = () => wrapper.findByTestId('highlights-mark'); + const findHighlightsTexts = () => wrapper.findAllByTestId('highlights-text'); + const findHighlightsMarks = () => wrapper.findAllByTestId('highlights-mark'); + + const fillText = async (text) => { + wrapper.setProps({ text }); + await nextTick(); + }; + + it('emits input event on input', () => { + const value = 'foo'; + + createComponent(); + findTextArea().setValue(value); + expect(wrapper.emitted('input')[0][0]).toEqual(value); + }); + + describe('focus classes', () => { + beforeEach(async () => { + createComponent(); + findTextArea().trigger('focus'); + await nextTick(); + }); + + it('is added on textarea focus', async () => { + expect(wrapper.attributes('class')).toEqual( + expect.stringContaining('gl-outline-none! gl-focus-ring-border-1-gray-900!'), + ); + }); + + it('is removed on textarea blur', async () => { + findTextArea().trigger('blur'); + await nextTick(); + + expect(wrapper.attributes('class')).toEqual( + expect.not.stringContaining('gl-outline-none! gl-focus-ring-border-1-gray-900!'), + ); + }); + }); + + describe('highlights', () => { + describe('subject line', () => { + it('does not highlight less than 50 characters', async () => { + const text = 'text less than 50 chars'; + + createComponent(); + await fillText(text); + + expect(findHighlightsText().text()).toEqual(text); + expect(findHighlightsMark().text()).toBeFalsy(); + }); + + it('highlights characters over 50 length', async () => { + const text = + 'text less than 50 chars that should not highlighted. text more than 50 should be highlighted'; + + createComponent(); + await fillText(text); + + expect(findHighlightsText().text()).toEqual(text.slice(0, 50)); + expect(findHighlightsMark().text()).toEqual(text.slice(50)); + }); + }); + + describe('body text', () => { + it('does not highlight body text less tan 72 characters', async () => { + const text = 'subject line\nbody content'; + + createComponent(); + await fillText(text); + + expect(findHighlightsTexts()).toHaveLength(2); + expect(findHighlightsMarks().at(1).attributes('style')).toEqual('display: none;'); + }); + + it('highlights body text more than 72 characters', async () => { + const text = + 'subject line\nbody content that will be highlighted when it is more than 72 characters in length'; + + createComponent(); + await fillText(text); + + expect(findHighlightsTexts()).toHaveLength(2); + expect(findHighlightsMarks().at(1).attributes('style')).not.toEqual('display: none;'); + expect(findHighlightsMarks().at(1).element.textContent).toEqual(' in length'); + }); + + it('highlights body text & subject line', async () => { + const text = + 'text less than 50 chars that should not highlighted\nbody content that will be highlighted when it is more than 72 characters in length'; + + createComponent(); + await fillText(text); + + expect(findHighlightsTexts()).toHaveLength(2); + expect(findHighlightsMarks()).toHaveLength(2); + expect(findHighlightsMarks().at(0).element.textContent).toEqual('d'); + expect(findHighlightsMarks().at(1).element.textContent).toEqual(' in length'); + }); + }); + }); + + describe('scrolling textarea', () => { + it('updates transform of highlights', async () => { + const yCoord = 50; + + createComponent(); + await fillText('subject line\n\n\n\n\n\n\n\n\n\n\nbody content'); + + wrapper.vm.$el.querySelector('textarea').scrollTo(0, yCoord); + await nextTick(); + + expect(wrapper.vm.scrollTop).toEqual(yCoord); + expect(findHighlights().attributes('style')).toEqual('transform: translate3d(0, -50px, 0);'); + }); + }); +}); diff --git a/spec/frontend/notes/components/multiline_comment_form_spec.js b/spec/frontend/notes/components/multiline_comment_form_spec.js index b6d603c6358..b027a261c15 100644 --- a/spec/frontend/notes/components/multiline_comment_form_spec.js +++ b/spec/frontend/notes/components/multiline_comment_form_spec.js @@ -50,18 +50,6 @@ describe('MultilineCommentForm', () => { expect(wrapper.vm.commentLineStart).toEqual(lineRange.start); expect(setSelectedCommentPosition).toHaveBeenCalled(); }); - - it('sets commentLineStart to selectedCommentPosition', () => { - const notes = { - selectedCommentPosition: { - start: { ...testLine }, - }, - }; - const wrapper = createWrapper({}, { notes }); - - expect(wrapper.vm.commentLineStart).toEqual(wrapper.vm.selectedCommentPosition.start); - expect(setSelectedCommentPosition).not.toHaveBeenCalled(); - }); }); describe('destroyed', () => { diff --git a/spec/lib/gitlab/ci/config/extendable_spec.rb b/spec/lib/gitlab/ci/config/extendable_spec.rb index 481f55d790e..2fc009569fc 100644 --- a/spec/lib/gitlab/ci/config/extendable_spec.rb +++ b/spec/lib/gitlab/ci/config/extendable_spec.rb @@ -73,6 +73,50 @@ RSpec.describe Gitlab::Ci::Config::Extendable do end end + context 'when the job tries to delete an extension key' do + let(:hash) do + { + something: { + script: 'deploy', + only: { variables: %w[$SOMETHING] } + }, + + test1: { + extends: 'something', + script: 'ls', + only: {} + }, + + test2: { + extends: 'something', + script: 'ls', + only: nil + } + } + end + + it 'deletes the key if assigned to null' do + expect(subject.to_hash).to eq( + something: { + script: 'deploy', + only: { variables: %w[$SOMETHING] } + }, + test1: { + extends: 'something', + script: 'ls', + only: { + variables: %w[$SOMETHING] + } + }, + test2: { + extends: 'something', + script: 'ls', + only: nil + } + ) + end + end + context 'when a hash uses recursive extensions' do let(:hash) do { diff --git a/spec/lib/gitlab/ci/yaml_processor_spec.rb b/spec/lib/gitlab/ci/yaml_processor_spec.rb index 1591c2e6b60..f00a801286d 100644 --- a/spec/lib/gitlab/ci/yaml_processor_spec.rb +++ b/spec/lib/gitlab/ci/yaml_processor_spec.rb @@ -1046,6 +1046,64 @@ module Gitlab end end + context 'when overriding `extends`' do + let(:config) do + <<~YAML + .base: + script: test + variables: + VAR1: base var 1 + + test1: + extends: .base + variables: + VAR1: test1 var 1 + VAR2: test2 var 2 + + test2: + extends: .base + variables: + VAR2: test2 var 2 + + test3: + extends: .base + variables: {} + + test4: + extends: .base + variables: null + YAML + end + + it 'correctly extends jobs' do + expect(config_processor.builds[0]).to include( + name: 'test1', + options: { script: ['test'] }, + job_variables: [{ key: 'VAR1', value: 'test1 var 1', public: true }, + { key: 'VAR2', value: 'test2 var 2', public: true }] + ) + + expect(config_processor.builds[1]).to include( + name: 'test2', + options: { script: ['test'] }, + job_variables: [{ key: 'VAR1', value: 'base var 1', public: true }, + { key: 'VAR2', value: 'test2 var 2', public: true }] + ) + + expect(config_processor.builds[2]).to include( + name: 'test3', + options: { script: ['test'] }, + job_variables: [{ key: 'VAR1', value: 'base var 1', public: true }] + ) + + expect(config_processor.builds[3]).to include( + name: 'test4', + options: { script: ['test'] }, + job_variables: [] + ) + end + end + context 'when using recursive `extends`' do let(:config) do <<~YAML diff --git a/spec/lib/gitlab/usage/metric_definition_spec.rb b/spec/lib/gitlab/usage/metric_definition_spec.rb index 522f69062fb..a22b3a733bd 100644 --- a/spec/lib/gitlab/usage/metric_definition_spec.rb +++ b/spec/lib/gitlab/usage/metric_definition_spec.rb @@ -9,6 +9,7 @@ RSpec.describe Gitlab::Usage::MetricDefinition do value_type: 'string', product_category: 'collection', product_stage: 'growth', + product_section: 'devops', status: 'active', milestone: '14.1', default_generation: 'generation_1', @@ -222,6 +223,7 @@ RSpec.describe Gitlab::Usage::MetricDefinition do value_type: 'string', product_category: 'collection', product_stage: 'growth', + product_section: 'devops', status: 'active', milestone: '14.1', default_generation: 'generation_1', diff --git a/spec/support/database/cross-database-modification-allowlist.yml b/spec/support/database/cross-database-modification-allowlist.yml index 627967f65f3..65b44379abc 100644 --- a/spec/support/database/cross-database-modification-allowlist.yml +++ b/spec/support/database/cross-database-modification-allowlist.yml @@ -378,7 +378,6 @@ - "./ee/spec/models/ci/build_spec.rb" - "./ee/spec/models/ci/minutes/additional_pack_spec.rb" - "./ee/spec/models/ci/pipeline_spec.rb" -- "./ee/spec/models/ci/subscriptions/project_spec.rb" - "./ee/spec/models/concerns/approval_rule_like_spec.rb" - "./ee/spec/models/concerns/approver_migrate_hook_spec.rb" - "./ee/spec/models/dora/daily_metrics_spec.rb" diff --git a/spec/support/database/prevent_cross_database_modification.rb b/spec/support/database/prevent_cross_database_modification.rb index 7ded85b65ce..c793c1c008b 100644 --- a/spec/support/database/prevent_cross_database_modification.rb +++ b/spec/support/database/prevent_cross_database_modification.rb @@ -84,6 +84,11 @@ module Database parsed_query = PgQuery.parse(sql) tables = sql.downcase.include?(' for update') ? parsed_query.tables : parsed_query.dml_tables + # We have some code where plans and gitlab_subscriptions are lazily + # created and this causes lots of spec failures + # https://gitlab.com/gitlab-org/gitlab/-/issues/343394 + tables -= %w[plans gitlab_subscriptions] + return if tables.empty? cross_database_context[:modified_tables_by_db][database].merge(tables) |