Commit 6bbba701 authored by Illya Klymov's avatar Illya Klymov

Refactored Karma spec to Jest for mr_widget_auto_merge_failed

parent 27c222d1
---
title: Refactored Karma spec to Jest for mr_widget_auto_merge_failed
merge_request: 32282
author: Illya Klymov
type: other
import Vue from 'vue'; import { shallowMount } from '@vue/test-utils';
import autoMergeFailedComponent from '~/vue_merge_request_widget/components/states/mr_widget_auto_merge_failed.vue'; import { GlLoadingIcon } from '@gitlab/ui';
import AutoMergeFailedComponent from '~/vue_merge_request_widget/components/states/mr_widget_auto_merge_failed.vue';
import eventHub from '~/vue_merge_request_widget/event_hub'; import eventHub from '~/vue_merge_request_widget/event_hub';
import mountComponent from 'spec/helpers/vue_mount_component_helper';
describe('MRWidgetAutoMergeFailed', () => { describe('MRWidgetAutoMergeFailed', () => {
let vm; let wrapper;
const mergeError = 'This is the merge error'; const mergeError = 'This is the merge error';
const findButton = () => wrapper.find('button');
const createComponent = (props = {}) => {
wrapper = shallowMount(AutoMergeFailedComponent, {
sync: false,
propsData: { ...props },
});
};
beforeEach(() => { beforeEach(() => {
const Component = Vue.extend(autoMergeFailedComponent); createComponent({
vm = mountComponent(Component, {
mr: { mergeError }, mr: { mergeError },
}); });
}); });
afterEach(() => { afterEach(() => {
vm.$destroy(); wrapper.destroy();
}); });
it('renders failed message', () => { it('renders failed message', () => {
expect(vm.$el.textContent).toContain('This merge request failed to be merged automatically'); expect(wrapper.text()).toContain('This merge request failed to be merged automatically');
}); });
it('renders merge error provided', () => { it('renders merge error provided', () => {
expect(vm.$el.innerText).toContain(mergeError); expect(wrapper.text()).toContain(mergeError);
}); });
it('render refresh button', () => { it('render refresh button', () => {
expect(vm.$el.querySelector('button').textContent.trim()).toEqual('Refresh'); expect(findButton().text()).toEqual('Refresh');
}); });
it('emits event and shows loading icon when button is clicked', done => { it('emits event and shows loading icon when button is clicked', () => {
spyOn(eventHub, '$emit'); jest.spyOn(eventHub, '$emit');
vm.$el.querySelector('button').click(); findButton().trigger('click');
expect(eventHub.$emit.calls.argsFor(0)[0]).toEqual('MRWidgetUpdateRequested'); expect(eventHub.$emit.mock.calls[0][0]).toBe('MRWidgetUpdateRequested');
Vue.nextTick(() => { return wrapper.vm.$nextTick(() => {
expect(vm.$el.querySelector('button').getAttribute('disabled')).toEqual('disabled'); expect(findButton().attributes('disabled')).toEqual('disabled');
expect(vm.$el.querySelector('button .loading-container span').classList).toContain( expect(
'gl-spinner', findButton()
); .find(GlLoadingIcon)
done(); .exists(),
).toBe(true);
}); });
}); });
}); });
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