diff options
Diffstat (limited to 'spec')
10 files changed, 249 insertions, 26 deletions
diff --git a/spec/frontend/issues/show/components/description_spec.js b/spec/frontend/issues/show/components/description_spec.js index bdb1448148e..9d9abce887b 100644 --- a/spec/frontend/issues/show/components/description_spec.js +++ b/spec/frontend/issues/show/components/description_spec.js @@ -12,6 +12,7 @@ import createMockApollo from 'helpers/mock_apollo_helper'; import waitForPromises from 'helpers/wait_for_promises'; import { shallowMountExtended } from 'helpers/vue_test_utils_helper'; +import createFlash from '~/flash'; import Description from '~/issues/show/components/description.vue'; import { updateHistory } from '~/lib/utils/url_utility'; import workItemQuery from '~/work_items/graphql/work_item.query.graphql'; @@ -71,7 +72,11 @@ describe('Description component', () => { const findModal = () => wrapper.findComponent(GlModal); const findWorkItemDetailModal = () => wrapper.findComponent(WorkItemDetailModal); - function createComponent({ props = {}, provide } = {}) { + function createComponent({ + props = {}, + provide, + createWorkItemFromTaskHandler = createWorkItemFromTaskSuccessHandler, + } = {}) { wrapper = shallowMountExtended(Description, { propsData: { issueId: 1, @@ -85,7 +90,7 @@ describe('Description component', () => { apolloProvider: createMockApollo([ [workItemQuery, queryHandler], [workItemTypesQuery, workItemTypesQueryHandler], - [createWorkItemFromTaskMutation, createWorkItemFromTaskSuccessHandler], + [createWorkItemFromTaskMutation, createWorkItemFromTaskHandler], ]), mocks: { $toast, @@ -317,7 +322,28 @@ describe('Description component', () => { expect(findModal().exists()).toBe(false); }); + it('shows toast after delete success', async () => { + const newDesc = 'description'; + findWorkItemDetailModal().vm.$emit('workItemDeleted', newDesc); + + expect(wrapper.emitted('updateDescription')).toEqual([[newDesc]]); + expect($toast.show).toHaveBeenCalledWith('Task deleted'); + }); + }); + + describe('creating work item from checklist item', () => { it('emits `updateDescription` after creating new work item', async () => { + createComponent({ + props: { + descriptionHtml: descriptionHtmlWithCheckboxes, + }, + provide: { + glFeatures: { + workItemsCreateFromMarkdown: true, + }, + }, + }); + const newDescription = `<p>New description</p>`; await findConvertToTaskButton().trigger('click'); @@ -327,12 +353,28 @@ describe('Description component', () => { expect(wrapper.emitted('updateDescription')).toEqual([[newDescription]]); }); - it('shows toast after delete success', async () => { - const newDesc = 'description'; - findWorkItemDetailModal().vm.$emit('workItemDeleted', newDesc); + it('shows flash message when creating task fails', async () => { + createComponent({ + props: { + descriptionHtml: descriptionHtmlWithCheckboxes, + }, + provide: { + glFeatures: { + workItemsCreateFromMarkdown: true, + }, + }, + createWorkItemFromTaskHandler: jest.fn().mockRejectedValue({}), + }); - expect(wrapper.emitted('updateDescription')).toEqual([[newDesc]]); - expect($toast.show).toHaveBeenCalledWith('Task deleted'); + await findConvertToTaskButton().trigger('click'); + + await waitForPromises(); + + expect(createFlash).toHaveBeenCalledWith( + expect.objectContaining({ + message: 'Something went wrong when creating task. Please try again.', + }), + ); }); }); diff --git a/spec/frontend/work_items/components/work_item_actions_spec.js b/spec/frontend/work_items/components/work_item_actions_spec.js index a1f1d47ab90..3c312fb4552 100644 --- a/spec/frontend/work_items/components/work_item_actions_spec.js +++ b/spec/frontend/work_items/components/work_item_actions_spec.js @@ -1,15 +1,30 @@ -import { GlModal } from '@gitlab/ui'; +import { GlDropdownDivider, GlModal } from '@gitlab/ui'; import { shallowMountExtended } from 'helpers/vue_test_utils_helper'; import WorkItemActions from '~/work_items/components/work_item_actions.vue'; +const TEST_ID_CONFIDENTIALITY_TOGGLE_ACTION = 'confidentiality-toggle-action'; +const TEST_ID_DELETE_ACTION = 'delete-action'; + describe('WorkItemActions component', () => { let wrapper; let glModalDirective; const findModal = () => wrapper.findComponent(GlModal); const findConfidentialityToggleButton = () => - wrapper.findByTestId('confidentiality-toggle-action'); - const findDeleteButton = () => wrapper.findByTestId('delete-action'); + wrapper.findByTestId(TEST_ID_CONFIDENTIALITY_TOGGLE_ACTION); + const findDeleteButton = () => wrapper.findByTestId(TEST_ID_DELETE_ACTION); + const findDropdownItems = () => wrapper.findAll('[data-testid="work-item-actions-dropdown"] > *'); + const findDropdownItemsActual = () => + findDropdownItems().wrappers.map((x) => { + if (x.is(GlDropdownDivider)) { + return { divider: true }; + } + + return { + testId: x.attributes('data-testid'), + text: x.text(), + }; + }); const createComponent = ({ canUpdate = true, @@ -19,7 +34,14 @@ describe('WorkItemActions component', () => { } = {}) => { glModalDirective = jest.fn(); wrapper = shallowMountExtended(WorkItemActions, { - propsData: { workItemId: '123', canUpdate, canDelete, isConfidential, isParentConfidential }, + propsData: { + workItemId: '123', + canUpdate, + canDelete, + isConfidential, + isParentConfidential, + workItemType: 'Task', + }, directives: { glModal: { bind(_, { value }) { @@ -44,8 +66,19 @@ describe('WorkItemActions component', () => { it('renders dropdown actions', () => { createComponent(); - expect(findConfidentialityToggleButton().exists()).toBe(true); - expect(findDeleteButton().exists()).toBe(true); + expect(findDropdownItemsActual()).toEqual([ + { + testId: TEST_ID_CONFIDENTIALITY_TOGGLE_ACTION, + text: 'Turn on confidentiality', + }, + { + divider: true, + }, + { + testId: TEST_ID_DELETE_ACTION, + text: 'Delete task', + }, + ]); }); describe('toggle confidentiality action', () => { @@ -103,7 +136,8 @@ describe('WorkItemActions component', () => { canDelete: false, }); - expect(wrapper.findByTestId('delete-action').exists()).toBe(false); + expect(findDeleteButton().exists()).toBe(false); + expect(wrapper.findComponent(GlDropdownDivider).exists()).toBe(false); }); }); }); diff --git a/spec/frontend/work_items/components/work_item_state_spec.js b/spec/frontend/work_items/components/work_item_state_spec.js index 6b23a6e4795..b24d940d56a 100644 --- a/spec/frontend/work_items/components/work_item_state_spec.js +++ b/spec/frontend/work_items/components/work_item_state_spec.js @@ -7,7 +7,6 @@ import waitForPromises from 'helpers/wait_for_promises'; import ItemState from '~/work_items/components/item_state.vue'; import WorkItemState from '~/work_items/components/work_item_state.vue'; import { - i18n, STATE_OPEN, STATE_CLOSED, STATE_EVENT_CLOSE, @@ -104,7 +103,9 @@ describe('WorkItemState component', () => { findItemState().vm.$emit('changed', STATE_CLOSED); await waitForPromises(); - expect(wrapper.emitted('error')).toEqual([[i18n.updateError]]); + expect(wrapper.emitted('error')).toEqual([ + ['Something went wrong while updating the task. Please try again.'], + ]); }); it('tracks editing the state', async () => { diff --git a/spec/frontend/work_items/components/work_item_title_spec.js b/spec/frontend/work_items/components/work_item_title_spec.js index c0d966abab8..a549aad5cd8 100644 --- a/spec/frontend/work_items/components/work_item_title_spec.js +++ b/spec/frontend/work_items/components/work_item_title_spec.js @@ -6,7 +6,7 @@ import { mockTracking } from 'helpers/tracking_helper'; import waitForPromises from 'helpers/wait_for_promises'; import ItemTitle from '~/work_items/components/item_title.vue'; import WorkItemTitle from '~/work_items/components/work_item_title.vue'; -import { i18n, TRACKING_CATEGORY_SHOW } from '~/work_items/constants'; +import { TRACKING_CATEGORY_SHOW } from '~/work_items/constants'; import updateWorkItemMutation from '~/work_items/graphql/update_work_item.mutation.graphql'; import updateWorkItemTaskMutation from '~/work_items/graphql/update_work_item_task.mutation.graphql'; import { updateWorkItemMutationResponse, workItemQueryResponse } from '../mock_data'; @@ -116,7 +116,9 @@ describe('WorkItemTitle component', () => { findItemTitle().vm.$emit('title-changed', 'new title'); await waitForPromises(); - expect(wrapper.emitted('error')).toEqual([[i18n.updateError]]); + expect(wrapper.emitted('error')).toEqual([ + ['Something went wrong while updating the task. Please try again.'], + ]); }); it('tracks editing the title', async () => { diff --git a/spec/frontend/work_items/components/work_item_weight_spec.js b/spec/frontend/work_items/components/work_item_weight_spec.js index 94bdb336deb..38dc1af0bac 100644 --- a/spec/frontend/work_items/components/work_item_weight_spec.js +++ b/spec/frontend/work_items/components/work_item_weight_spec.js @@ -7,7 +7,7 @@ import { mountExtended } from 'helpers/vue_test_utils_helper'; import waitForPromises from 'helpers/wait_for_promises'; import { __ } from '~/locale'; import WorkItemWeight from '~/work_items/components/work_item_weight.vue'; -import { i18n, TRACKING_CATEGORY_SHOW } from '~/work_items/constants'; +import { TRACKING_CATEGORY_SHOW } from '~/work_items/constants'; import updateWorkItemMutation from '~/work_items/graphql/update_work_item.mutation.graphql'; import { updateWorkItemMutationResponse } from 'jest/work_items/mock_data'; @@ -181,7 +181,9 @@ describe('WorkItemWeight component', () => { findInput().trigger('blur'); await waitForPromises(); - expect(wrapper.emitted('error')).toEqual([[i18n.updateError]]); + expect(wrapper.emitted('error')).toEqual([ + ['Something went wrong while updating the task. Please try again.'], + ]); }); it('emits an error when there is a network error', async () => { @@ -194,7 +196,9 @@ describe('WorkItemWeight component', () => { findInput().trigger('blur'); await waitForPromises(); - expect(wrapper.emitted('error')).toEqual([[i18n.updateError]]); + expect(wrapper.emitted('error')).toEqual([ + ['Something went wrong while updating the task. Please try again.'], + ]); }); it('tracks updating the weight', () => { diff --git a/spec/frontend/work_items/pages/create_work_item_spec.js b/spec/frontend/work_items/pages/create_work_item_spec.js index fed8be3783a..15dac25b7d9 100644 --- a/spec/frontend/work_items/pages/create_work_item_spec.js +++ b/spec/frontend/work_items/pages/create_work_item_spec.js @@ -193,6 +193,8 @@ describe('Create work item component', () => { wrapper.find('form').trigger('submit'); await waitForPromises(); - expect(findAlert().text()).toBe(CreateWorkItem.createErrorText); + expect(findAlert().text()).toBe( + 'Something went wrong when creating work item. Please try again.', + ); }); }); diff --git a/spec/frontend/work_items/pages/work_item_detail_spec.js b/spec/frontend/work_items/pages/work_item_detail_spec.js index ab6050418c7..95982db3620 100644 --- a/spec/frontend/work_items/pages/work_item_detail_spec.js +++ b/spec/frontend/work_items/pages/work_item_detail_spec.js @@ -379,11 +379,12 @@ describe('WorkItemDetail component', () => { it('shows an error message when WorkItemTitle emits an `error` event', async () => { createComponent(); await waitForPromises(); + const updateError = 'Failed to update'; - findWorkItemTitle().vm.$emit('error', i18n.updateError); + findWorkItemTitle().vm.$emit('error', updateError); await waitForPromises(); - expect(findAlert().text()).toBe(i18n.updateError); + expect(findAlert().text()).toBe(updateError); }); it('calls the subscription', () => { @@ -456,11 +457,12 @@ describe('WorkItemDetail component', () => { it('shows an error message when it emits an `error` event', async () => { createComponent({ workItemsMvc2Enabled: true }); await waitForPromises(); + const updateError = 'Failed to update'; - findWorkItemWeight().vm.$emit('error', i18n.updateError); + findWorkItemWeight().vm.$emit('error', updateError); await waitForPromises(); - expect(findAlert().text()).toBe(i18n.updateError); + expect(findAlert().text()).toBe(updateError); }); }); diff --git a/spec/lib/gitlab/background_migration/backfill_cluster_agents_has_vulnerabilities_spec.rb b/spec/lib/gitlab/background_migration/backfill_cluster_agents_has_vulnerabilities_spec.rb new file mode 100644 index 00000000000..3aab0cdf54b --- /dev/null +++ b/spec/lib/gitlab/background_migration/backfill_cluster_agents_has_vulnerabilities_spec.rb @@ -0,0 +1,107 @@ +# frozen_string_literal: true + +require 'spec_helper' + +RSpec.describe Gitlab::BackgroundMigration::BackfillClusterAgentsHasVulnerabilities, :migration do # rubocop:disable Layout/LineLength + let(:migration) do + described_class.new(start_id: 1, end_id: 10, + batch_table: table_name, batch_column: batch_column, + sub_batch_size: sub_batch_size, pause_ms: pause_ms, + connection: ApplicationRecord.connection) + end + + let(:users_table) { table(:users) } + let(:vulnerability_reads_table) { table(:vulnerability_reads) } + let(:vulnerability_scanners_table) { table(:vulnerability_scanners) } + let(:vulnerabilities_table) { table(:vulnerabilities) } + let(:namespaces_table) { table(:namespaces) } + let(:projects_table) { table(:projects) } + let(:cluster_agents_table) { table(:cluster_agents) } + + let(:table_name) { 'cluster_agents' } + let(:batch_column) { :id } + let(:sub_batch_size) { 100 } + let(:pause_ms) { 0 } + + subject(:perform_migration) { migration.perform } + + before do + users_table.create!(id: 1, name: 'John Doe', email: 'test@example.com', projects_limit: 5) + + namespaces_table.create!(id: 1, name: 'Namespace 1', path: 'namespace-1') + namespaces_table.create!(id: 2, name: 'Namespace 2', path: 'namespace-2') + namespaces_table.create!(id: 3, name: 'Namespace 3', path: 'namespace-3') + + projects_table.create!(id: 1, namespace_id: 1, name: 'Project 1', path: 'project-1', project_namespace_id: 1) + projects_table.create!(id: 2, namespace_id: 2, name: 'Project 2', path: 'project-2', project_namespace_id: 2) + projects_table.create!(id: 3, namespace_id: 2, name: 'Project 3', path: 'project-3', project_namespace_id: 3) + + cluster_agents_table.create!(id: 1, name: 'Agent 1', project_id: 1) + cluster_agents_table.create!(id: 2, name: 'Agent 2', project_id: 2) + cluster_agents_table.create!(id: 3, name: 'Agent 3', project_id: 1) + cluster_agents_table.create!(id: 4, name: 'Agent 4', project_id: 1) + cluster_agents_table.create!(id: 5, name: 'Agent 5', project_id: 1) + cluster_agents_table.create!(id: 6, name: 'Agent 6', project_id: 1) + cluster_agents_table.create!(id: 7, name: 'Agent 7', project_id: 3) + cluster_agents_table.create!(id: 8, name: 'Agent 8', project_id: 1) + cluster_agents_table.create!(id: 9, name: 'Agent 9', project_id: 1) + cluster_agents_table.create!(id: 10, name: 'Agent 10', project_id: 3) + cluster_agents_table.create!(id: 11, name: 'Agent 11', project_id: 1) + + vulnerability_scanners_table.create!(id: 1, project_id: 1, external_id: 'starboard', name: 'Starboard') + vulnerability_scanners_table.create!(id: 2, project_id: 2, external_id: 'starboard', name: 'Starboard') + vulnerability_scanners_table.create!(id: 3, project_id: 3, external_id: 'starboard', name: 'Starboard') + + add_vulnerability_read!(1, project_id: 1, cluster_agent_id: 1, report_type: 7) + add_vulnerability_read!(2, project_id: 1, cluster_agent_id: nil, report_type: 7) + add_vulnerability_read!(3, project_id: 1, cluster_agent_id: 3, report_type: 7) + add_vulnerability_read!(4, project_id: 1, cluster_agent_id: nil, report_type: 7) + add_vulnerability_read!(5, project_id: 2, cluster_agent_id: 5, report_type: 5) + add_vulnerability_read!(7, project_id: 2, cluster_agent_id: 7, report_type: 7) + add_vulnerability_read!(9, project_id: 3, cluster_agent_id: 9, report_type: 7) + add_vulnerability_read!(10, project_id: 1, cluster_agent_id: 10, report_type: 7) + add_vulnerability_read!(11, project_id: 2, cluster_agent_id: 11, report_type: 7) + end + + it 'backfills `has_vulnerabilities` for the selected records', :aggregate_failures do + queries = ActiveRecord::QueryRecorder.new do + perform_migration + end + + expect(queries.count).to eq(3) + expect(cluster_agents_table.where(has_vulnerabilities: true).count).to eq 2 + expect(cluster_agents_table.where(has_vulnerabilities: true).pluck(:id)).to match_array([1, 3]) + end + + it 'tracks timings of queries' do + expect(migration.batch_metrics.timings).to be_empty + + expect { perform_migration }.to change { migration.batch_metrics.timings } + end + + private + + def add_vulnerability_read!(id, project_id:, cluster_agent_id:, report_type:) + vulnerabilities_table.create!( + id: id, + project_id: project_id, + author_id: 1, + title: "Vulnerability #{id}", + severity: 5, + confidence: 5, + report_type: report_type + ) + + vulnerability_reads_table.create!( + id: id, + uuid: SecureRandom.uuid, + severity: 5, + state: 1, + vulnerability_id: id, + scanner_id: project_id, + casted_cluster_agent_id: cluster_agent_id, + project_id: project_id, + report_type: report_type + ) + end +end diff --git a/spec/migrations/schedule_backfill_cluster_agents_has_vulnerabilities_spec.rb b/spec/migrations/schedule_backfill_cluster_agents_has_vulnerabilities_spec.rb new file mode 100644 index 00000000000..675cc332e69 --- /dev/null +++ b/spec/migrations/schedule_backfill_cluster_agents_has_vulnerabilities_spec.rb @@ -0,0 +1,24 @@ +# frozen_string_literal: true + +require 'spec_helper' +require_migration! + +RSpec.describe ScheduleBackfillClusterAgentsHasVulnerabilities do + let_it_be(:batched_migration) { described_class::MIGRATION } + + it 'schedules background jobs for each batch of cluster agents' do + reversible_migration do |migration| + migration.before -> { + expect(batched_migration).not_to have_scheduled_batched_migration + } + + migration.after -> { + expect(batched_migration).to have_scheduled_batched_migration( + table_name: :cluster_agents, + column_name: :id, + interval: described_class::DELAY_INTERVAL + ) + } + end + end +end diff --git a/spec/views/profiles/show.html.haml_spec.rb b/spec/views/profiles/show.html.haml_spec.rb index daa1d20e6b1..5751d47ee97 100644 --- a/spec/views/profiles/show.html.haml_spec.rb +++ b/spec/views/profiles/show.html.haml_spec.rb @@ -17,6 +17,11 @@ RSpec.describe 'profiles/show' do expect(rendered).to have_field('user_name', with: user.name) expect(rendered).to have_field('user_id', with: user.id) + + expectd_link = help_page_path('user/profile/index', anchor: 'change-the-email-displayed-on-your-commits') + expected_link_html = "<a href=\"#{expectd_link}\" target=\"_blank\" " \ + "rel=\"noopener noreferrer\">#{_('Learn more.')}</a>" + expect(rendered.include?(expected_link_html)).to eq(true) end end end |