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 autoMergeFailedComponent from '~/vue_merge_request_widget/components/states/mr_widget_auto_merge_failed.vue';
import { shallowMount } from '@vue/test-utils';
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 mountComponent from 'spec/helpers/vue_mount_component_helper';
describe('MRWidgetAutoMergeFailed', () => {
let vm;
let wrapper;
const mergeError = 'This is the merge error';
const findButton = () => wrapper.find('button');
const createComponent = (props = {}) => {
wrapper = shallowMount(AutoMergeFailedComponent, {
sync: false,
propsData: { ...props },
});
};
beforeEach(() => {
const Component = Vue.extend(autoMergeFailedComponent);
vm = mountComponent(Component, {
createComponent({
mr: { mergeError },
});
});
afterEach(() => {
vm.$destroy();
wrapper.destroy();
});
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', () => {
expect(vm.$el.innerText).toContain(mergeError);
expect(wrapper.text()).toContain(mergeError);
});
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 => {
spyOn(eventHub, '$emit');
vm.$el.querySelector('button').click();
it('emits event and shows loading icon when button is clicked', () => {
jest.spyOn(eventHub, '$emit');
findButton().trigger('click');
expect(eventHub.$emit.calls.argsFor(0)[0]).toEqual('MRWidgetUpdateRequested');
expect(eventHub.$emit.mock.calls[0][0]).toBe('MRWidgetUpdateRequested');
Vue.nextTick(() => {
expect(vm.$el.querySelector('button').getAttribute('disabled')).toEqual('disabled');
expect(vm.$el.querySelector('button .loading-container span').classList).toContain(
'gl-spinner',
);
done();
return wrapper.vm.$nextTick(() => {
expect(findButton().attributes('disabled')).toEqual('disabled');
expect(
findButton()
.find(GlLoadingIcon)
.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