diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2021-05-07 18:10:39 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2021-05-07 18:10:39 +0300 |
commit | 05b83be3ee097da8e71c8655d8f9f2c179cc3f7c (patch) | |
tree | db08678678565e8e072eeff47bf51c78f6c3d7b0 /spec | |
parent | 53f456b167f19877d663ee6ed510673cebee0f91 (diff) |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec')
8 files changed, 209 insertions, 86 deletions
diff --git a/spec/frontend/batch_comments/components/preview_dropdown_spec.js b/spec/frontend/batch_comments/components/preview_dropdown_spec.js new file mode 100644 index 00000000000..41be04d0b7e --- /dev/null +++ b/spec/frontend/batch_comments/components/preview_dropdown_spec.js @@ -0,0 +1,71 @@ +import Vue from 'vue'; +import Vuex from 'vuex'; +import { shallowMountExtended } from 'helpers/vue_test_utils_helper'; +import PreviewDropdown from '~/batch_comments/components/preview_dropdown.vue'; + +Vue.use(Vuex); + +let wrapper; + +const toggleActiveFileByHash = jest.fn(); +const scrollToDraft = jest.fn(); + +function factory({ viewDiffsFileByFile = false, draftsCount = 1, sortedDrafts = [] } = {}) { + const store = new Vuex.Store({ + modules: { + diffs: { + namespaced: true, + actions: { + toggleActiveFileByHash, + }, + state: { + viewDiffsFileByFile, + }, + }, + batchComments: { + namespaced: true, + actions: { scrollToDraft }, + getters: { draftsCount: () => draftsCount, sortedDrafts: () => sortedDrafts }, + }, + }, + }); + + wrapper = shallowMountExtended(PreviewDropdown, { + store, + }); +} + +describe('Batch comments preview dropdown', () => { + afterEach(() => { + wrapper.destroy(); + }); + + describe('clicking draft', () => { + it('it toggles active file when viewDiffsFileByFile is true', async () => { + factory({ + viewDiffsFileByFile: true, + sortedDrafts: [{ id: 1, file_hash: 'hash' }], + }); + + wrapper.findByTestId('preview-item').vm.$emit('click'); + + await Vue.nextTick(); + + expect(toggleActiveFileByHash).toHaveBeenCalledWith(expect.anything(), 'hash'); + expect(scrollToDraft).toHaveBeenCalledWith(expect.anything(), { id: 1, file_hash: 'hash' }); + }); + + it('calls scrollToDraft', async () => { + factory({ + viewDiffsFileByFile: false, + sortedDrafts: [{ id: 1 }], + }); + + wrapper.findByTestId('preview-item').vm.$emit('click'); + + await Vue.nextTick(); + + expect(scrollToDraft).toHaveBeenCalledWith(expect.anything(), { id: 1 }); + }); + }); +}); diff --git a/spec/frontend/content_editor/components/toolbar_button_spec.js b/spec/frontend/content_editor/components/toolbar_button_spec.js index 42fab2a5616..a49efa34017 100644 --- a/spec/frontend/content_editor/components/toolbar_button_spec.js +++ b/spec/frontend/content_editor/components/toolbar_button_spec.js @@ -83,7 +83,7 @@ describe('content_editor/components/toolbar_button', () => { await findButton().trigger('click'); expect(toggleFooSpy).toHaveBeenCalled(); - expect(wrapper.emitted().click).toHaveLength(1); + expect(wrapper.emitted().execute).toHaveLength(1); }); it('does not executes the content type command when executeCommand = false', async () => { @@ -92,7 +92,7 @@ describe('content_editor/components/toolbar_button', () => { await findButton().trigger('click'); expect(toggleFooSpy).not.toHaveBeenCalled(); - expect(wrapper.emitted().click).toHaveLength(1); + expect(wrapper.emitted().execute).toHaveLength(1); }); }); }); diff --git a/spec/frontend/content_editor/components/top_toolbar_spec.js b/spec/frontend/content_editor/components/top_toolbar_spec.js index e7cdb8d0967..8f47be3f489 100644 --- a/spec/frontend/content_editor/components/top_toolbar_spec.js +++ b/spec/frontend/content_editor/components/top_toolbar_spec.js @@ -1,12 +1,17 @@ import { shallowMount } from '@vue/test-utils'; +import { mockTracking } from 'helpers/tracking_helper'; import { extendedWrapper } from 'helpers/vue_test_utils_helper'; import TopToolbar from '~/content_editor/components/top_toolbar.vue'; +import { + TOOLBAR_CONTROL_TRACKING_ACTION, + CONTENT_EDITOR_TRACKING_LABEL, +} from '~/content_editor/constants'; import { createContentEditor } from '~/content_editor/services/create_content_editor'; describe('content_editor/components/top_toolbar', () => { let wrapper; let contentEditor; - + let trackingSpy; const buildEditor = () => { contentEditor = createContentEditor({ renderMarkdown: () => true }); }; @@ -22,6 +27,10 @@ describe('content_editor/components/top_toolbar', () => { }; beforeEach(() => { + trackingSpy = mockTracking(undefined, null, jest.spyOn); + }); + + beforeEach(() => { buildEditor(); }); @@ -29,7 +38,7 @@ describe('content_editor/components/top_toolbar', () => { wrapper.destroy(); }); - it.each` + describe.each` testId | buttonProps ${'bold'} | ${{ contentType: 'bold', iconName: 'bold', label: 'Bold text', editorCommand: 'toggleBold' }} ${'italic'} | ${{ contentType: 'italic', iconName: 'italic', label: 'Italic text', editorCommand: 'toggleItalic' }} @@ -37,11 +46,31 @@ describe('content_editor/components/top_toolbar', () => { ${'blockquote'} | ${{ contentType: 'blockquote', iconName: 'quote', label: 'Insert a quote', editorCommand: 'toggleBlockquote' }} ${'bullet-list'} | ${{ contentType: 'bulletList', iconName: 'list-bulleted', label: 'Add a bullet list', editorCommand: 'toggleBulletList' }} ${'ordered-list'} | ${{ contentType: 'orderedList', iconName: 'list-numbered', label: 'Add a numbered list', editorCommand: 'toggleOrderedList' }} - `('renders $testId button', ({ testId, buttonProps }) => { - buildWrapper(); - expect(wrapper.findByTestId(testId).props()).toEqual({ - ...buttonProps, - tiptapEditor: contentEditor.tiptapEditor, + `('given a $testId toolbar control', ({ testId, buttonProps }) => { + beforeEach(() => { + buildWrapper(); + }); + + it('renders the toolbar control with the provided properties', () => { + expect(wrapper.findByTestId(testId).props()).toEqual({ + ...buttonProps, + tiptapEditor: contentEditor.tiptapEditor, + }); + }); + + it.each` + control | eventData + ${'bold'} | ${{ contentType: 'bold' }} + ${'blockquote'} | ${{ contentType: 'blockquote', value: 1 }} + `('tracks the execution of toolbar controls', ({ control, eventData }) => { + const { contentType, value } = eventData; + wrapper.findByTestId(control).vm.$emit('execute', eventData); + + expect(trackingSpy).toHaveBeenCalledWith(undefined, TOOLBAR_CONTROL_TRACKING_ACTION, { + label: CONTENT_EDITOR_TRACKING_LABEL, + property: contentType, + value, + }); }); }); }); diff --git a/spec/lib/gitlab/ci/pipeline/chain/seed_spec.rb b/spec/lib/gitlab/ci/pipeline/chain/seed_spec.rb index 889c9d239a5..2e537f40692 100644 --- a/spec/lib/gitlab/ci/pipeline/chain/seed_spec.rb +++ b/spec/lib/gitlab/ci/pipeline/chain/seed_spec.rb @@ -218,15 +218,18 @@ RSpec.describe Gitlab::Ci::Pipeline::Chain::Seed do end context 'N+1 queries' do - it 'avoids N+1 queries when calculating variables of jobs' do + it 'avoids N+1 queries when calculating variables of jobs', :use_sql_query_cache do + warm_up_pipeline, warm_up_command = prepare_pipeline1 + perform_seed(warm_up_pipeline, warm_up_command) + pipeline1, command1 = prepare_pipeline1 pipeline2, command2 = prepare_pipeline2 - control = ActiveRecord::QueryRecorder.new do + control = ActiveRecord::QueryRecorder.new(skip_cached: false) do perform_seed(pipeline1, command1) end - expect { perform_seed(pipeline2, command2) }.not_to exceed_query_limit( + expect { perform_seed(pipeline2, command2) }.not_to exceed_all_query_limit( control.count + expected_extra_queries ) end diff --git a/spec/lib/gitlab/database/schema_cache_with_renamed_table_spec.rb b/spec/lib/gitlab/database/schema_cache_with_renamed_table_spec.rb new file mode 100644 index 00000000000..8c0c4155ccc --- /dev/null +++ b/spec/lib/gitlab/database/schema_cache_with_renamed_table_spec.rb @@ -0,0 +1,83 @@ +# frozen_string_literal: true + +require 'spec_helper' + +RSpec.describe Gitlab::Database::SchemaCacheWithRenamedTable do + let(:old_model) do + Class.new(ActiveRecord::Base) do + self.table_name = 'projects' + end + end + + let(:new_model) do + Class.new(ActiveRecord::Base) do + self.table_name = 'projects_new' + end + end + + before do + stub_const('Gitlab::Database::TABLES_TO_BE_RENAMED', { 'projects' => 'projects_new' }) + end + + context 'when table is not renamed yet' do + before do + old_model.reset_column_information + ActiveRecord::Base.connection.schema_cache.clear! + end + + it 'uses the original table to look up metadata' do + expect(old_model.primary_key).to eq('id') + end + end + + context 'when table is renamed' do + before do + ActiveRecord::Base.connection.execute("ALTER TABLE projects RENAME TO projects_new") + ActiveRecord::Base.connection.execute("CREATE VIEW projects AS SELECT * FROM projects_new") + + old_model.reset_column_information + ActiveRecord::Base.connection.schema_cache.clear! + end + + it 'uses the renamed table to look up metadata' do + expect(old_model.primary_key).to eq('id') + end + + it 'has primary key' do + expect(old_model.primary_key).to eq('id') + expect(old_model.primary_key).to eq(new_model.primary_key) + end + + it 'has the same column definitions' do + expect(old_model.columns).to eq(new_model.columns) + end + + it 'has the same indexes' do + indexes_for_old_table = ActiveRecord::Base.connection.schema_cache.indexes('projects') + indexes_for_new_table = ActiveRecord::Base.connection.schema_cache.indexes('projects_new') + + expect(indexes_for_old_table).to eq(indexes_for_new_table) + end + + it 'has the same column_hash' do + columns_hash_for_old_table = ActiveRecord::Base.connection.schema_cache.columns_hash('projects') + columns_hash_for_new_table = ActiveRecord::Base.connection.schema_cache.columns_hash('projects_new') + + expect(columns_hash_for_old_table).to eq(columns_hash_for_new_table) + end + + describe 'when the table behind a model is actually a view' do + let(:group) { create(:group) } + let(:project_attributes) { attributes_for(:project, namespace_id: group.id).except(:creator) } + let(:record) { old_model.create!(project_attributes) } + + it 'can persist records' do + expect(record.reload.attributes).to eq(new_model.find(record.id).attributes) + end + + it 'can find records' do + expect(old_model.find_by_id(record.id)).not_to be_nil + end + end + end +end diff --git a/spec/models/ci/build_dependencies_spec.rb b/spec/models/ci/build_dependencies_spec.rb index e576345f1ca..d00d88ae397 100644 --- a/spec/models/ci/build_dependencies_spec.rb +++ b/spec/models/ci/build_dependencies_spec.rb @@ -18,10 +18,6 @@ RSpec.describe Ci::BuildDependencies do let!(:rubocop_test) { create(:ci_build, pipeline: pipeline, name: 'rubocop', stage_idx: 1, stage: 'test') } let!(:staging) { create(:ci_build, pipeline: pipeline, name: 'staging', stage_idx: 2, stage: 'deploy') } - before do - stub_feature_flags(ci_validate_build_dependencies_override: false) - end - context 'for local dependencies' do subject { described_class.new(job).all } @@ -378,14 +374,6 @@ RSpec.describe Ci::BuildDependencies do end it { is_expected.to eq(false) } - - context 'when ci_validate_build_dependencies_override feature flag is enabled' do - before do - stub_feature_flags(ci_validate_build_dependencies_override: job.project) - end - - it { is_expected.to eq(true) } - end end end end diff --git a/spec/models/ci/build_spec.rb b/spec/models/ci/build_spec.rb index 9848ef30388..c7850b0bc16 100644 --- a/spec/models/ci/build_spec.rb +++ b/spec/models/ci/build_spec.rb @@ -3631,41 +3631,24 @@ RSpec.describe Ci::Build do end let!(:job) { create(:ci_build, :pending, pipeline: pipeline, stage_idx: 1, options: options) } + let!(:pre_stage_job) { create(:ci_build, :success, pipeline: pipeline, name: 'test', stage_idx: 0) } - context 'when validates for dependencies is enabled' do - before do - stub_feature_flags(ci_validate_build_dependencies_override: false) - end - - let!(:pre_stage_job) { create(:ci_build, :success, pipeline: pipeline, name: 'test', stage_idx: 0) } - - context 'when "dependencies" keyword is not defined' do - let(:options) { {} } - - it { expect(job).to have_valid_build_dependencies } - end - - context 'when "dependencies" keyword is empty' do - let(:options) { { dependencies: [] } } + context 'when "dependencies" keyword is not defined' do + let(:options) { {} } - it { expect(job).to have_valid_build_dependencies } - end + it { expect(job).to have_valid_build_dependencies } + end - context 'when "dependencies" keyword is specified' do - let(:options) { { dependencies: ['test'] } } + context 'when "dependencies" keyword is empty' do + let(:options) { { dependencies: [] } } - it_behaves_like 'validation is active' - end + it { expect(job).to have_valid_build_dependencies } end - context 'when validates for dependencies is disabled' do + context 'when "dependencies" keyword is specified' do let(:options) { { dependencies: ['test'] } } - before do - stub_feature_flags(ci_validate_build_dependencies_override: true) - end - - it_behaves_like 'validation is not active' + it_behaves_like 'validation is active' end end diff --git a/spec/services/ci/register_job_service_spec.rb b/spec/services/ci/register_job_service_spec.rb index 65211632e3a..839a3c53f07 100644 --- a/spec/services/ci/register_job_service_spec.rb +++ b/spec/services/ci/register_job_service_spec.rb @@ -516,10 +516,6 @@ module Ci end end - before do - stub_feature_flags(ci_validate_build_dependencies_override: false) - end - let!(:pre_stage_job) { create(:ci_build, :success, pipeline: pipeline, name: 'test', stage_idx: 0) } let!(:pending_job) do @@ -530,37 +526,7 @@ module Ci subject { execute(specific_runner) } - context 'when validates for dependencies is enabled' do - before do - stub_feature_flags(ci_validate_build_dependencies_override: false) - end - - it_behaves_like 'validation is active' - - context 'when the main feature flag is enabled for a specific project' do - before do - stub_feature_flags(ci_validate_build_dependencies: pipeline.project) - end - - it_behaves_like 'validation is active' - end - - context 'when the main feature flag is enabled for a different project' do - before do - stub_feature_flags(ci_validate_build_dependencies: create(:project)) - end - - it_behaves_like 'validation is not active' - end - end - - context 'when validates for dependencies is disabled' do - before do - stub_feature_flags(ci_validate_build_dependencies_override: true) - end - - it_behaves_like 'validation is not active' - end + it_behaves_like 'validation is active' end context 'when build is degenerated' do |