Commit 3e01a16b authored by Jackie Fraser's avatar Jackie Fraser Committed by Enrique Alcantara

Migrate mr_widget_auto_merge_enabled_spec to Jest

parent 5587cf3f
import { shallowMount, createLocalVue } from '@vue/test-utils'; import { shallowMount } from '@vue/test-utils';
import { trimText } from 'spec/helpers/text_helper';
import MRWidgetAutoMergeEnabled from '~/vue_merge_request_widget/components/states/mr_widget_auto_merge_enabled.vue'; import MRWidgetAutoMergeEnabled from '~/vue_merge_request_widget/components/states/mr_widget_auto_merge_enabled.vue';
import { import {
MWPS_MERGE_STRATEGY, MWPS_MERGE_STRATEGY,
...@@ -8,7 +7,6 @@ import { ...@@ -8,7 +7,6 @@ import {
} from '~/vue_merge_request_widget/constants'; } from '~/vue_merge_request_widget/constants';
describe('MRWidgetAutoMergeEnabled', () => { describe('MRWidgetAutoMergeEnabled', () => {
const localVue = createLocalVue();
let wrapper; let wrapper;
let vm; let vm;
...@@ -31,12 +29,11 @@ describe('MRWidgetAutoMergeEnabled', () => { ...@@ -31,12 +29,11 @@ describe('MRWidgetAutoMergeEnabled', () => {
}; };
const factory = (mrUpdates = {}) => { const factory = (mrUpdates = {}) => {
wrapper = shallowMount(localVue.extend(MRWidgetAutoMergeEnabled), { wrapper = shallowMount(MRWidgetAutoMergeEnabled, {
propsData: { propsData: {
mr: { ...mr, ...mrUpdates }, mr: { ...mr, ...mrUpdates },
service, service,
}, },
localVue,
}); });
({ vm } = wrapper); ({ vm } = wrapper);
...@@ -44,6 +41,7 @@ describe('MRWidgetAutoMergeEnabled', () => { ...@@ -44,6 +41,7 @@ describe('MRWidgetAutoMergeEnabled', () => {
afterEach(() => { afterEach(() => {
wrapper.destroy(); wrapper.destroy();
wrapper = null;
}); });
describe('computed', () => { describe('computed', () => {
...@@ -125,7 +123,7 @@ describe('MRWidgetAutoMergeEnabled', () => { ...@@ -125,7 +123,7 @@ describe('MRWidgetAutoMergeEnabled', () => {
mergeTrainsCount: 0, mergeTrainsCount: 0,
}); });
const statusText = trimText(vm.$el.querySelector('.js-status-text-after-author').innerText); const statusText = wrapper.find('.js-status-text-after-author').text();
expect(statusText).toBe('to start a merge train when the pipeline succeeds'); expect(statusText).toBe('to start a merge train when the pipeline succeeds');
}); });
...@@ -136,7 +134,7 @@ describe('MRWidgetAutoMergeEnabled', () => { ...@@ -136,7 +134,7 @@ describe('MRWidgetAutoMergeEnabled', () => {
mergeTrainsCount: 1, mergeTrainsCount: 1,
}); });
const statusText = trimText(vm.$el.querySelector('.js-status-text-after-author').innerText); const statusText = wrapper.find('.js-status-text-after-author').text();
expect(statusText).toBe('to be added to the merge train when the pipeline succeeds'); expect(statusText).toBe('to be added to the merge train when the pipeline succeeds');
}); });
...@@ -144,7 +142,7 @@ describe('MRWidgetAutoMergeEnabled', () => { ...@@ -144,7 +142,7 @@ describe('MRWidgetAutoMergeEnabled', () => {
it('should render the cancel button as "Cancel automatic merge" if MTWPS is selected', () => { it('should render the cancel button as "Cancel automatic merge" if MTWPS is selected', () => {
factory({ autoMergeStrategy: MTWPS_MERGE_STRATEGY }); factory({ autoMergeStrategy: MTWPS_MERGE_STRATEGY });
const cancelButtonText = trimText(vm.$el.querySelector('.js-cancel-auto-merge').innerText); const cancelButtonText = wrapper.find('.js-cancel-auto-merge').text();
expect(cancelButtonText).toBe('Cancel automatic merge'); expect(cancelButtonText).toBe('Cancel automatic merge');
}); });
...@@ -153,7 +151,7 @@ describe('MRWidgetAutoMergeEnabled', () => { ...@@ -153,7 +151,7 @@ describe('MRWidgetAutoMergeEnabled', () => {
it('should render the cancel button as "Remove from merge train" if the pipeline has been added to the merge train', () => { it('should render the cancel button as "Remove from merge train" if the pipeline has been added to the merge train', () => {
factory({ autoMergeStrategy: MT_MERGE_STRATEGY }); factory({ autoMergeStrategy: MT_MERGE_STRATEGY });
const cancelButtonText = trimText(vm.$el.querySelector('.js-cancel-auto-merge').innerText); const cancelButtonText = wrapper.find('.js-cancel-auto-merge').text();
expect(cancelButtonText).toBe('Remove from merge train'); expect(cancelButtonText).toBe('Remove from merge train');
}); });
......
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