2023-03-04 22:38:38 +05:30
|
|
|
import Vue from 'vue';
|
|
|
|
import VueApollo from 'vue-apollo';
|
|
|
|
import { shallowMountExtended } from 'helpers/vue_test_utils_helper';
|
|
|
|
import createMockApollo from 'helpers/mock_apollo_helper';
|
|
|
|
import waitForPromises from 'helpers/wait_for_promises';
|
|
|
|
import SidebarHeader from '~/jobs/components/job/sidebar/sidebar_header.vue';
|
2022-10-11 01:57:18 +05:30
|
|
|
import JobRetryButton from '~/jobs/components/job/sidebar/job_sidebar_retry_button.vue';
|
2023-03-04 22:38:38 +05:30
|
|
|
import getJobQuery from '~/jobs/components/job/graphql/queries/get_job.query.graphql';
|
|
|
|
import { mockFullPath, mockId, mockJobResponse } from './mock_data';
|
2022-10-11 01:57:18 +05:30
|
|
|
|
2023-03-04 22:38:38 +05:30
|
|
|
Vue.use(VueApollo);
|
|
|
|
|
|
|
|
const defaultProvide = {
|
|
|
|
projectPath: mockFullPath,
|
|
|
|
};
|
|
|
|
|
|
|
|
describe('Sidebar Header', () => {
|
2022-10-11 01:57:18 +05:30
|
|
|
let wrapper;
|
|
|
|
|
2023-03-04 22:38:38 +05:30
|
|
|
const createComponent = ({ options = {}, props = {}, restJob = {} } = {}) => {
|
|
|
|
wrapper = shallowMountExtended(SidebarHeader, {
|
|
|
|
propsData: {
|
|
|
|
...props,
|
|
|
|
jobId: mockId,
|
|
|
|
restJob,
|
|
|
|
},
|
|
|
|
provide: {
|
|
|
|
...defaultProvide,
|
|
|
|
},
|
|
|
|
...options,
|
|
|
|
});
|
2022-10-11 01:57:18 +05:30
|
|
|
};
|
|
|
|
|
2023-06-20 00:43:36 +05:30
|
|
|
const createComponentWithApollo = ({ props = {}, restJob = {} } = {}) => {
|
2023-03-04 22:38:38 +05:30
|
|
|
const getJobQueryResponse = jest.fn().mockResolvedValue(mockJobResponse);
|
2022-10-11 01:57:18 +05:30
|
|
|
|
2023-03-04 22:38:38 +05:30
|
|
|
const requestHandlers = [[getJobQuery, getJobQueryResponse]];
|
2022-10-11 01:57:18 +05:30
|
|
|
|
2023-03-04 22:38:38 +05:30
|
|
|
const apolloProvider = createMockApollo(requestHandlers);
|
2022-10-11 01:57:18 +05:30
|
|
|
|
2023-03-04 22:38:38 +05:30
|
|
|
const options = {
|
|
|
|
apolloProvider,
|
|
|
|
};
|
2022-10-11 01:57:18 +05:30
|
|
|
|
2023-03-04 22:38:38 +05:30
|
|
|
createComponent({
|
|
|
|
props,
|
|
|
|
restJob,
|
|
|
|
options,
|
2022-10-11 01:57:18 +05:30
|
|
|
});
|
|
|
|
|
2023-03-04 22:38:38 +05:30
|
|
|
return waitForPromises();
|
|
|
|
};
|
2022-10-11 01:57:18 +05:30
|
|
|
|
2023-03-04 22:38:38 +05:30
|
|
|
const findCancelButton = () => wrapper.findByTestId('cancel-button');
|
|
|
|
const findEraseButton = () => wrapper.findByTestId('job-log-erase-link');
|
|
|
|
const findJobName = () => wrapper.findByTestId('job-name');
|
|
|
|
const findRetryButton = () => wrapper.findComponent(JobRetryButton);
|
2022-10-11 01:57:18 +05:30
|
|
|
|
2023-03-04 22:38:38 +05:30
|
|
|
describe('when rendering contents', () => {
|
|
|
|
it('renders the correct job name', async () => {
|
|
|
|
await createComponentWithApollo();
|
|
|
|
expect(findJobName().text()).toBe(mockJobResponse.data.project.job.name);
|
2022-10-11 01:57:18 +05:30
|
|
|
});
|
|
|
|
|
2023-03-04 22:38:38 +05:30
|
|
|
it('does not render buttons with no paths', async () => {
|
|
|
|
await createComponentWithApollo();
|
|
|
|
expect(findCancelButton().exists()).toBe(false);
|
|
|
|
expect(findEraseButton().exists()).toBe(false);
|
|
|
|
expect(findRetryButton().exists()).toBe(false);
|
2022-10-11 01:57:18 +05:30
|
|
|
});
|
|
|
|
|
2023-03-04 22:38:38 +05:30
|
|
|
it('renders a retry button with a path', async () => {
|
|
|
|
await createComponentWithApollo({ restJob: { retry_path: 'retry/path' } });
|
|
|
|
expect(findRetryButton().exists()).toBe(true);
|
2022-10-11 01:57:18 +05:30
|
|
|
});
|
|
|
|
|
2023-03-04 22:38:38 +05:30
|
|
|
it('renders a cancel button with a path', async () => {
|
|
|
|
await createComponentWithApollo({ restJob: { cancel_path: 'cancel/path' } });
|
|
|
|
expect(findCancelButton().exists()).toBe(true);
|
2022-10-11 01:57:18 +05:30
|
|
|
});
|
|
|
|
|
2023-03-04 22:38:38 +05:30
|
|
|
it('renders an erase button with a path', async () => {
|
|
|
|
await createComponentWithApollo({ restJob: { erase_path: 'erase/path' } });
|
|
|
|
expect(findEraseButton().exists()).toBe(true);
|
2022-10-11 01:57:18 +05:30
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|