debian-mirror-gitlab/spec/frontend/pipelines/components/jobs/jobs_app_spec.js

129 lines
3.6 KiB
JavaScript
Raw Normal View History

2022-05-07 20:08:51 +05:30
import { GlIntersectionObserver, GlSkeletonLoader, GlLoadingIcon } from '@gitlab/ui';
2022-04-04 11:22:00 +05:30
import { shallowMount } from '@vue/test-utils';
import Vue from 'vue';
2022-01-26 12:08:38 +05:30
import VueApollo from 'vue-apollo';
import createMockApollo from 'helpers/mock_apollo_helper';
import waitForPromises from 'helpers/wait_for_promises';
import createFlash from '~/flash';
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';
2022-04-04 11:22:00 +05:30
Vue.use(VueApollo);
2022-01-26 12:08:38 +05:30
jest.mock('~/flash');
describe('Jobs app', () => {
let wrapper;
let resolverSpy;
const findSkeletonLoader = () => wrapper.findComponent(GlSkeletonLoader);
2022-05-07 20:08:51 +05:30
const findLoadingSpinner = () => wrapper.findComponent(GlLoadingIcon);
2022-01-26 12:08:38 +05:30
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: {
fullPath: 'root/ci-project',
pipelineIid: 1,
},
apolloProvider: createMockApolloProvider(resolver),
});
};
beforeEach(() => {
resolverSpy = jest.fn().mockResolvedValue(mockPipelineJobsQueryResponse);
});
afterEach(() => {
wrapper.destroy();
});
2022-05-07 20:08:51 +05:30
describe('loading spinner', () => {
beforeEach(async () => {
createComponent(resolverSpy);
await waitForPromises();
triggerInfiniteScroll();
});
it('displays loading spinner when fetching more jobs', () => {
expect(findLoadingSpinner().exists()).toBe(true);
expect(findSkeletonLoader().exists()).toBe(false);
});
it('hides loading spinner after jobs have been fetched', async () => {
await waitForPromises();
expect(findLoadingSpinner().exists()).toBe(false);
expect(findSkeletonLoader().exists()).toBe(false);
});
});
it('displays the skeleton loader', () => {
2022-01-26 12:08:38 +05:30
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(createFlash).not.toHaveBeenCalled();
});
it('handles job fetch error correctly', async () => {
resolverSpy = jest.fn().mockRejectedValue(new Error('GraphQL error'));
createComponent(resolverSpy);
await waitForPromises();
expect(createFlash).toHaveBeenCalledWith({
2022-04-04 11:22:00 +05:30
message: 'An error occurred while fetching the pipelines jobs.',
2022-01-26 12:08:38 +05:30
});
});
it('handles infinite scrolling by calling fetchMore', async () => {
createComponent(resolverSpy);
await waitForPromises();
triggerInfiniteScroll();
2022-04-04 11:22:00 +05:30
await waitForPromises();
2022-01-26 12:08:38 +05:30
expect(resolverSpy).toHaveBeenCalledWith({
after: 'eyJpZCI6Ijg0NyJ9',
fullPath: 'root/ci-project',
iid: 1,
});
});
2022-05-07 20:08:51 +05:30
it('does not display skeleton loader again after fetchMore', async () => {
2022-01-26 12:08:38 +05:30
createComponent(resolverSpy);
expect(findSkeletonLoader().exists()).toBe(true);
await waitForPromises();
triggerInfiniteScroll();
2022-04-04 11:22:00 +05:30
await waitForPromises();
2022-01-26 12:08:38 +05:30
expect(findSkeletonLoader().exists()).toBe(false);
});
});