pipelines_table_spec.js 3.01 KB
Newer Older
1 2 3
import { mount } from '@vue/test-utils';
import { extendedWrapper } from 'helpers/vue_test_utils_helper';
import PipelinesTable from '~/pipelines/components/pipelines_list/pipelines_table.vue';
Jose Vargas's avatar
Jose Vargas committed
4
import { PipelineKeyOptions } from '~/pipelines/constants';
5 6 7 8 9 10 11 12 13 14 15 16 17 18

import { triggeredBy, triggered } from './mock_data';

jest.mock('~/pipelines/event_hub');

describe('Pipelines Table', () => {
  let pipeline;
  let wrapper;

  const jsonFixtureName = 'pipelines/pipelines.json';

  const defaultProps = {
    pipelines: [],
    viewType: 'root',
Jose Vargas's avatar
Jose Vargas committed
19
    pipelineKeyOption: PipelineKeyOptions[0],
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
  };

  const createMockPipeline = () => {
    const { pipelines } = getJSONFixture(jsonFixtureName);
    return pipelines.find((p) => p.user !== null && p.commit !== null);
  };

  const createComponent = (props = {}) => {
    wrapper = extendedWrapper(
      mount(PipelinesTable, {
        propsData: {
          ...defaultProps,
          ...props,
        },
      }),
    );
  };

  const findUpstream = () => wrapper.findByTestId('mini-graph-upstream');
  const findDownstream = () => wrapper.findByTestId('mini-graph-downstream');

  beforeEach(() => {
    pipeline = createMockPipeline();
  });

  afterEach(() => {
    wrapper.destroy();
  });

  describe('Pipelines Table', () => {
    describe('upstream linked pipelines', () => {
      beforeEach(() => {
        pipeline = createMockPipeline();
        pipeline.triggered_by = triggeredBy;

        createComponent({ pipelines: [pipeline] });
      });

      it('should render only a upstream pipeline', () => {
        expect(findUpstream().exists()).toBe(true);
        expect(findDownstream().exists()).toBe(false);
      });

      it('should pass an array of the correct data to the linked pipeline component', () => {
        const triggeredByProps = findUpstream().props('triggeredBy');

        expect(triggeredByProps).toEqual(expect.any(Array));
        expect(triggeredByProps).toHaveLength(1);
        expect(triggeredByProps[0]).toBe(triggeredBy);
      });
    });

    describe('downstream linked pipelines', () => {
      beforeEach(() => {
        pipeline = createMockPipeline();
        pipeline.triggered = triggered;

        createComponent({ pipelines: [pipeline] });
      });

80 81 82 83
      it('should pass the pipeline path prop for the counter badge', () => {
        expect(findDownstream().props('pipelinePath')).toBe(pipeline.path);
      });

84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105
      it('should render only a downstream pipeline', () => {
        expect(findDownstream().exists()).toBe(true);
        expect(findUpstream().exists()).toBe(false);
      });
    });

    describe('upstream and downstream linked pipelines', () => {
      beforeEach(() => {
        pipeline = createMockPipeline();
        pipeline.triggered = triggered;
        pipeline.triggered_by = triggeredBy;

        createComponent({ pipelines: [pipeline] });
      });

      it('should render both downstream and upstream pipelines', () => {
        expect(findDownstream().exists()).toBe(true);
        expect(findUpstream().exists()).toBe(true);
      });
    });
  });
});