Commit 6be3dc25 authored by Miguel Rincon's avatar Miguel Rincon

Update EE MR widget tests to match guidelines

parent a2973bc3
import { mount } from '@vue/test-utils'; import { shallowMount } from '@vue/test-utils';
import LinkedPipelinesMiniList from 'ee/vue_shared/components/linked_pipelines_mini_list.vue'; import LinkedPipelinesMiniList from 'ee/vue_shared/components/linked_pipelines_mini_list.vue';
import mockData from 'ee_jest/vue_mr_widget/mock_data'; import mockData from 'ee_jest/vue_mr_widget/mock_data';
import { trimText } from 'helpers/text_helper'; import MrWidgetPipeline from '~/vue_merge_request_widget/components/mr_widget_pipeline.vue';
import pipelineComponent from '~/vue_merge_request_widget/components/mr_widget_pipeline.vue';
import mockLinkedPipelines from '../vue_shared/components/linked_pipelines_mock_data'; import mockLinkedPipelines from '../vue_shared/components/linked_pipelines_mock_data';
describe('MRWidgetPipeline', () => { describe('MRWidgetPipeline', () => {
...@@ -11,10 +10,10 @@ describe('MRWidgetPipeline', () => { ...@@ -11,10 +10,10 @@ describe('MRWidgetPipeline', () => {
const findPipelineInfoContainer = () => wrapper.find('[data-testid="pipeline-info-container"'); const findPipelineInfoContainer = () => wrapper.find('[data-testid="pipeline-info-container"');
const findPipelinesMiniList = () => wrapper.find(LinkedPipelinesMiniList); const findPipelinesMiniList = () => wrapper.find(LinkedPipelinesMiniList);
function createComponent(pipeline) { const createWrapper = (props) => {
wrapper = mount(pipelineComponent, { wrapper = shallowMount(MrWidgetPipeline, {
propsData: { propsData: {
pipeline, pipeline: mockData,
pipelineCoverageDelta: undefined, pipelineCoverageDelta: undefined,
hasCi: true, hasCi: true,
ciStatus: 'success', ciStatus: 'success',
...@@ -22,9 +21,10 @@ describe('MRWidgetPipeline', () => { ...@@ -22,9 +21,10 @@ describe('MRWidgetPipeline', () => {
sourceBranch: undefined, sourceBranch: undefined,
mrTroubleshootingDocsPath: 'help', mrTroubleshootingDocsPath: 'help',
ciTroubleshootingDocsPath: 'help2', ciTroubleshootingDocsPath: 'help2',
...props,
}, },
}); });
} };
afterEach(() => { afterEach(() => {
wrapper.destroy(); wrapper.destroy();
...@@ -45,12 +45,11 @@ describe('MRWidgetPipeline', () => { ...@@ -45,12 +45,11 @@ describe('MRWidgetPipeline', () => {
pipeline.details.name = 'Merge train pipeline'; pipeline.details.name = 'Merge train pipeline';
pipeline.merge_request_event_type = 'merge_train'; pipeline.merge_request_event_type = 'merge_train';
createComponent(pipeline); createWrapper({ pipeline });
const expected = `Merge train pipeline #${pipeline.id} ${pipeline.details.status.label} for ${pipeline.commit.short_id}`; const expected = `Merge train pipeline #${pipeline.id} ${pipeline.details.status.label} for ${pipeline.commit.short_id}`;
const actual = trimText(findPipelineInfoContainer().text());
expect(actual).toBe(expected); expect(findPipelineInfoContainer().text()).toMatchInterpolatedText(expected);
}); });
}); });
...@@ -59,12 +58,11 @@ describe('MRWidgetPipeline', () => { ...@@ -59,12 +58,11 @@ describe('MRWidgetPipeline', () => {
pipeline.details.name = 'Merged result pipeline'; pipeline.details.name = 'Merged result pipeline';
pipeline.merge_request_event_type = 'merged_result'; pipeline.merge_request_event_type = 'merged_result';
createComponent(pipeline); createWrapper({ pipeline });
const expected = `Merged result pipeline #${pipeline.id} ${pipeline.details.status.label} for ${pipeline.commit.short_id}`; const expected = `Merged result pipeline #${pipeline.id} ${pipeline.details.status.label} for ${pipeline.commit.short_id}`;
const actual = trimText(findPipelineInfoContainer().text());
expect(actual).toBe(expected); expect(findPipelineInfoContainer().text()).toMatchInterpolatedText(expected);
}); });
}); });
}); });
...@@ -74,7 +72,7 @@ describe('MRWidgetPipeline', () => { ...@@ -74,7 +72,7 @@ describe('MRWidgetPipeline', () => {
beforeEach(() => { beforeEach(() => {
const pipeline = { ...mockData.pipeline, triggered_by: mockLinkedPipelines.triggered_by }; const pipeline = { ...mockData.pipeline, triggered_by: mockLinkedPipelines.triggered_by };
createComponent(pipeline); createWrapper({ pipeline });
}); });
it('should render the linked pipelines mini list', () => { it('should render the linked pipelines mini list', () => {
...@@ -98,7 +96,7 @@ describe('MRWidgetPipeline', () => { ...@@ -98,7 +96,7 @@ describe('MRWidgetPipeline', () => {
beforeEach(() => { beforeEach(() => {
const pipeline = { ...mockData.pipeline, triggered: mockLinkedPipelines.triggered }; const pipeline = { ...mockData.pipeline, triggered: mockLinkedPipelines.triggered };
createComponent(pipeline); createWrapper({ pipeline });
}); });
it('should render the linked pipelines mini list', () => { it('should render the linked pipelines mini list', () => {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment