Commit a56d6581 authored by Illya Klymov's avatar Illya Klymov

Merge branch '220476-convert-mr_widget_status_icon_spec-vtu' into 'master'

Use vue test utils in MR Widget Status Icon spec

See merge request gitlab-org/gitlab!52493
parents c8fd8a89 71c115c8
......@@ -43,10 +43,9 @@ export default {
<gl-button
v-if="showDisabledButton"
type="button"
category="primary"
variant="success"
class="js-disabled-merge-button"
data-testid="disabled-merge-button"
:disabled="true"
>
{{ s__('mrWidget|Merge') }}
......
import Vue from 'vue';
import mountComponent from 'helpers/vue_mount_component_helper';
import { GlLoadingIcon } from '@gitlab/ui';
import { shallowMount, mount } from '@vue/test-utils';
import mrStatusIcon from '~/vue_merge_request_widget/components/mr_widget_status_icon.vue';
describe('MR widget status icon component', () => {
let vm;
let Component;
let wrapper;
beforeEach(() => {
Component = Vue.extend(mrStatusIcon);
});
const findLoadingIcon = () => wrapper.find(GlLoadingIcon);
const findDisabledMergeButton = () => wrapper.find('[data-testid="disabled-merge-button"]');
const createWrapper = (props, mountFn = shallowMount) => {
wrapper = mountFn(mrStatusIcon, {
propsData: {
...props,
},
});
};
afterEach(() => {
vm.$destroy();
wrapper.destroy();
});
describe('while loading', () => {
it('renders loading icon', () => {
vm = mountComponent(Component, { status: 'loading' });
createWrapper({ status: 'loading' });
expect(vm.$el.querySelector('.mr-widget-icon span').classList).toContain('gl-spinner');
expect(findLoadingIcon().exists()).toBe(true);
});
});
describe('with status icon', () => {
it('renders ci status icon', () => {
vm = mountComponent(Component, { status: 'failed' });
it('renders success status icon', () => {
createWrapper({ status: 'success' }, mount);
expect(wrapper.find('[data-testid="status_success-icon"]').exists()).toBe(true);
});
it('renders failed status icon', () => {
createWrapper({ status: 'failed' }, mount);
expect(vm.$el.querySelector('.js-ci-status-icon-failed')).not.toBeNull();
expect(wrapper.find('[data-testid="status_failed-icon"]').exists()).toBe(true);
});
});
describe('with disabled button', () => {
it('renders a disabled button', () => {
vm = mountComponent(Component, { status: 'failed', showDisabledButton: true });
createWrapper({ status: 'failed', showDisabledButton: true });
expect(vm.$el.querySelector('.js-disabled-merge-button').textContent.trim()).toEqual('Merge');
expect(findDisabledMergeButton().exists()).toBe(true);
});
});
describe('without disabled button', () => {
it('does not render a disabled button', () => {
vm = mountComponent(Component, { status: 'failed' });
createWrapper({ status: 'failed' });
expect(vm.$el.querySelector('.js-disabled-merge-button')).toBeNull();
expect(findDisabledMergeButton().exists()).toBe(false);
});
});
});
......@@ -113,9 +113,9 @@ describe('MRWidgetFailedToMerge', () => {
describe('while it is not regresing', () => {
it('renders warning icon and disabled merge button', () => {
expect(vm.$el.querySelector('.js-ci-status-icon-warning')).not.toBeNull();
expect(vm.$el.querySelector('.js-disabled-merge-button').getAttribute('disabled')).toEqual(
'disabled',
);
expect(
vm.$el.querySelector('[data-testid="disabled-merge-button"]').getAttribute('disabled'),
).toEqual('disabled');
});
it('renders given error', () => {
......
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