diff options
Diffstat (limited to 'spec/frontend/pipelines/components/jobs')
3 files changed, 0 insertions, 348 deletions
diff --git a/spec/frontend/pipelines/components/jobs/failed_jobs_app_spec.js b/spec/frontend/pipelines/components/jobs/failed_jobs_app_spec.js deleted file mode 100644 index 6a2453704db..00000000000 --- a/spec/frontend/pipelines/components/jobs/failed_jobs_app_spec.js +++ /dev/null @@ -1,80 +0,0 @@ -import { GlLoadingIcon } from '@gitlab/ui'; -import { shallowMount } from '@vue/test-utils'; -import Vue from 'vue'; -import VueApollo from 'vue-apollo'; -import createMockApollo from 'helpers/mock_apollo_helper'; -import waitForPromises from 'helpers/wait_for_promises'; -import { createAlert } from '~/alert'; -import FailedJobsApp from '~/pipelines/components/jobs/failed_jobs_app.vue'; -import FailedJobsTable from '~/pipelines/components/jobs/failed_jobs_table.vue'; -import GetFailedJobsQuery from '~/pipelines/graphql/queries/get_failed_jobs.query.graphql'; -import { mockFailedJobsQueryResponse } from '../../mock_data'; - -Vue.use(VueApollo); - -jest.mock('~/alert'); - -describe('Failed Jobs App', () => { - let wrapper; - let resolverSpy; - - const findLoadingSpinner = () => wrapper.findComponent(GlLoadingIcon); - const findJobsTable = () => wrapper.findComponent(FailedJobsTable); - - const createMockApolloProvider = (resolver) => { - const requestHandlers = [[GetFailedJobsQuery, resolver]]; - - return createMockApollo(requestHandlers); - }; - - const createComponent = (resolver) => { - wrapper = shallowMount(FailedJobsApp, { - provide: { - fullPath: 'root/ci-project', - pipelineIid: 1, - }, - apolloProvider: createMockApolloProvider(resolver), - }); - }; - - beforeEach(() => { - resolverSpy = jest.fn().mockResolvedValue(mockFailedJobsQueryResponse); - }); - - describe('loading spinner', () => { - it('displays loading spinner when fetching failed jobs', () => { - createComponent(resolverSpy); - - expect(findLoadingSpinner().exists()).toBe(true); - }); - - it('hides loading spinner after the failed jobs have been fetched', async () => { - createComponent(resolverSpy); - - await waitForPromises(); - - expect(findLoadingSpinner().exists()).toBe(false); - }); - }); - - it('displays the failed jobs table', async () => { - createComponent(resolverSpy); - - await waitForPromises(); - - expect(findJobsTable().exists()).toBe(true); - expect(createAlert).not.toHaveBeenCalled(); - }); - - it('handles query fetch error correctly', async () => { - resolverSpy = jest.fn().mockRejectedValue(new Error('GraphQL error')); - - createComponent(resolverSpy); - - await waitForPromises(); - - expect(createAlert).toHaveBeenCalledWith({ - message: 'There was a problem fetching the failed jobs.', - }); - }); -}); diff --git a/spec/frontend/pipelines/components/jobs/failed_jobs_table_spec.js b/spec/frontend/pipelines/components/jobs/failed_jobs_table_spec.js deleted file mode 100644 index 99a178120cc..00000000000 --- a/spec/frontend/pipelines/components/jobs/failed_jobs_table_spec.js +++ /dev/null @@ -1,141 +0,0 @@ -import { GlButton, GlLink, GlTableLite } from '@gitlab/ui'; -import Vue from 'vue'; -import VueApollo from 'vue-apollo'; -import createMockApollo from 'helpers/mock_apollo_helper'; -import { mockTracking, unmockTracking } from 'helpers/tracking_helper'; -import waitForPromises from 'helpers/wait_for_promises'; -import { mountExtended } from 'helpers/vue_test_utils_helper'; -import { createAlert } from '~/alert'; -import { redirectTo } from '~/lib/utils/url_utility'; // eslint-disable-line import/no-deprecated -import FailedJobsTable from '~/pipelines/components/jobs/failed_jobs_table.vue'; -import RetryFailedJobMutation from '~/pipelines/graphql/mutations/retry_failed_job.mutation.graphql'; -import { TRACKING_CATEGORIES } from '~/pipelines/constants'; -import { - successRetryMutationResponse, - failedRetryMutationResponse, - mockFailedJobsData, - mockFailedJobsDataNoPermission, -} from '../../mock_data'; - -jest.mock('~/alert'); -jest.mock('~/lib/utils/url_utility'); - -Vue.use(VueApollo); - -describe('Failed Jobs Table', () => { - let wrapper; - - const successRetryMutationHandler = jest.fn().mockResolvedValue(successRetryMutationResponse); - const failedRetryMutationHandler = jest.fn().mockResolvedValue(failedRetryMutationResponse); - - const findJobsTable = () => wrapper.findComponent(GlTableLite); - const findRetryButton = () => wrapper.findComponent(GlButton); - const findJobLink = () => wrapper.findComponent(GlLink); - const findJobLog = () => wrapper.findByTestId('job-log'); - const findSummary = (index) => wrapper.findAllByTestId('job-trace-summary').at(index); - const findFirstFailureMessage = () => wrapper.findAllByTestId('job-failure-message').at(0); - - const createMockApolloProvider = (resolver) => { - const requestHandlers = [[RetryFailedJobMutation, resolver]]; - return createMockApollo(requestHandlers); - }; - - const createComponent = (resolver, failedJobsData = mockFailedJobsData) => { - wrapper = mountExtended(FailedJobsTable, { - propsData: { - failedJobs: failedJobsData, - }, - apolloProvider: createMockApolloProvider(resolver), - }); - }; - - it('displays the failed jobs table', () => { - createComponent(); - - expect(findJobsTable().exists()).toBe(true); - }); - - it('displays failed job summary', () => { - createComponent(); - - expect(findSummary(0).text()).toBe('Html Summary'); - }); - - it('displays no job log when no trace', () => { - createComponent(); - - expect(findSummary(1).text()).toBe('No job log'); - }); - - it('displays failure reason', () => { - createComponent(); - - expect(findFirstFailureMessage().text()).toBe('Job failed'); - }); - - it('calls the retry failed job mutation and tracks the click', () => { - const trackingSpy = mockTracking(undefined, wrapper.element, jest.spyOn); - - createComponent(successRetryMutationHandler); - - findRetryButton().trigger('click'); - - expect(successRetryMutationHandler).toHaveBeenCalledWith({ - id: mockFailedJobsData[0].id, - }); - expect(trackingSpy).toHaveBeenCalledTimes(1); - expect(trackingSpy).toHaveBeenCalledWith(undefined, 'click_retry', { - label: TRACKING_CATEGORIES.failed, - }); - - unmockTracking(); - }); - - it('redirects to the new job after the mutation', async () => { - const { - data: { - jobRetry: { job }, - }, - } = successRetryMutationResponse; - - createComponent(successRetryMutationHandler); - - findRetryButton().trigger('click'); - - await waitForPromises(); - - expect(redirectTo).toHaveBeenCalledWith(job.detailedStatus.detailsPath); // eslint-disable-line import/no-deprecated - }); - - it('shows error message if the retry failed job mutation fails', async () => { - createComponent(failedRetryMutationHandler); - - findRetryButton().trigger('click'); - - await waitForPromises(); - - expect(createAlert).toHaveBeenCalledWith({ - message: 'There was a problem retrying the failed job.', - }); - }); - - it('hides the job log and retry button if a user does not have permission', () => { - createComponent([[]], mockFailedJobsDataNoPermission); - - expect(findJobLog().exists()).toBe(false); - expect(findRetryButton().exists()).toBe(false); - }); - - it('displays the job log and retry button if a user has permission', () => { - createComponent(); - - expect(findJobLog().exists()).toBe(true); - expect(findRetryButton().exists()).toBe(true); - }); - - it('job name links to the correct job', () => { - createComponent(); - - expect(findJobLink().attributes('href')).toBe(mockFailedJobsData[0].detailedStatus.detailsPath); - }); -}); diff --git a/spec/frontend/pipelines/components/jobs/jobs_app_spec.js b/spec/frontend/pipelines/components/jobs/jobs_app_spec.js deleted file mode 100644 index 39475788fe2..00000000000 --- a/spec/frontend/pipelines/components/jobs/jobs_app_spec.js +++ /dev/null @@ -1,127 +0,0 @@ -import { GlIntersectionObserver, GlSkeletonLoader, GlLoadingIcon } from '@gitlab/ui'; -import { shallowMount } from '@vue/test-utils'; -import Vue from 'vue'; -import VueApollo from 'vue-apollo'; -import createMockApollo from 'helpers/mock_apollo_helper'; -import waitForPromises from 'helpers/wait_for_promises'; -import { createAlert } from '~/alert'; -import JobsApp from '~/pipelines/components/jobs/jobs_app.vue'; -import JobsTable from '~/jobs/components/table/jobs_table.vue'; -import getPipelineJobsQuery from '~/pipelines/graphql/queries/get_pipeline_jobs.query.graphql'; -import { mockPipelineJobsQueryResponse } from '../../mock_data'; - -Vue.use(VueApollo); - -jest.mock('~/alert'); - -describe('Jobs app', () => { - let wrapper; - let resolverSpy; - - const findSkeletonLoader = () => wrapper.findComponent(GlSkeletonLoader); - const findLoadingSpinner = () => wrapper.findComponent(GlLoadingIcon); - const findJobsTable = () => wrapper.findComponent(JobsTable); - - const triggerInfiniteScroll = () => - wrapper.findComponent(GlIntersectionObserver).vm.$emit('appear'); - - const createMockApolloProvider = (resolver) => { - const requestHandlers = [[getPipelineJobsQuery, resolver]]; - - return createMockApollo(requestHandlers); - }; - - const createComponent = (resolver) => { - wrapper = shallowMount(JobsApp, { - provide: { - projectPath: 'root/ci-project', - pipelineIid: 1, - }, - apolloProvider: createMockApolloProvider(resolver), - }); - }; - - beforeEach(() => { - resolverSpy = jest.fn().mockResolvedValue(mockPipelineJobsQueryResponse); - }); - - describe('loading spinner', () => { - const setup = async () => { - createComponent(resolverSpy); - - await waitForPromises(); - - triggerInfiniteScroll(); - }; - - it('displays loading spinner when fetching more jobs', async () => { - await setup(); - - expect(findLoadingSpinner().exists()).toBe(true); - expect(findSkeletonLoader().exists()).toBe(false); - }); - - it('hides loading spinner after jobs have been fetched', async () => { - await setup(); - await waitForPromises(); - - expect(findLoadingSpinner().exists()).toBe(false); - expect(findSkeletonLoader().exists()).toBe(false); - }); - }); - - it('displays the skeleton loader', () => { - createComponent(resolverSpy); - - expect(findSkeletonLoader().exists()).toBe(true); - expect(findJobsTable().exists()).toBe(false); - }); - - it('displays the jobs table', async () => { - createComponent(resolverSpy); - - await waitForPromises(); - - expect(findJobsTable().exists()).toBe(true); - expect(findSkeletonLoader().exists()).toBe(false); - expect(createAlert).not.toHaveBeenCalled(); - }); - - it('handles job fetch error correctly', async () => { - resolverSpy = jest.fn().mockRejectedValue(new Error('GraphQL error')); - - createComponent(resolverSpy); - - await waitForPromises(); - - expect(createAlert).toHaveBeenCalledWith({ - message: 'An error occurred while fetching the pipelines jobs.', - }); - }); - - it('handles infinite scrolling by calling fetchMore', async () => { - createComponent(resolverSpy); - await waitForPromises(); - - triggerInfiniteScroll(); - await waitForPromises(); - - expect(resolverSpy).toHaveBeenCalledWith({ - after: 'eyJpZCI6Ijg0NyJ9', - fullPath: 'root/ci-project', - iid: 1, - }); - }); - - it('does not display skeleton loader again after fetchMore', async () => { - createComponent(resolverSpy); - - expect(findSkeletonLoader().exists()).toBe(true); - await waitForPromises(); - - triggerInfiniteScroll(); - await waitForPromises(); - - expect(findSkeletonLoader().exists()).toBe(false); - }); -}); |