2021-06-08 01:23:25 +05:30
|
|
|
import '~/commons';
|
2021-12-11 22:18:48 +05:30
|
|
|
import { GlTableLite } from '@gitlab/ui';
|
2020-05-24 23:13:21 +05:30
|
|
|
import { mount } from '@vue/test-utils';
|
2021-11-18 22:05:49 +05:30
|
|
|
import fixture from 'test_fixtures/pipelines/pipelines.json';
|
2021-04-17 20:07:23 +05:30
|
|
|
import { extendedWrapper } from 'helpers/vue_test_utils_helper';
|
|
|
|
import PipelineMiniGraph from '~/pipelines/components/pipelines_list/pipeline_mini_graph.vue';
|
|
|
|
import PipelineOperations from '~/pipelines/components/pipelines_list/pipeline_operations.vue';
|
|
|
|
import PipelineTriggerer from '~/pipelines/components/pipelines_list/pipeline_triggerer.vue';
|
|
|
|
import PipelineUrl from '~/pipelines/components/pipelines_list/pipeline_url.vue';
|
2020-07-28 23:09:34 +05:30
|
|
|
import PipelinesTable from '~/pipelines/components/pipelines_list/pipelines_table.vue';
|
2021-04-17 20:07:23 +05:30
|
|
|
import PipelinesTimeago from '~/pipelines/components/pipelines_list/time_ago.vue';
|
2022-04-04 11:22:00 +05:30
|
|
|
import {
|
|
|
|
PipelineKeyOptions,
|
|
|
|
BUTTON_TOOLTIP_RETRY,
|
|
|
|
BUTTON_TOOLTIP_CANCEL,
|
|
|
|
} from '~/pipelines/constants';
|
2021-04-17 20:07:23 +05:30
|
|
|
|
|
|
|
import eventHub from '~/pipelines/event_hub';
|
2021-06-08 01:23:25 +05:30
|
|
|
import CiBadge from '~/vue_shared/components/ci_badge_link.vue';
|
2021-04-17 20:07:23 +05:30
|
|
|
import CommitComponent from '~/vue_shared/components/commit.vue';
|
|
|
|
|
|
|
|
jest.mock('~/pipelines/event_hub');
|
2020-05-24 23:13:21 +05:30
|
|
|
|
|
|
|
describe('Pipelines Table', () => {
|
|
|
|
let pipeline;
|
|
|
|
let wrapper;
|
|
|
|
|
|
|
|
const defaultProps = {
|
|
|
|
pipelines: [],
|
|
|
|
viewType: 'root',
|
2021-10-27 15:23:28 +05:30
|
|
|
pipelineKeyOption: PipelineKeyOptions[0],
|
2020-05-24 23:13:21 +05:30
|
|
|
};
|
|
|
|
|
2021-04-17 20:07:23 +05:30
|
|
|
const createMockPipeline = () => {
|
2021-11-18 22:05:49 +05:30
|
|
|
// Clone fixture as it could be modified by tests
|
|
|
|
const { pipelines } = JSON.parse(JSON.stringify(fixture));
|
2021-04-17 20:07:23 +05:30
|
|
|
return pipelines.find((p) => p.user !== null && p.commit !== null);
|
2020-05-24 23:13:21 +05:30
|
|
|
};
|
|
|
|
|
2022-04-04 11:22:00 +05:30
|
|
|
const createComponent = (props = {}, rearrangePipelinesTable = false) => {
|
2021-04-17 20:07:23 +05:30
|
|
|
wrapper = extendedWrapper(
|
|
|
|
mount(PipelinesTable, {
|
|
|
|
propsData: {
|
|
|
|
...defaultProps,
|
|
|
|
...props,
|
|
|
|
},
|
2022-04-04 11:22:00 +05:30
|
|
|
provide: {
|
|
|
|
glFeatures: {
|
|
|
|
rearrangePipelinesTable,
|
|
|
|
},
|
|
|
|
},
|
2021-04-17 20:07:23 +05:30
|
|
|
}),
|
|
|
|
);
|
|
|
|
};
|
2020-05-24 23:13:21 +05:30
|
|
|
|
2021-12-11 22:18:48 +05:30
|
|
|
const findGlTableLite = () => wrapper.findComponent(GlTableLite);
|
2021-06-08 01:23:25 +05:30
|
|
|
const findStatusBadge = () => wrapper.findComponent(CiBadge);
|
2021-04-17 20:07:23 +05:30
|
|
|
const findPipelineInfo = () => wrapper.findComponent(PipelineUrl);
|
|
|
|
const findTriggerer = () => wrapper.findComponent(PipelineTriggerer);
|
|
|
|
const findCommit = () => wrapper.findComponent(CommitComponent);
|
|
|
|
const findPipelineMiniGraph = () => wrapper.findComponent(PipelineMiniGraph);
|
|
|
|
const findTimeAgo = () => wrapper.findComponent(PipelinesTimeago);
|
|
|
|
const findActions = () => wrapper.findComponent(PipelineOperations);
|
|
|
|
|
2021-04-29 21:17:54 +05:30
|
|
|
const findTableRows = () => wrapper.findAllByTestId('pipeline-table-row');
|
2021-04-17 20:07:23 +05:30
|
|
|
const findStatusTh = () => wrapper.findByTestId('status-th');
|
|
|
|
const findPipelineTh = () => wrapper.findByTestId('pipeline-th');
|
|
|
|
const findTriggererTh = () => wrapper.findByTestId('triggerer-th');
|
|
|
|
const findCommitTh = () => wrapper.findByTestId('commit-th');
|
|
|
|
const findStagesTh = () => wrapper.findByTestId('stages-th');
|
|
|
|
const findTimeAgoTh = () => wrapper.findByTestId('timeago-th');
|
|
|
|
const findActionsTh = () => wrapper.findByTestId('actions-th');
|
2022-04-04 11:22:00 +05:30
|
|
|
const findRetryBtn = () => wrapper.findByTestId('pipelines-retry-button');
|
|
|
|
const findCancelBtn = () => wrapper.findByTestId('pipelines-cancel-button');
|
2020-05-24 23:13:21 +05:30
|
|
|
|
2021-04-17 20:07:23 +05:30
|
|
|
beforeEach(() => {
|
|
|
|
pipeline = createMockPipeline();
|
2020-05-24 23:13:21 +05:30
|
|
|
});
|
|
|
|
|
|
|
|
afterEach(() => {
|
|
|
|
wrapper.destroy();
|
|
|
|
wrapper = null;
|
|
|
|
});
|
|
|
|
|
2022-04-04 11:22:00 +05:30
|
|
|
describe('Pipelines Table with rearrangePipelinesTable feature flag turned off', () => {
|
2021-04-17 20:07:23 +05:30
|
|
|
beforeEach(() => {
|
2021-04-29 21:17:54 +05:30
|
|
|
createComponent({ pipelines: [pipeline], viewType: 'root' });
|
2021-04-17 20:07:23 +05:30
|
|
|
});
|
|
|
|
|
2021-04-29 21:17:54 +05:30
|
|
|
it('displays table', () => {
|
2021-12-11 22:18:48 +05:30
|
|
|
expect(findGlTableLite().exists()).toBe(true);
|
2021-04-17 20:07:23 +05:30
|
|
|
});
|
|
|
|
|
|
|
|
it('should render table head with correct columns', () => {
|
|
|
|
expect(findStatusTh().text()).toBe('Status');
|
2021-10-27 15:23:28 +05:30
|
|
|
expect(findPipelineTh().text()).toBe('Pipeline ID');
|
2021-04-17 20:07:23 +05:30
|
|
|
expect(findTriggererTh().text()).toBe('Triggerer');
|
|
|
|
expect(findCommitTh().text()).toBe('Commit');
|
|
|
|
expect(findStagesTh().text()).toBe('Stages');
|
|
|
|
expect(findTimeAgoTh().text()).toBe('Duration');
|
|
|
|
expect(findActionsTh().text()).toBe('Actions');
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should display a table row', () => {
|
|
|
|
expect(findTableRows()).toHaveLength(1);
|
2020-05-24 23:13:21 +05:30
|
|
|
});
|
|
|
|
|
2021-04-17 20:07:23 +05:30
|
|
|
describe('status cell', () => {
|
|
|
|
it('should render a status badge', () => {
|
|
|
|
expect(findStatusBadge().exists()).toBe(true);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should render status badge with correct path', () => {
|
|
|
|
expect(findStatusBadge().attributes('href')).toBe(pipeline.path);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('pipeline cell', () => {
|
|
|
|
it('should render pipeline information', () => {
|
|
|
|
expect(findPipelineInfo().exists()).toBe(true);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should display the pipeline id', () => {
|
|
|
|
expect(findPipelineInfo().text()).toContain(`#${pipeline.id}`);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('triggerer cell', () => {
|
|
|
|
it('should render the pipeline triggerer', () => {
|
|
|
|
expect(findTriggerer().exists()).toBe(true);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('commit cell', () => {
|
|
|
|
it('should render commit information', () => {
|
|
|
|
expect(findCommit().exists()).toBe(true);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should display and link to commit', () => {
|
|
|
|
expect(findCommit().text()).toContain(pipeline.commit.short_id);
|
|
|
|
expect(findCommit().props('commitUrl')).toBe(pipeline.commit.commit_path);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should display the commit author', () => {
|
|
|
|
expect(findCommit().props('author')).toEqual(pipeline.commit.author);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('stages cell', () => {
|
|
|
|
it('should render a pipeline mini graph', () => {
|
|
|
|
expect(findPipelineMiniGraph().exists()).toBe(true);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should render the right number of stages', () => {
|
|
|
|
const stagesLength = pipeline.details.stages.length;
|
|
|
|
expect(
|
|
|
|
findPipelineMiniGraph().findAll('[data-testid="mini-pipeline-graph-dropdown"]'),
|
|
|
|
).toHaveLength(stagesLength);
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('when pipeline does not have stages', () => {
|
|
|
|
beforeEach(() => {
|
|
|
|
pipeline = createMockPipeline();
|
|
|
|
pipeline.details.stages = null;
|
|
|
|
|
|
|
|
createComponent({ pipelines: [pipeline] }, true);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('stages are not rendered', () => {
|
|
|
|
expect(findPipelineMiniGraph().exists()).toBe(false);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should not update dropdown', () => {
|
|
|
|
expect(findPipelineMiniGraph().props('updateDropdown')).toBe(false);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('when update graph dropdown is set, should update graph dropdown', () => {
|
|
|
|
createComponent({ pipelines: [pipeline], updateGraphDropdown: true }, true);
|
|
|
|
|
|
|
|
expect(findPipelineMiniGraph().props('updateDropdown')).toBe(true);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('when action request is complete, should refresh table', () => {
|
|
|
|
findPipelineMiniGraph().vm.$emit('pipelineActionRequestComplete');
|
|
|
|
|
|
|
|
expect(eventHub.$emit).toHaveBeenCalledWith('refreshPipelinesTable');
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('duration cell', () => {
|
|
|
|
it('should render duration information', () => {
|
|
|
|
expect(findTimeAgo().exists()).toBe(true);
|
|
|
|
});
|
|
|
|
});
|
2020-05-24 23:13:21 +05:30
|
|
|
|
2021-04-17 20:07:23 +05:30
|
|
|
describe('operations cell', () => {
|
|
|
|
it('should render pipeline operations', () => {
|
|
|
|
expect(findActions().exists()).toBe(true);
|
|
|
|
});
|
2022-04-04 11:22:00 +05:30
|
|
|
|
|
|
|
it('should render retry action tooltip', () => {
|
|
|
|
expect(findRetryBtn().attributes('title')).toBe(BUTTON_TOOLTIP_RETRY);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should render cancel action tooltip', () => {
|
|
|
|
expect(findCancelBtn().attributes('title')).toBe(BUTTON_TOOLTIP_CANCEL);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('Pipelines Table with rearrangePipelinesTable feature flag turned on', () => {
|
|
|
|
beforeEach(() => {
|
|
|
|
createComponent({ pipelines: [pipeline], viewType: 'root' }, true);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should render table head with correct columns', () => {
|
|
|
|
expect(findStatusTh().text()).toBe('Status');
|
|
|
|
expect(findPipelineTh().text()).toBe('Pipeline');
|
|
|
|
expect(findStagesTh().text()).toBe('Stages');
|
|
|
|
expect(findActionsTh().text()).toBe('Actions');
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('triggerer cell', () => {
|
|
|
|
it('should render the pipeline triggerer', () => {
|
|
|
|
expect(findTriggerer().exists()).toBe(true);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('commit cell', () => {
|
|
|
|
it('should not render commit information', () => {
|
|
|
|
expect(findCommit().exists()).toBe(false);
|
|
|
|
});
|
2020-05-24 23:13:21 +05:30
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|