diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2023-06-06 09:08:48 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2023-06-06 09:08:48 +0300 |
commit | c77b780ee080b978bd5a63f642f741e8892383dc (patch) | |
tree | 7c50ab6450a61d27485f9557b666af46ec5adfdd /spec/frontend/ci | |
parent | 5e448ff06309854c838fb5eaa46fd05ebc5218ab (diff) |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec/frontend/ci')
-rw-r--r-- | spec/frontend/ci/artifacts/components/artifact_row_spec.js | 52 | ||||
-rw-r--r-- | spec/frontend/ci/artifacts/components/job_artifacts_table_spec.js | 362 |
2 files changed, 182 insertions, 232 deletions
diff --git a/spec/frontend/ci/artifacts/components/artifact_row_spec.js b/spec/frontend/ci/artifacts/components/artifact_row_spec.js index 96ddedc3a9d..8bf1138bc85 100644 --- a/spec/frontend/ci/artifacts/components/artifact_row_spec.js +++ b/spec/frontend/ci/artifacts/components/artifact_row_spec.js @@ -4,7 +4,7 @@ import { numberToHumanSize } from '~/lib/utils/number_utils'; import { shallowMountExtended } from 'helpers/vue_test_utils_helper'; import waitForPromises from 'helpers/wait_for_promises'; import ArtifactRow from '~/ci/artifacts/components/artifact_row.vue'; -import { BULK_DELETE_FEATURE_FLAG, I18N_BULK_DELETE_MAX_SELECTED } from '~/ci/artifacts/constants'; +import { I18N_BULK_DELETE_MAX_SELECTED } from '~/ci/artifacts/constants'; describe('ArtifactRow component', () => { let wrapper; @@ -18,7 +18,7 @@ describe('ArtifactRow component', () => { const findDeleteButton = () => wrapper.findByTestId('job-artifact-row-delete-button'); const findCheckbox = () => wrapper.findComponent(GlFormCheckbox); - const createComponent = ({ canDestroyArtifacts = true, glFeatures = {}, props = {} } = {}) => { + const createComponent = ({ canDestroyArtifacts = true, props = {} } = {}) => { wrapper = shallowMountExtended(ArtifactRow, { propsData: { artifact, @@ -28,7 +28,7 @@ describe('ArtifactRow component', () => { isSelectedArtifactsLimitReached: false, ...props, }, - provide: { canDestroyArtifacts, glFeatures }, + provide: { canDestroyArtifacts }, stubs: { GlBadge, GlFriendlyWrap }, }); }; @@ -80,35 +80,31 @@ describe('ArtifactRow component', () => { }); describe('bulk delete checkbox', () => { - describe('with permission and feature flag enabled', () => { - it('emits selectArtifact when toggled', () => { - createComponent({ glFeatures: { [BULK_DELETE_FEATURE_FLAG]: true } }); - - findCheckbox().vm.$emit('input', true); + it('emits selectArtifact when toggled', () => { + createComponent(); - expect(wrapper.emitted('selectArtifact')).toStrictEqual([[artifact, true]]); - }); + findCheckbox().vm.$emit('input', true); - describe('when the selected artifacts limit is reached', () => { - it('remains enabled if the artifact was selected', () => { - createComponent({ - glFeatures: { [BULK_DELETE_FEATURE_FLAG]: true }, - props: { isSelected: true, isSelectedArtifactsLimitReached: true }, - }); + expect(wrapper.emitted('selectArtifact')).toStrictEqual([[artifact, true]]); + }); - expect(findCheckbox().attributes('disabled')).toBeUndefined(); - expect(findCheckbox().attributes('title')).toBe(''); + describe('when the selected artifacts limit is reached', () => { + it('remains enabled if the artifact was selected', () => { + createComponent({ + props: { isSelected: true, isSelectedArtifactsLimitReached: true }, }); - it('is disabled if the artifact was not selected', () => { - createComponent({ - glFeatures: { [BULK_DELETE_FEATURE_FLAG]: true }, - props: { isSelected: false, isSelectedArtifactsLimitReached: true }, - }); + expect(findCheckbox().attributes('disabled')).toBeUndefined(); + expect(findCheckbox().attributes('title')).toBe(''); + }); - expect(findCheckbox().attributes('disabled')).toBeDefined(); - expect(findCheckbox().attributes('title')).toBe(I18N_BULK_DELETE_MAX_SELECTED); + it('is disabled if the artifact was not selected', () => { + createComponent({ + props: { isSelected: false, isSelectedArtifactsLimitReached: true }, }); + + expect(findCheckbox().attributes('disabled')).toBeDefined(); + expect(findCheckbox().attributes('title')).toBe(I18N_BULK_DELETE_MAX_SELECTED); }); }); @@ -117,11 +113,5 @@ describe('ArtifactRow component', () => { expect(findCheckbox().exists()).toBe(false); }); - - it('is not shown with feature flag disabled', () => { - createComponent(); - - expect(findCheckbox().exists()).toBe(false); - }); }); }); diff --git a/spec/frontend/ci/artifacts/components/job_artifacts_table_spec.js b/spec/frontend/ci/artifacts/components/job_artifacts_table_spec.js index 9a16fac7406..e062140246b 100644 --- a/spec/frontend/ci/artifacts/components/job_artifacts_table_spec.js +++ b/spec/frontend/ci/artifacts/components/job_artifacts_table_spec.js @@ -30,7 +30,6 @@ import { JOBS_PER_PAGE, I18N_FETCH_ERROR, INITIAL_CURRENT_PAGE, - BULK_DELETE_FEATURE_FLAG, I18N_BULK_DELETE_ERROR, SELECTED_ARTIFACTS_MAX_COUNT, } from '~/ci/artifacts/constants'; @@ -152,7 +151,6 @@ describe('JobArtifactsTable component', () => { }, data = {}, canDestroyArtifacts = true, - glFeatures = {}, } = {}) => { requestHandlers = handlers; wrapper = mountExtended(JobArtifactsTable, { @@ -165,7 +163,6 @@ describe('JobArtifactsTable component', () => { projectId, canDestroyArtifacts, artifactsManagementFeedbackImagePath: 'banner/image/path', - glFeatures, }, mocks: { $toast: { @@ -332,6 +329,7 @@ describe('JobArtifactsTable component', () => { it('is disabled when there is no download path', async () => { const jobWithoutDownloadPath = { ...job, + hasArtifacts: true, archive: { downloadPath: null }, }; @@ -358,6 +356,7 @@ describe('JobArtifactsTable component', () => { it('is disabled when there is no browse path', async () => { const jobWithoutBrowsePath = { ...job, + hasArtifacts: true, browseArtifactsPath: null, }; @@ -407,75 +406,71 @@ describe('JobArtifactsTable component', () => { describe('delete button', () => { const artifactsFromJob = job.artifacts.nodes.map((node) => node.id); - describe('with delete permission and bulk delete feature flag enabled', () => { - beforeEach(async () => { - createComponent({ - canDestroyArtifacts: true, - glFeatures: { [BULK_DELETE_FEATURE_FLAG]: true }, - }); - - await waitForPromises(); + beforeEach(async () => { + createComponent({ + canDestroyArtifacts: true, }); - it('opens the confirmation modal with the artifacts from the job', async () => { - await findDeleteButton().vm.$emit('click'); - - expect(findBulkDeleteModal().props()).toMatchObject({ - visible: true, - artifactsToDelete: artifactsFromJob, - }); - }); + await waitForPromises(); + }); - it('on confirm, deletes the artifacts from the job and shows a toast', async () => { - findDeleteButton().vm.$emit('click'); - findBulkDeleteModal().vm.$emit('primary'); + it('opens the confirmation modal with the artifacts from the job', async () => { + await findDeleteButton().vm.$emit('click'); - expect(bulkDestroyMutationHandler).toHaveBeenCalledWith({ - projectId: convertToGraphQLId(TYPENAME_PROJECT, projectId), - ids: artifactsFromJob, - }); + expect(findBulkDeleteModal().props()).toMatchObject({ + visible: true, + artifactsToDelete: artifactsFromJob, + }); + }); - await waitForPromises(); + it('on confirm, deletes the artifacts from the job and shows a toast', async () => { + findDeleteButton().vm.$emit('click'); + findBulkDeleteModal().vm.$emit('primary'); - expect(mockToastShow).toHaveBeenCalledWith( - `${artifactsFromJob.length} selected artifacts deleted`, - ); + expect(bulkDestroyMutationHandler).toHaveBeenCalledWith({ + projectId: convertToGraphQLId(TYPENAME_PROJECT, projectId), + ids: artifactsFromJob, }); - it('does not clear selected artifacts on success', async () => { - // select job 2 via checkbox - findJobCheckbox(2).vm.$emit('change', true); + await waitForPromises(); - // click delete button job 1 - findDeleteButton().vm.$emit('click'); + expect(mockToastShow).toHaveBeenCalledWith( + `${artifactsFromJob.length} selected artifacts deleted`, + ); + }); - // job 2's artifacts should still be selected - expect(findBulkDelete().props('selectedArtifacts')).toStrictEqual( - job2.artifacts.nodes.map((node) => node.id), - ); + it('does not clear selected artifacts on success', async () => { + // select job 2 via checkbox + findJobCheckbox(2).vm.$emit('change', true); - // confirm delete - findBulkDeleteModal().vm.$emit('primary'); + // click delete button job 1 + findDeleteButton().vm.$emit('click'); - // job 1's artifacts should be deleted - expect(bulkDestroyMutationHandler).toHaveBeenCalledWith({ - projectId: convertToGraphQLId(TYPENAME_PROJECT, projectId), - ids: artifactsFromJob, - }); + // job 2's artifacts should still be selected + expect(findBulkDelete().props('selectedArtifacts')).toStrictEqual( + job2.artifacts.nodes.map((node) => node.id), + ); - await waitForPromises(); + // confirm delete + findBulkDeleteModal().vm.$emit('primary'); - // job 2's artifacts should still be selected - expect(findBulkDelete().props('selectedArtifacts')).toStrictEqual( - job2.artifacts.nodes.map((node) => node.id), - ); + // job 1's artifacts should be deleted + expect(bulkDestroyMutationHandler).toHaveBeenCalledWith({ + projectId: convertToGraphQLId(TYPENAME_PROJECT, projectId), + ids: artifactsFromJob, }); + + await waitForPromises(); + + // job 2's artifacts should still be selected + expect(findBulkDelete().props('selectedArtifacts')).toStrictEqual( + job2.artifacts.nodes.map((node) => node.id), + ); }); it('shows an alert and does not clear selected artifacts on error', async () => { createComponent({ canDestroyArtifacts: true, - glFeatures: { [BULK_DELETE_FEATURE_FLAG]: true }, handlers: { getJobArtifactsQuery: jest.fn().mockResolvedValue(getJobArtifactsResponse), bulkDestroyArtifactsMutation: jest.fn().mockRejectedValue(), @@ -505,21 +500,9 @@ describe('JobArtifactsTable component', () => { }); }); - it('is disabled when bulk delete feature flag is disabled', async () => { - createComponent({ - canDestroyArtifacts: true, - glFeatures: { [BULK_DELETE_FEATURE_FLAG]: false }, - }); - - await waitForPromises(); - - expect(findDeleteButton().attributes('disabled')).toBeDefined(); - }); - it('is hidden when user does not have delete permission', async () => { createComponent({ canDestroyArtifacts: false, - glFeatures: { [BULK_DELETE_FEATURE_FLAG]: false }, }); await waitForPromises(); @@ -531,175 +514,168 @@ describe('JobArtifactsTable component', () => { describe('bulk delete', () => { const selectedArtifacts = job.artifacts.nodes.map((node) => node.id); - describe('with permission and feature flag enabled', () => { - beforeEach(async () => { - createComponent({ - canDestroyArtifacts: true, - glFeatures: { [BULK_DELETE_FEATURE_FLAG]: true }, - }); - - await waitForPromises(); + beforeEach(async () => { + createComponent({ + canDestroyArtifacts: true, }); - it('shows selected artifacts when a job is checked', async () => { - expect(findBulkDeleteContainer().exists()).toBe(false); - - await findJobCheckbox().vm.$emit('change', true); + await waitForPromises(); + }); - expect(findBulkDeleteContainer().exists()).toBe(true); - expect(findBulkDelete().props('selectedArtifacts')).toStrictEqual(selectedArtifacts); - }); + it('shows selected artifacts when a job is checked', async () => { + expect(findBulkDeleteContainer().exists()).toBe(false); - it('disappears when selected artifacts are cleared', async () => { - await findJobCheckbox().vm.$emit('change', true); + await findJobCheckbox().vm.$emit('change', true); - expect(findBulkDeleteContainer().exists()).toBe(true); + expect(findBulkDeleteContainer().exists()).toBe(true); + expect(findBulkDelete().props('selectedArtifacts')).toStrictEqual(selectedArtifacts); + }); - await findBulkDelete().vm.$emit('clearSelectedArtifacts'); + it('disappears when selected artifacts are cleared', async () => { + await findJobCheckbox().vm.$emit('change', true); - expect(findBulkDeleteContainer().exists()).toBe(false); - }); + expect(findBulkDeleteContainer().exists()).toBe(true); - it('shows a modal to confirm bulk delete', async () => { - findJobCheckbox().vm.$emit('change', true); - findBulkDelete().vm.$emit('showBulkDeleteModal'); + await findBulkDelete().vm.$emit('clearSelectedArtifacts'); - await nextTick(); + expect(findBulkDeleteContainer().exists()).toBe(false); + }); - expect(findBulkDeleteModal().props('visible')).toBe(true); - }); + it('shows a modal to confirm bulk delete', async () => { + findJobCheckbox().vm.$emit('change', true); + findBulkDelete().vm.$emit('showBulkDeleteModal'); - it('deletes the selected artifacts and shows a toast', async () => { - findJobCheckbox().vm.$emit('change', true); - findBulkDelete().vm.$emit('showBulkDeleteModal'); - findBulkDeleteModal().vm.$emit('primary'); + await nextTick(); - expect(bulkDestroyMutationHandler).toHaveBeenCalledWith({ - projectId: convertToGraphQLId(TYPENAME_PROJECT, projectId), - ids: selectedArtifacts, - }); + expect(findBulkDeleteModal().props('visible')).toBe(true); + }); - await waitForPromises(); + it('deletes the selected artifacts and shows a toast', async () => { + findJobCheckbox().vm.$emit('change', true); + findBulkDelete().vm.$emit('showBulkDeleteModal'); + findBulkDeleteModal().vm.$emit('primary'); - expect(mockToastShow).toHaveBeenCalledWith( - `${selectedArtifacts.length} selected artifacts deleted`, - ); + expect(bulkDestroyMutationHandler).toHaveBeenCalledWith({ + projectId: convertToGraphQLId(TYPENAME_PROJECT, projectId), + ids: selectedArtifacts, }); - it('clears selected artifacts on success', async () => { - findJobCheckbox().vm.$emit('change', true); - findBulkDelete().vm.$emit('showBulkDeleteModal'); - findBulkDeleteModal().vm.$emit('primary'); + await waitForPromises(); - await waitForPromises(); + expect(mockToastShow).toHaveBeenCalledWith( + `${selectedArtifacts.length} selected artifacts deleted`, + ); + }); - expect(findBulkDelete().props('selectedArtifacts')).toStrictEqual([]); - }); + it('clears selected artifacts on success', async () => { + findJobCheckbox().vm.$emit('change', true); + findBulkDelete().vm.$emit('showBulkDeleteModal'); + findBulkDeleteModal().vm.$emit('primary'); - describe('select all checkbox', () => { - describe('when no artifacts are selected', () => { - it('is not checked', () => { - expect(findSelectAllCheckboxChecked()).toBe(false); - expect(findSelectAllCheckboxIndeterminate()).toBe(false); - }); + await waitForPromises(); - it('selects all artifacts when toggled', async () => { - toggleSelectAllCheckbox(); + expect(findBulkDelete().props('selectedArtifacts')).toStrictEqual([]); + }); - await nextTick(); + describe('select all checkbox', () => { + describe('when no artifacts are selected', () => { + it('is not checked', () => { + expect(findSelectAllCheckboxChecked()).toBe(false); + expect(findSelectAllCheckboxIndeterminate()).toBe(false); + }); - expect(findSelectAllCheckboxChecked()).toBe(true); - expect(findSelectAllCheckboxIndeterminate()).toBe(false); - expect(findBulkDelete().props('selectedArtifacts')).toStrictEqual(allArtifacts); - }); + it('selects all artifacts when toggled', async () => { + toggleSelectAllCheckbox(); + + await nextTick(); + + expect(findSelectAllCheckboxChecked()).toBe(true); + expect(findSelectAllCheckboxIndeterminate()).toBe(false); + expect(findBulkDelete().props('selectedArtifacts')).toStrictEqual(allArtifacts); }); + }); - describe('when some artifacts are selected', () => { - beforeEach(async () => { - findJobCheckbox().vm.$emit('change', true); + describe('when some artifacts are selected', () => { + beforeEach(async () => { + findJobCheckbox().vm.$emit('change', true); - await nextTick(); - }); + await nextTick(); + }); - it('is indeterminate', () => { - expect(findSelectAllCheckboxChecked()).toBe(true); - expect(findSelectAllCheckboxIndeterminate()).toBe(true); - }); + it('is indeterminate', () => { + expect(findSelectAllCheckboxChecked()).toBe(true); + expect(findSelectAllCheckboxIndeterminate()).toBe(true); + }); - it('deselects all artifacts when toggled', async () => { - toggleSelectAllCheckbox(); + it('deselects all artifacts when toggled', async () => { + toggleSelectAllCheckbox(); - await nextTick(); + await nextTick(); - expect(findSelectAllCheckboxChecked()).toBe(false); - expect(findBulkDelete().props('selectedArtifacts')).toStrictEqual([]); - }); + expect(findSelectAllCheckboxChecked()).toBe(false); + expect(findBulkDelete().props('selectedArtifacts')).toStrictEqual([]); }); + }); - describe('when all artifacts are selected', () => { - beforeEach(async () => { - findJobCheckbox(1).vm.$emit('change', true); - findJobCheckbox(2).vm.$emit('change', true); + describe('when all artifacts are selected', () => { + beforeEach(async () => { + findJobCheckbox(1).vm.$emit('change', true); + findJobCheckbox(2).vm.$emit('change', true); - await nextTick(); - }); + await nextTick(); + }); - it('is checked', () => { - expect(findSelectAllCheckboxChecked()).toBe(true); - expect(findSelectAllCheckboxIndeterminate()).toBe(false); - }); + it('is checked', () => { + expect(findSelectAllCheckboxChecked()).toBe(true); + expect(findSelectAllCheckboxIndeterminate()).toBe(false); + }); - it('deselects all artifacts when toggled', async () => { - toggleSelectAllCheckbox(); + it('deselects all artifacts when toggled', async () => { + toggleSelectAllCheckbox(); - await nextTick(); + await nextTick(); - expect(findSelectAllCheckboxChecked()).toBe(false); - expect(findBulkDelete().props('selectedArtifacts')).toStrictEqual([]); - }); + expect(findSelectAllCheckboxChecked()).toBe(false); + expect(findBulkDelete().props('selectedArtifacts')).toStrictEqual([]); }); + }); - describe('when an artifact is selected on another page', () => { - const otherPageArtifact = { id: 'gid://gitlab/Ci::JobArtifact/some/other/id' }; + describe('when an artifact is selected on another page', () => { + const otherPageArtifact = { id: 'gid://gitlab/Ci::JobArtifact/some/other/id' }; - beforeEach(async () => { - // expand the first job row to access the details component - findCount().trigger('click'); + beforeEach(async () => { + // expand the first job row to access the details component + findCount().trigger('click'); - await nextTick(); + await nextTick(); - // mock the selection of an artifact on another page by emitting a select event - findDetailsInRow(1).vm.$emit('selectArtifact', otherPageArtifact, true); - }); + // mock the selection of an artifact on another page by emitting a select event + findDetailsInRow(1).vm.$emit('selectArtifact', otherPageArtifact, true); + }); - it('is not checked even though an artifact is selected', () => { - expect(findBulkDelete().props('selectedArtifacts')).toStrictEqual([ - otherPageArtifact.id, - ]); - expect(findSelectAllCheckboxChecked()).toBe(false); - expect(findSelectAllCheckboxIndeterminate()).toBe(false); - }); + it('is not checked even though an artifact is selected', () => { + expect(findBulkDelete().props('selectedArtifacts')).toStrictEqual([otherPageArtifact.id]); + expect(findSelectAllCheckboxChecked()).toBe(false); + expect(findSelectAllCheckboxIndeterminate()).toBe(false); + }); - it('only toggles selection of visible artifacts, leaving the other artifact selected', async () => { - toggleSelectAllCheckbox(); + it('only toggles selection of visible artifacts, leaving the other artifact selected', async () => { + toggleSelectAllCheckbox(); - await nextTick(); + await nextTick(); - expect(findSelectAllCheckboxChecked()).toBe(true); - expect(findBulkDelete().props('selectedArtifacts')).toStrictEqual([ - otherPageArtifact.id, - ...allArtifacts, - ]); + expect(findSelectAllCheckboxChecked()).toBe(true); + expect(findBulkDelete().props('selectedArtifacts')).toStrictEqual([ + otherPageArtifact.id, + ...allArtifacts, + ]); - toggleSelectAllCheckbox(); + toggleSelectAllCheckbox(); - await nextTick(); + await nextTick(); - expect(findSelectAllCheckboxChecked()).toBe(false); - expect(findBulkDelete().props('selectedArtifacts')).toStrictEqual([ - otherPageArtifact.id, - ]); - }); + expect(findSelectAllCheckboxChecked()).toBe(false); + expect(findBulkDelete().props('selectedArtifacts')).toStrictEqual([otherPageArtifact.id]); }); }); }); @@ -711,7 +687,6 @@ describe('JobArtifactsTable component', () => { beforeEach(async () => { createComponent({ canDestroyArtifacts: true, - glFeatures: { [BULK_DELETE_FEATURE_FLAG]: true }, data: { selectedArtifacts: new Array(selectedArtifactsLength).fill('artifact-id'), }, @@ -742,7 +717,6 @@ describe('JobArtifactsTable component', () => { beforeEach(async () => { createComponent({ canDestroyArtifacts: true, - glFeatures: { [BULK_DELETE_FEATURE_FLAG]: true }, data: { selectedArtifacts: maxSelectedArtifacts }, }); @@ -775,7 +749,6 @@ describe('JobArtifactsTable component', () => { beforeEach(async () => { createComponent({ canDestroyArtifacts: true, - glFeatures: { [BULK_DELETE_FEATURE_FLAG]: true }, data: { selectedArtifacts: maxSelectedArtifactsIncludingCurrentPage, }, @@ -811,7 +784,6 @@ describe('JobArtifactsTable component', () => { it('shows an alert and does not clear selected artifacts on error', async () => { createComponent({ canDestroyArtifacts: true, - glFeatures: { [BULK_DELETE_FEATURE_FLAG]: true }, handlers: { getJobArtifactsQuery: jest.fn().mockResolvedValue(getJobArtifactsResponse), bulkDestroyArtifactsMutation: jest.fn().mockRejectedValue(), @@ -837,18 +809,6 @@ describe('JobArtifactsTable component', () => { it('shows no checkboxes without permission', async () => { createComponent({ canDestroyArtifacts: false, - glFeatures: { [BULK_DELETE_FEATURE_FLAG]: true }, - }); - - await waitForPromises(); - - expect(findAnyCheckbox().exists()).toBe(false); - }); - - it('shows no checkboxes with feature flag disabled', async () => { - createComponent({ - canDestroyArtifacts: true, - glFeatures: { [BULK_DELETE_FEATURE_FLAG]: false }, }); await waitForPromises(); |