diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2022-08-19 09:09:31 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2022-08-19 09:09:31 +0300 |
commit | 8c68904468d88beaeb618bfe81289a6c1eb8538c (patch) | |
tree | af8e70ac99ec5bc1692f1e02d5c9499b3bb68e42 /spec | |
parent | b0c61201a70f1980dc5a2454d979b95415455d14 (diff) |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec')
12 files changed, 238 insertions, 179 deletions
diff --git a/spec/features/work_items/work_item_children_spec.rb b/spec/features/work_items/work_item_children_spec.rb new file mode 100644 index 00000000000..c50d3b64dc0 --- /dev/null +++ b/spec/features/work_items/work_item_children_spec.rb @@ -0,0 +1,110 @@ +# frozen_string_literal: true + +require 'spec_helper' + +RSpec.describe 'Work item children', :js do + let_it_be(:group) { create(:group) } + let_it_be(:project) { create(:project, :public, namespace: group) } + let_it_be(:user) { create(:user) } + let_it_be(:issue) { create(:issue, project: project) } + + context 'for signed in user' do + before do + project.add_developer(user) + + sign_in(user) + + stub_feature_flags(work_items: true) + stub_feature_flags(work_items_hierarchy: true) + + visit project_issue_path(project, issue) + + wait_for_requests + end + + it 'are not displayed when issue does not have work item children', :aggregate_failures do + page.within('[data-testid="work-item-links"]') do + expect(find('[data-testid="links-empty"]')).to have_content(_('No child items are currently assigned.')) + expect(page).not_to have_selector('[data-testid="add-links-form"]') + expect(page).not_to have_selector('[data-testid="links-child"]') + end + end + + it 'toggles widget body', :aggregate_failures do + page.within('[data-testid="work-item-links"]') do + expect(page).to have_selector('[data-testid="links-body"]') + + click_button 'Collapse child items' + + expect(page).not_to have_selector('[data-testid="links-body"]') + + click_button 'Expand child items' + + expect(page).to have_selector('[data-testid="links-body"]') + end + end + + it 'toggles form', :aggregate_failures do + page.within('[data-testid="work-item-links"]') do + expect(page).not_to have_selector('[data-testid="add-links-form"]') + + click_button 'Add a task' + + expect(page).to have_selector('[data-testid="add-links-form"]') + + click_button 'Cancel' + + expect(page).not_to have_selector('[data-testid="add-links-form"]') + end + end + + it 'addss a child task', :aggregate_failures do + page.within('[data-testid="work-item-links"]') do + click_button 'Add a task' + + expect(page).to have_button('Create task', disabled: true) + fill_in 'Add a title', with: 'Task 1' + + expect(page).to have_button('Create task', disabled: false) + + click_button 'Create task' + + wait_for_all_requests + + expect(find('[data-testid="links-child"]')).to have_content('Task 1') + end + end + + it 'removes a child task and undoing', :aggregate_failures do + page.within('[data-testid="work-item-links"]') do + click_button 'Add a task' + fill_in 'Add a title', with: 'Task 1' + click_button 'Create task' + wait_for_all_requests + + expect(find('[data-testid="links-child"]')).to have_content('Task 1') + expect(find('[data-testid="children-count"]')).to have_content('1') + + find('[data-testid="links-menu"]').click + click_button 'Remove' + + wait_for_all_requests + + expect(page).not_to have_content('Task 1') + expect(find('[data-testid="children-count"]')).to have_content('0') + end + + page.within('.gl-toast') do + expect(find('.toast-body')).to have_content(_('Child removed')) + find('.b-toaster a', text: 'Undo').click + end + + wait_for_all_requests + + page.within('[data-testid="work-item-links"]') do + expect(find('[data-testid="links-child"]')).to have_content('Task 1') + expect(find('[data-testid="children-count"]')).to have_content('1') + end + end + end +end diff --git a/spec/frontend/jobs/components/environments_block_spec.js b/spec/frontend/jobs/components/environments_block_spec.js index d90c9137a8f..5a2b6988224 100644 --- a/spec/frontend/jobs/components/environments_block_spec.js +++ b/spec/frontend/jobs/components/environments_block_spec.js @@ -46,7 +46,7 @@ describe('Environments block', () => { }); }; - const findText = () => wrapper.find(EnvironmentsBlock).text(); + const findText = () => wrapper.findComponent(EnvironmentsBlock).text(); const findJobDeploymentLink = () => wrapper.find('[data-testid="job-deployment-link"]'); const findEnvironmentLink = () => wrapper.find('[data-testid="job-environment-link"]'); const findClusterLink = () => wrapper.find('[data-testid="job-cluster-link"]'); diff --git a/spec/frontend/jobs/components/erased_block_spec.js b/spec/frontend/jobs/components/erased_block_spec.js index 057df20ccc2..7b44458c18b 100644 --- a/spec/frontend/jobs/components/erased_block_spec.js +++ b/spec/frontend/jobs/components/erased_block_spec.js @@ -10,7 +10,7 @@ describe('Erased block', () => { const timeago = getTimeago(); const formattedDate = timeago.format(erasedAt); - const findLink = () => wrapper.find(GlLink); + const findLink = () => wrapper.findComponent(GlLink); const createComponent = (props) => { wrapper = mount(ErasedBlock, { diff --git a/spec/frontend/jobs/components/job_app_spec.js b/spec/frontend/jobs/components/job_app_spec.js index b4b5bc4669d..d028b65f075 100644 --- a/spec/frontend/jobs/components/job_app_spec.js +++ b/spec/frontend/jobs/components/job_app_spec.js @@ -57,18 +57,18 @@ describe('Job App', () => { await nextTick(); }; - const findLoadingComponent = () => wrapper.find(GlLoadingIcon); - const findSidebar = () => wrapper.find(Sidebar); + const findLoadingComponent = () => wrapper.findComponent(GlLoadingIcon); + const findSidebar = () => wrapper.findComponent(Sidebar); const findJobContent = () => wrapper.find('[data-testid="job-content"'); - const findStuckBlockComponent = () => wrapper.find(StuckBlock); + const findStuckBlockComponent = () => wrapper.findComponent(StuckBlock); const findStuckBlockWithTags = () => wrapper.find('[data-testid="job-stuck-with-tags"'); const findStuckBlockNoActiveRunners = () => wrapper.find('[data-testid="job-stuck-no-active-runners"'); - const findFailedJobComponent = () => wrapper.find(UnmetPrerequisitesBlock); - const findEnvironmentsBlockComponent = () => wrapper.find(EnvironmentsBlock); - const findErasedBlock = () => wrapper.find(ErasedBlock); + const findFailedJobComponent = () => wrapper.findComponent(UnmetPrerequisitesBlock); + const findEnvironmentsBlockComponent = () => wrapper.findComponent(EnvironmentsBlock); + const findErasedBlock = () => wrapper.findComponent(ErasedBlock); const findArchivedJob = () => wrapper.find('[data-testid="archived-job"]'); - const findEmptyState = () => wrapper.find(EmptyState); + const findEmptyState = () => wrapper.findComponent(EmptyState); const findJobNewIssueLink = () => wrapper.find('[data-testid="job-new-issue"]'); const findJobEmptyStateTitle = () => wrapper.find('[data-testid="job-empty-state-title"]'); const findJobLogScrollTop = () => wrapper.find('[data-testid="job-controller-scroll-top"]'); diff --git a/spec/frontend/jobs/components/job_retry_forward_deployment_modal_spec.js b/spec/frontend/jobs/components/job_retry_forward_deployment_modal_spec.js index 08973223c08..fa6a3b5d350 100644 --- a/spec/frontend/jobs/components/job_retry_forward_deployment_modal_spec.js +++ b/spec/frontend/jobs/components/job_retry_forward_deployment_modal_spec.js @@ -10,8 +10,8 @@ describe('Job Retry Forward Deployment Modal', () => { let wrapper; const retryOutdatedJobDocsUrl = 'url-to-docs'; - const findLink = () => wrapper.find(GlLink); - const findModal = () => wrapper.find(GlModal); + const findLink = () => wrapper.findComponent(GlLink); + const findModal = () => wrapper.findComponent(GlModal); const createWrapper = ({ props = {}, provide = {}, stubs = {} } = {}) => { store = createStore(); diff --git a/spec/frontend/jobs/components/job_sidebar_details_container_spec.js b/spec/frontend/jobs/components/job_sidebar_details_container_spec.js index 4046f0269dd..a398f998dff 100644 --- a/spec/frontend/jobs/components/job_sidebar_details_container_spec.js +++ b/spec/frontend/jobs/components/job_sidebar_details_container_spec.js @@ -11,7 +11,7 @@ describe('Job Sidebar Details Container', () => { const findJobTimeout = () => wrapper.findByTestId('job-timeout'); const findJobTags = () => wrapper.findByTestId('job-tags'); - const findAllDetailsRow = () => wrapper.findAll(DetailRow); + const findAllDetailsRow = () => wrapper.findAllComponents(DetailRow); const createWrapper = ({ props = {} } = {}) => { store = createStore(); diff --git a/spec/frontend/jobs/components/log/line_header_spec.js b/spec/frontend/jobs/components/log/line_header_spec.js index bdc8ae0eef0..ec8e79bba13 100644 --- a/spec/frontend/jobs/components/log/line_header_spec.js +++ b/spec/frontend/jobs/components/log/line_header_spec.js @@ -39,7 +39,7 @@ describe('Job Log Header Line', () => { }); it('renders the line number component', () => { - expect(wrapper.find(LineNumber).exists()).toBe(true); + expect(wrapper.findComponent(LineNumber).exists()).toBe(true); }); it('renders a span the provided text', () => { @@ -90,7 +90,7 @@ describe('Job Log Header Line', () => { }); it('renders the duration badge', () => { - expect(wrapper.find(DurationBadge).exists()).toBe(true); + expect(wrapper.findComponent(DurationBadge).exists()).toBe(true); }); }); }); diff --git a/spec/frontend/jobs/components/log/line_spec.js b/spec/frontend/jobs/components/log/line_spec.js index bf80d90e299..50ebd1610d2 100644 --- a/spec/frontend/jobs/components/log/line_spec.js +++ b/spec/frontend/jobs/components/log/line_spec.js @@ -42,7 +42,7 @@ describe('Job Log Line', () => { }); it('renders the line number component', () => { - expect(wrapper.find(LineNumber).exists()).toBe(true); + expect(wrapper.findComponent(LineNumber).exists()).toBe(true); }); it('renders a span the provided text', () => { diff --git a/spec/frontend/jobs/components/sidebar_spec.js b/spec/frontend/jobs/components/sidebar_spec.js index 39c71986ce4..9a4720bf97b 100644 --- a/spec/frontend/jobs/components/sidebar_spec.js +++ b/spec/frontend/jobs/components/sidebar_spec.js @@ -15,11 +15,11 @@ describe('Sidebar details block', () => { let wrapper; const forwardDeploymentFailure = 'forward_deployment_failure'; - const findModal = () => wrapper.find(JobRetryForwardDeploymentModal); + const findModal = () => wrapper.findComponent(JobRetryForwardDeploymentModal); const findArtifactsBlock = () => wrapper.findComponent(ArtifactsBlock); const findCancelButton = () => wrapper.findByTestId('cancel-button'); const findNewIssueButton = () => wrapper.findByTestId('job-new-issue'); - const findRetryButton = () => wrapper.find(JobRetryButton); + const findRetryButton = () => wrapper.findComponent(JobRetryButton); const findTerminalLink = () => wrapper.findByTestId('terminal-link'); const findEraseLink = () => wrapper.findByTestId('job-log-erase-link'); @@ -176,7 +176,7 @@ describe('Sidebar details block', () => { describe('with stages', () => { it('renders value provided as selectedStage as selected', () => { - expect(wrapper.find(StagesDropdown).props('selectedStage')).toBe('aStage'); + expect(wrapper.findComponent(StagesDropdown).props('selectedStage')).toBe('aStage'); }); }); @@ -184,7 +184,7 @@ describe('Sidebar details block', () => { beforeEach(() => store.dispatch('receiveJobSuccess', job)); it('does not render jobs container', () => { - expect(wrapper.find(JobsContainer).exists()).toBe(false); + expect(wrapper.findComponent(JobsContainer).exists()).toBe(false); }); }); @@ -195,7 +195,7 @@ describe('Sidebar details block', () => { }); it('renders list of jobs', () => { - expect(wrapper.find(JobsContainer).exists()).toBe(true); + expect(wrapper.findComponent(JobsContainer).exists()).toBe(true); }); }); }); diff --git a/spec/frontend/jobs/components/stuck_block_spec.js b/spec/frontend/jobs/components/stuck_block_spec.js index 1580ed45e46..119255cc1e9 100644 --- a/spec/frontend/jobs/components/stuck_block_spec.js +++ b/spec/frontend/jobs/components/stuck_block_spec.js @@ -26,8 +26,8 @@ describe('Stuck Block Job component', () => { wrapper.find('[data-testid="job-stuck-no-active-runners"]'); const findStuckNoRunners = () => wrapper.find('[data-testid="job-stuck-no-runners"]'); const findStuckWithTags = () => wrapper.find('[data-testid="job-stuck-with-tags"]'); - const findRunnerPathLink = () => wrapper.find(GlLink); - const findAllBadges = () => wrapper.findAll(GlBadge); + const findRunnerPathLink = () => wrapper.findComponent(GlLink); + const findAllBadges = () => wrapper.findAllComponents(GlBadge); describe('with no runners for project', () => { beforeEach(() => { diff --git a/spec/frontend/jobs/components/unmet_prerequisites_block_spec.js b/spec/frontend/jobs/components/unmet_prerequisites_block_spec.js index aeb85694e60..d1dbd65bd17 100644 --- a/spec/frontend/jobs/components/unmet_prerequisites_block_spec.js +++ b/spec/frontend/jobs/components/unmet_prerequisites_block_spec.js @@ -23,7 +23,7 @@ describe('Unmet Prerequisites Block Job component', () => { }); it('renders an alert with the correct message', () => { - const container = wrapper.find(GlAlert); + const container = wrapper.findComponent(GlAlert); const alertMessage = 'This job failed because the necessary resources were not successfully created.'; @@ -32,7 +32,7 @@ describe('Unmet Prerequisites Block Job component', () => { }); it('renders link to help page', () => { - const helpLink = wrapper.find(GlLink); + const helpLink = wrapper.findComponent(GlLink); expect(helpLink).not.toBeNull(); expect(helpLink.text()).toContain('More information'); diff --git a/spec/lib/gitlab/ci/parsers/security/validators/schema_validator_spec.rb b/spec/lib/gitlab/ci/parsers/security/validators/schema_validator_spec.rb index 7828aa99f6a..0f87ee82733 100644 --- a/spec/lib/gitlab/ci/parsers/security/validators/schema_validator_spec.rb +++ b/spec/lib/gitlab/ci/parsers/security/validators/schema_validator_spec.rb @@ -21,6 +21,51 @@ RSpec.describe Gitlab::Ci::Parsers::Security::Validators::SchemaValidator do let(:validator) { described_class.new(report_type, report_data, report_version, project: project, scanner: scanner) } + shared_examples 'report is valid' do + context 'and the report is valid' do + let(:report_data) do + { + 'version' => report_version, + 'vulnerabilities' => [] + } + end + + it { is_expected.to be_truthy } + end + end + + shared_examples 'logs related information' do + it 'logs related information' do + expect(Gitlab::AppLogger).to receive(:info).with( + message: "security report schema validation problem", + security_report_type: report_type, + security_report_version: report_version, + project_id: project.id, + security_report_failure: security_report_failure, + security_report_scanner_id: 'gemnasium', + security_report_scanner_version: '2.1.0' + ) + + subject + end + end + + shared_examples 'report is invalid' do + context 'and the report is invalid' do + let(:report_data) do + { + 'version' => report_version + } + end + + let(:security_report_failure) { 'schema_validation_fails' } + + it { is_expected.to be_falsey } + + it_behaves_like 'logs related information' + end + end + describe 'SUPPORTED_VERSIONS' do schema_path = Rails.root.join("lib", "gitlab", "ci", "parsers", "security", "validators", "schemas") @@ -75,80 +120,16 @@ RSpec.describe Gitlab::Ci::Parsers::Security::Validators::SchemaValidator do (latest_vendored_version[0...2] << "34").join(".") end - context 'and the report is valid' do - let(:report_data) do - { - 'version' => report_version, - 'vulnerabilities' => [] - } - end - - it { is_expected.to be_truthy } - end - - context 'and the report is invalid' do - let(:report_data) do - { - 'version' => report_version - } - end - - it { is_expected.to be_falsey } - - it 'logs related information' do - expect(Gitlab::AppLogger).to receive(:info).with( - message: "security report schema validation problem", - security_report_type: report_type, - security_report_version: report_version, - project_id: project.id, - security_report_failure: 'schema_validation_fails', - security_report_scanner_id: 'gemnasium', - security_report_scanner_version: '2.1.0' - ) - - subject - end - end + it_behaves_like 'report is valid' + it_behaves_like 'report is invalid' end context 'when given a supported schema version' do let(:report_type) { :dast } let(:report_version) { described_class::SUPPORTED_VERSIONS[report_type].last } - context 'and the report is valid' do - let(:report_data) do - { - 'version' => report_version, - 'vulnerabilities' => [] - } - end - - it { is_expected.to be_truthy } - end - - context 'and the report is invalid' do - let(:report_data) do - { - 'version' => report_version - } - end - - it { is_expected.to be_falsey } - - it 'logs related information' do - expect(Gitlab::AppLogger).to receive(:info).with( - message: "security report schema validation problem", - security_report_type: report_type, - security_report_version: report_version, - project_id: project.id, - security_report_failure: 'schema_validation_fails', - security_report_scanner_id: 'gemnasium', - security_report_scanner_version: '2.1.0' - ) - - subject - end - end + it_behaves_like 'report is valid' + it_behaves_like 'report is invalid' end context 'when given a deprecated schema version' do @@ -173,21 +154,11 @@ RSpec.describe Gitlab::Ci::Parsers::Security::Validators::SchemaValidator do } end + let(:security_report_failure) { 'using_deprecated_schema_version' } + it { is_expected.to be_truthy } - it 'logs related information' do - expect(Gitlab::AppLogger).to receive(:info).with( - message: "security report schema validation problem", - security_report_type: report_type, - security_report_version: report_version, - project_id: project.id, - security_report_failure: 'using_deprecated_schema_version', - security_report_scanner_id: 'gemnasium', - security_report_scanner_version: '2.1.0' - ) - - subject - end + it_behaves_like 'logs related information' end context 'and the report does not pass schema validation' do @@ -213,21 +184,11 @@ RSpec.describe Gitlab::Ci::Parsers::Security::Validators::SchemaValidator do } end + let(:security_report_failure) { 'using_unsupported_schema_version' } + it { is_expected.to be_falsey } - it 'logs related information' do - expect(Gitlab::AppLogger).to receive(:info).with( - message: "security report schema validation problem", - security_report_type: report_type, - security_report_version: report_version, - project_id: project.id, - security_report_failure: 'using_unsupported_schema_version', - security_report_scanner_id: 'gemnasium', - security_report_scanner_version: '2.1.0' - ) - - subject - end + it_behaves_like 'logs related information' end context 'and the report is invalid' do @@ -282,6 +243,23 @@ RSpec.describe Gitlab::Ci::Parsers::Security::Validators::SchemaValidator do end end + shared_examples 'report is valid with no error' do + context 'and the report is valid' do + let(:report_data) do + { + 'version' => report_version, + 'vulnerabilities' => [] + } + end + + it { is_expected.to be_empty } + end + end + + shared_examples 'report with expected errors' do + it { is_expected.to match_array(expected_errors) } + end + describe '#errors' do subject { validator.errors } @@ -289,16 +267,7 @@ RSpec.describe Gitlab::Ci::Parsers::Security::Validators::SchemaValidator do let(:report_type) { :dast } let(:report_version) { described_class::SUPPORTED_VERSIONS[report_type].last } - context 'and the report is valid' do - let(:report_data) do - { - 'version' => report_version, - 'vulnerabilities' => [] - } - end - - it { is_expected.to be_empty } - end + it_behaves_like 'report is valid with no error' context 'and the report is invalid' do let(:report_data) do @@ -313,7 +282,7 @@ RSpec.describe Gitlab::Ci::Parsers::Security::Validators::SchemaValidator do ] end - it { is_expected.to match_array(expected_errors) } + it_behaves_like 'report with expected errors' end end @@ -331,16 +300,7 @@ RSpec.describe Gitlab::Ci::Parsers::Security::Validators::SchemaValidator do stub_const("#{described_class}::DEPRECATED_VERSIONS", deprecations_hash) end - context 'and the report passes schema validation' do - let(:report_data) do - { - 'version' => '10.0.0', - 'vulnerabilities' => [] - } - end - - it { is_expected.to be_empty } - end + it_behaves_like 'report is valid with no error' context 'and the report does not pass schema validation' do let(:report_data) do @@ -356,7 +316,7 @@ RSpec.describe Gitlab::Ci::Parsers::Security::Validators::SchemaValidator do ] end - it { is_expected.to match_array(expected_errors) } + it_behaves_like 'report with expected errors' end end @@ -383,7 +343,7 @@ RSpec.describe Gitlab::Ci::Parsers::Security::Validators::SchemaValidator do ] end - it { is_expected.to match_array(expected_errors) } + it_behaves_like 'report with expected errors' end context 'and the report is invalid' do @@ -400,7 +360,7 @@ RSpec.describe Gitlab::Ci::Parsers::Security::Validators::SchemaValidator do ] end - it { is_expected.to match_array(expected_errors) } + it_behaves_like 'report with expected errors' end end @@ -426,10 +386,27 @@ RSpec.describe Gitlab::Ci::Parsers::Security::Validators::SchemaValidator do ] end - it { is_expected.to match_array(expected_errors) } + it_behaves_like 'report with expected errors' end end + shared_examples 'report is valid with no warning' do + context 'and the report is valid' do + let(:report_data) do + { + 'version' => report_version, + 'vulnerabilities' => [] + } + end + + it { is_expected.to be_empty } + end + end + + shared_examples 'report with expected warnings' do + it { is_expected.to match_array(expected_deprecation_warnings) } + end + describe '#deprecation_warnings' do subject { validator.deprecation_warnings } @@ -491,7 +468,7 @@ RSpec.describe Gitlab::Ci::Parsers::Security::Validators::SchemaValidator do } end - it { is_expected.to match_array(expected_deprecation_warnings) } + it_behaves_like 'report with expected warnings' end context 'and the report does not pass schema validation' do @@ -501,7 +478,7 @@ RSpec.describe Gitlab::Ci::Parsers::Security::Validators::SchemaValidator do } end - it { is_expected.to match_array(expected_deprecation_warnings) } + it_behaves_like 'report with expected warnings' end end @@ -516,7 +493,7 @@ RSpec.describe Gitlab::Ci::Parsers::Security::Validators::SchemaValidator do } end - it { is_expected.to match_array(expected_deprecation_warnings) } + it_behaves_like 'report with expected warnings' end end @@ -561,21 +538,11 @@ RSpec.describe Gitlab::Ci::Parsers::Security::Validators::SchemaValidator do } end + let(:security_report_failure) { 'schema_validation_fails' } + it { is_expected.to match_array([message]) } - it 'logs related information' do - expect(Gitlab::AppLogger).to receive(:info).with( - message: "security report schema validation problem", - security_report_type: report_type, - security_report_version: report_version, - project_id: project.id, - security_report_failure: 'schema_validation_fails', - security_report_scanner_id: 'gemnasium', - security_report_scanner_version: '2.1.0' - ) - - subject - end + it_behaves_like 'logs related information' end end @@ -583,16 +550,7 @@ RSpec.describe Gitlab::Ci::Parsers::Security::Validators::SchemaValidator do let(:report_type) { :dast } let(:report_version) { described_class::SUPPORTED_VERSIONS[report_type].last } - context 'and the report is valid' do - let(:report_data) do - { - 'version' => report_version, - 'vulnerabilities' => [] - } - end - - it { is_expected.to be_empty } - end + it_behaves_like 'report is valid with no warning' context 'and the report is invalid' do let(:report_data) do @@ -644,16 +602,7 @@ RSpec.describe Gitlab::Ci::Parsers::Security::Validators::SchemaValidator do let(:report_type) { :dast } let(:report_version) { "12.37.0" } - context 'and the report is valid' do - let(:report_data) do - { - 'version' => report_version, - 'vulnerabilities' => [] - } - end - - it { is_expected.to be_empty } - end + it_behaves_like 'report is valid with no warning' context 'and the report is invalid' do let(:report_data) do |