Commit 603e3de5 authored by Kushal Pandya's avatar Kushal Pandya

Merge branch 'jivanvl-update-spec-vue-test-utils' into 'master'

Refactor ci_icon_spec to use vue-test-utils

See merge request gitlab-org/gitlab!53417
parents a8073782 e917f90f
import Vue from 'vue'; import { shallowMount } from '@vue/test-utils';
import mountComponent from 'helpers/vue_mount_component_helper'; import { GlIcon } from '@gitlab/ui';
import ciIcon from '~/vue_shared/components/ci_icon.vue'; import ciIcon from '~/vue_shared/components/ci_icon.vue';
describe('CI Icon component', () => { describe('CI Icon component', () => {
const Component = Vue.extend(ciIcon); let wrapper;
let vm;
afterEach(() => { afterEach(() => {
vm.$destroy(); wrapper.destroy();
wrapper = null;
}); });
it('should render a span element with an svg', () => { it('should render a span element with an svg', () => {
vm = mountComponent(Component, { wrapper = shallowMount(ciIcon, {
status: { propsData: {
icon: 'status_success', status: {
}, icon: 'status_success',
}); },
},
expect(vm.$el.tagName).toEqual('SPAN'); });
expect(vm.$el.querySelector('span > svg')).toBeDefined();
}); expect(wrapper.find('span').exists()).toBe(true);
expect(wrapper.find(GlIcon).exists()).toBe(true);
it('should render a success status', () => { });
vm = mountComponent(Component, {
status: { describe('rendering a status', () => {
icon: 'status_success', it.each`
group: 'success', icon | group | cssClass
}, ${'status_success'} | ${'success'} | ${'ci-status-icon-success'}
}); ${'status_failed'} | ${'failed'} | ${'ci-status-icon-failed'}
${'status_warning'} | ${'warning'} | ${'ci-status-icon-warning'}
expect(vm.$el.classList.contains('ci-status-icon-success')).toEqual(true); ${'status_pending'} | ${'pending'} | ${'ci-status-icon-pending'}
}); ${'status_running'} | ${'running'} | ${'ci-status-icon-running'}
${'status_created'} | ${'created'} | ${'ci-status-icon-created'}
it('should render a failed status', () => { ${'status_skipped'} | ${'skipped'} | ${'ci-status-icon-skipped'}
vm = mountComponent(Component, { ${'status_canceled'} | ${'canceled'} | ${'ci-status-icon-canceled'}
status: { ${'status_manual'} | ${'manual'} | ${'ci-status-icon-manual'}
icon: 'status_failed', `('should render a $group status', ({ icon, group, cssClass }) => {
group: 'failed', wrapper = shallowMount(ciIcon, {
}, propsData: {
}); status: {
icon,
expect(vm.$el.classList.contains('ci-status-icon-failed')).toEqual(true); group,
}); },
},
it('should render success with warnings status', () => { });
vm = mountComponent(Component, {
status: { expect(wrapper.classes()).toContain(cssClass);
icon: 'status_warning',
group: 'warning',
},
});
expect(vm.$el.classList.contains('ci-status-icon-warning')).toEqual(true);
});
it('should render pending status', () => {
vm = mountComponent(Component, {
status: {
icon: 'status_pending',
group: 'pending',
},
}); });
expect(vm.$el.classList.contains('ci-status-icon-pending')).toEqual(true);
});
it('should render running status', () => {
vm = mountComponent(Component, {
status: {
icon: 'status_running',
group: 'running',
},
});
expect(vm.$el.classList.contains('ci-status-icon-running')).toEqual(true);
});
it('should render created status', () => {
vm = mountComponent(Component, {
status: {
icon: 'status_created',
group: 'created',
},
});
expect(vm.$el.classList.contains('ci-status-icon-created')).toEqual(true);
});
it('should render skipped status', () => {
vm = mountComponent(Component, {
status: {
icon: 'status_skipped',
group: 'skipped',
},
});
expect(vm.$el.classList.contains('ci-status-icon-skipped')).toEqual(true);
});
it('should render canceled status', () => {
vm = mountComponent(Component, {
status: {
icon: 'status_canceled',
group: 'canceled',
},
});
expect(vm.$el.classList.contains('ci-status-icon-canceled')).toEqual(true);
});
it('should render status for manual action', () => {
vm = mountComponent(Component, {
status: {
icon: 'status_manual',
group: 'manual',
},
});
expect(vm.$el.classList.contains('ci-status-icon-manual')).toEqual(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