Welcome to mirror list, hosted at ThFree Co, Russian Federation.

sidebar_header_spec.js « job « components « jobs « frontend « spec - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: cf182330578ddeec5896f888c5acf058db0d7b05 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
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';
import JobRetryButton from '~/jobs/components/job/sidebar/job_sidebar_retry_button.vue';
import getJobQuery from '~/jobs/components/job/graphql/queries/get_job.query.graphql';
import { mockFullPath, mockId, mockJobResponse } from './mock_data';

Vue.use(VueApollo);

const defaultProvide = {
  projectPath: mockFullPath,
};

describe('Sidebar Header', () => {
  let wrapper;

  const createComponent = ({ options = {}, props = {}, restJob = {} } = {}) => {
    wrapper = shallowMountExtended(SidebarHeader, {
      propsData: {
        ...props,
        jobId: mockId,
        restJob,
      },
      provide: {
        ...defaultProvide,
      },
      ...options,
    });
  };

  const createComponentWithApollo = ({ props = {}, restJob = {} } = {}) => {
    const getJobQueryResponse = jest.fn().mockResolvedValue(mockJobResponse);

    const requestHandlers = [[getJobQuery, getJobQueryResponse]];

    const apolloProvider = createMockApollo(requestHandlers);

    const options = {
      apolloProvider,
    };

    createComponent({
      props,
      restJob,
      options,
    });

    return waitForPromises();
  };

  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);

  describe('when rendering contents', () => {
    it('renders the correct job name', async () => {
      await createComponentWithApollo();
      expect(findJobName().text()).toBe(mockJobResponse.data.project.job.name);
    });

    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);
    });

    it('renders a retry button with a path', async () => {
      await createComponentWithApollo({ restJob: { retry_path: 'retry/path' } });
      expect(findRetryButton().exists()).toBe(true);
    });

    it('renders a cancel button with a path', async () => {
      await createComponentWithApollo({ restJob: { cancel_path: 'cancel/path' } });
      expect(findCancelButton().exists()).toBe(true);
    });

    it('renders an erase button with a path', async () => {
      await createComponentWithApollo({ restJob: { erase_path: 'erase/path' } });
      expect(findEraseButton().exists()).toBe(true);
    });
  });
});