diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2023-02-23 00:07:43 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2023-02-23 00:07:43 +0300 |
commit | f19ffffacda2d7f415f682f6e50e3cf06182e15e (patch) | |
tree | b8a78ba727ab2ef38808c028401842e7370948b0 /spec/frontend/jobs | |
parent | d0f16d56f3716d4a60027eb261f12080094f8db3 (diff) |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec/frontend/jobs')
-rw-r--r-- | spec/frontend/jobs/components/table/graphql/cache_config_spec.js | 19 | ||||
-rw-r--r-- | spec/frontend/jobs/components/table/job_table_app_spec.js | 45 | ||||
-rw-r--r-- | spec/frontend/jobs/mock_data.js | 2 |
3 files changed, 61 insertions, 5 deletions
diff --git a/spec/frontend/jobs/components/table/graphql/cache_config_spec.js b/spec/frontend/jobs/components/table/graphql/cache_config_spec.js index 88c97285b85..e3b1ca1cce3 100644 --- a/spec/frontend/jobs/components/table/graphql/cache_config_spec.js +++ b/spec/frontend/jobs/components/table/graphql/cache_config_spec.js @@ -84,4 +84,23 @@ describe('jobs/components/table/graphql/cache_config', () => { expect(res.nodes).toHaveLength(CIJobConnectionIncomingCacheRunningStatus.nodes.length); }); }); + + describe('when incoming data has no nodes', () => { + it('should return existing cache', () => { + const res = cacheConfig.typePolicies.CiJobConnection.merge( + CIJobConnectionExistingCache, + { __typename: 'CiJobConnection', count: 500 }, + { + args: { statuses: 'SUCCESS' }, + }, + ); + + const expectedResponse = { + ...CIJobConnectionExistingCache, + statuses: 'SUCCESS', + }; + + expect(res).toEqual(expectedResponse); + }); + }); }); diff --git a/spec/frontend/jobs/components/table/job_table_app_spec.js b/spec/frontend/jobs/components/table/job_table_app_spec.js index 109cef6f817..b14a3bae54f 100644 --- a/spec/frontend/jobs/components/table/job_table_app_spec.js +++ b/spec/frontend/jobs/components/table/job_table_app_spec.js @@ -14,6 +14,7 @@ import waitForPromises from 'helpers/wait_for_promises'; import { TEST_HOST } from 'spec/test_constants'; import { createAlert } from '~/flash'; import getJobsQuery from '~/jobs/components/table/graphql/queries/get_jobs.query.graphql'; +import getJobsCountQuery from '~/jobs/components/table/graphql/queries/get_jobs_count.query.graphql'; import JobsTable from '~/jobs/components/table/jobs_table.vue'; import JobsTableApp from '~/jobs/components/table/jobs_table_app.vue'; import JobsTableTabs from '~/jobs/components/table/jobs_table_tabs.vue'; @@ -23,6 +24,7 @@ import { mockJobsResponsePaginated, mockJobsResponseEmpty, mockFailedSearchToken, + mockJobsCountResponse, } from '../../mock_data'; const projectPath = 'gitlab-org/gitlab'; @@ -37,6 +39,8 @@ describe('Job table app', () => { const failedHandler = jest.fn().mockRejectedValue(new Error('GraphQL error')); const emptyHandler = jest.fn().mockResolvedValue(mockJobsResponseEmpty); + const countSuccessHandler = jest.fn().mockResolvedValue(mockJobsCountResponse); + const findSkeletonLoader = () => wrapper.findComponent(GlSkeletonLoader); const findLoadingSpinner = () => wrapper.findComponent(GlLoadingIcon); const findTable = () => wrapper.findComponent(JobsTable); @@ -48,14 +52,18 @@ describe('Job table app', () => { const triggerInfiniteScroll = () => wrapper.findComponent(GlIntersectionObserver).vm.$emit('appear'); - const createMockApolloProvider = (handler) => { - const requestHandlers = [[getJobsQuery, handler]]; + const createMockApolloProvider = (handler, countHandler) => { + const requestHandlers = [ + [getJobsQuery, handler], + [getJobsCountQuery, countHandler], + ]; return createMockApollo(requestHandlers); }; const createComponent = ({ handler = successHandler, + countHandler = countSuccessHandler, mountFn = shallowMount, data = {}, } = {}) => { @@ -68,7 +76,7 @@ describe('Job table app', () => { provide: { fullPath: projectPath, }, - apolloProvider: createMockApolloProvider(handler), + apolloProvider: createMockApolloProvider(handler, countHandler), }); }; @@ -148,12 +156,39 @@ describe('Job table app', () => { }); describe('error state', () => { - it('should show an alert if there is an error fetching the data', async () => { + it('should show an alert if there is an error fetching the jobs data', async () => { createComponent({ handler: failedHandler }); await waitForPromises(); - expect(findAlert().exists()).toBe(true); + expect(findAlert().text()).toBe('There was an error fetching the jobs for your project.'); + expect(findTable().exists()).toBe(false); + }); + + it('should show an alert if there is an error fetching the jobs count data', async () => { + createComponent({ handler: successHandler, countHandler: failedHandler }); + + await waitForPromises(); + + expect(findAlert().text()).toBe( + 'There was an error fetching the number of jobs for your project.', + ); + }); + + it('jobs table should still load if count query fails', async () => { + createComponent({ handler: successHandler, countHandler: failedHandler }); + + await waitForPromises(); + + expect(findTable().exists()).toBe(true); + }); + + it('jobs count should be zero if count query fails', async () => { + createComponent({ handler: successHandler, countHandler: failedHandler }); + + await waitForPromises(); + + expect(findTabs().props('allJobsCount')).toBe(0); }); }); diff --git a/spec/frontend/jobs/mock_data.js b/spec/frontend/jobs/mock_data.js index 9abd610c26d..483b4ca711f 100644 --- a/spec/frontend/jobs/mock_data.js +++ b/spec/frontend/jobs/mock_data.js @@ -1,3 +1,4 @@ +import mockJobsCount from 'test_fixtures/graphql/jobs/get_jobs_count.query.graphql.json'; import mockJobsEmpty from 'test_fixtures/graphql/jobs/get_jobs.query.graphql.empty.json'; import mockJobsPaginated from 'test_fixtures/graphql/jobs/get_jobs.query.graphql.paginated.json'; import mockJobs from 'test_fixtures/graphql/jobs/get_jobs.query.graphql.json'; @@ -13,6 +14,7 @@ export const mockJobsResponsePaginated = mockJobsPaginated; export const mockJobsResponseEmpty = mockJobsEmpty; export const mockJobsNodes = mockJobs.data.project.jobs.nodes; export const mockJobsNodesAsGuest = mockJobsAsGuest.data.project.jobs.nodes; +export const mockJobsCountResponse = mockJobsCount; export const stages = [ { |