Commit 71c115c8 authored by Miguel Rincon's avatar Miguel Rincon

Use vue test utils in MR Widget Status Icon spec

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