Commit b7302be0 authored by Fatih Acet's avatar Fatih Acet

Rewrite failing specs with VueTestUtils

To also verify existence of the slots
parent 325fd300
...@@ -250,7 +250,6 @@ export default { ...@@ -250,7 +250,6 @@ export default {
:path="issue.path" :path="issue.path"
:state="issue.state" :state="issue.state"
:milestone="issue.milestone" :milestone="issue.milestone"
:due-date="issue.due_date"
:assignees="issue.assignees" :assignees="issue.assignees"
:created-at="issue.created_at" :created-at="issue.created_at"
:closed-at="issue.closed_at" :closed-at="issue.closed_at"
......
import Vue from 'vue'; import Vue from 'vue';
import issueItem from '~/vue_shared/components/issue/related_issuable_item.vue'; import { mount, createLocalVue } from '@vue/test-utils';
import mountComponent from 'spec/helpers/vue_mount_component_helper'; import RelatedIssuableItem from '~/vue_shared/components/issue/related_issuable_item.vue';
import { defaultMilestone, defaultAssignees } from './related_issuable_mock_data'; import { defaultMilestone, defaultAssignees } from './related_issuable_mock_data';
describe('issueItem', () => { describe('RelatedIssuableItem', () => {
let vm; let wrapper;
const props = { const props = {
idKey: 1, idKey: 1,
displayReference: 'gitlab-org/gitlab-test#1', displayReference: 'gitlab-org/gitlab-test#1',
...@@ -19,38 +19,50 @@ describe('issueItem', () => { ...@@ -19,38 +19,50 @@ describe('issueItem', () => {
assignees: defaultAssignees, assignees: defaultAssignees,
eventNamespace: 'relatedIssue', eventNamespace: 'relatedIssue',
}; };
const slots = {
dueDate: '<div class="js-due-date-slot"></div>',
weight: '<div class="js-weight-slot"></div>',
};
beforeEach(() => { beforeEach(() => {
const IssueItem = Vue.extend(issueItem); const localVue = createLocalVue();
vm = mountComponent(IssueItem, props);
wrapper = mount(localVue.extend(RelatedIssuableItem), {
localVue,
slots,
sync: false,
propsData: props,
});
});
afterEach(() => {
wrapper.destroy();
}); });
it('contains issuable-info-container class when canReorder is false', () => { it('contains issuable-info-container class when canReorder is false', () => {
expect(vm.canReorder).toEqual(false); expect(wrapper.props('canReorder')).toBe(false);
expect(vm.$el.querySelector('.issuable-info-container')).toBeNull(); expect(wrapper.find('.issuable-info-container').exists()).toBe(true);
}); });
it('does not render token state', () => { it('does not render token state', () => {
expect(vm.$el.querySelector('.text-secondary svg')).toBeNull(); expect(wrapper.find('.text-secondary svg').exists()).toBe(false);
}); });
it('does not render remove button', () => { it('does not render remove button', () => {
expect(vm.$refs.removeButton).toBeUndefined(); expect(wrapper.find({ ref: 'removeButton' }).exists()).toBe(false);
}); });
describe('token title', () => { describe('token title', () => {
it('links to computedPath', () => { it('links to computedPath', () => {
expect(vm.$el.querySelector('.item-title a').href).toEqual(props.path); expect(wrapper.find('.item-title a').attributes('href')).toEqual(wrapper.props('path'));
}); });
it('renders confidential icon', () => { it('renders confidential icon', () => {
expect( expect(wrapper.find('.confidential-icon').exists()).toBe(true);
vm.$el.querySelector('.item-title svg.confidential-icon use').getAttribute('xlink:href'),
).toContain('eye-slash');
}); });
it('renders title', () => { it('renders title', () => {
expect(vm.$el.querySelector('.item-title a').innerText.trim()).toEqual(props.title); expect(wrapper.find('.item-title a').text()).toEqual(props.title);
}); });
}); });
...@@ -58,19 +70,21 @@ describe('issueItem', () => { ...@@ -58,19 +70,21 @@ describe('issueItem', () => {
let tokenState; let tokenState;
beforeEach(done => { beforeEach(done => {
vm.state = 'opened'; wrapper.setProps({ state: 'opened' });
Vue.nextTick(() => { Vue.nextTick(() => {
tokenState = vm.$el.querySelector('.item-meta svg'); tokenState = wrapper.find('.issue-token-state-icon-open');
done(); done();
}); });
}); });
it('renders if hasState', () => { it('renders if hasState', () => {
expect(tokenState).toBeDefined(); expect(tokenState.exists()).toBe(true);
}); });
it('renders state title', () => { it('renders state title', () => {
const stateTitle = tokenState.getAttribute('data-original-title').trim(); const stateTitle = tokenState.attributes('data-original-title');
expect(stateTitle).toContain('<span class="bold">Opened</span>'); expect(stateTitle).toContain('<span class="bold">Opened</span>');
expect(stateTitle).toContain( expect(stateTitle).toContain(
...@@ -79,19 +93,22 @@ describe('issueItem', () => { ...@@ -79,19 +93,22 @@ describe('issueItem', () => {
}); });
it('renders aria label', () => { it('renders aria label', () => {
expect(tokenState.getAttribute('aria-label')).toEqual('opened'); expect(tokenState.attributes('aria-label')).toEqual('opened');
}); });
it('renders open icon when open state', () => { it('renders open icon when open state', () => {
expect(tokenState.classList.contains('issue-token-state-icon-open')).toEqual(true); expect(tokenState.classes('issue-token-state-icon-open')).toBe(true);
}); });
it('renders close icon when close state', done => { it('renders close icon when close state', done => {
vm.state = 'closed'; wrapper.setProps({
vm.closedAt = '2018-12-01T00:00:00.00Z'; state: 'closed',
closedAt: '2018-12-01T00:00:00.00Z',
});
Vue.nextTick(() => { Vue.nextTick(() => {
expect(tokenState.classList.contains('issue-token-state-icon-closed')).toEqual(true); expect(tokenState.classes('issue-token-state-icon-closed')).toBe(true);
done(); done();
}); });
}); });
...@@ -102,49 +119,40 @@ describe('issueItem', () => { ...@@ -102,49 +119,40 @@ describe('issueItem', () => {
beforeEach(done => { beforeEach(done => {
Vue.nextTick(() => { Vue.nextTick(() => {
tokenMetadata = vm.$el.querySelector('.item-meta'); tokenMetadata = wrapper.find('.item-meta');
done(); done();
}); });
}); });
it('renders item path and ID', () => { it('renders item path and ID', () => {
const pathAndID = tokenMetadata.querySelector('.item-path-id').innerText.trim(); const pathAndID = tokenMetadata.find('.item-path-id').text();
expect(pathAndID).toContain('gitlab-org/gitlab-test'); expect(pathAndID).toContain('gitlab-org/gitlab-test');
expect(pathAndID).toContain('#1'); expect(pathAndID).toContain('#1');
}); });
it('renders milestone icon and name', () => { it('renders milestone icon and name', () => {
const milestoneIconEl = tokenMetadata.querySelector('.item-milestone svg use'); const milestoneIcon = tokenMetadata.find('.item-milestone svg use');
const milestoneTitle = tokenMetadata.querySelector('.item-milestone .milestone-title'); const milestoneTitle = tokenMetadata.find('.item-milestone .milestone-title');
expect(milestoneIconEl.getAttribute('xlink:href')).toContain('clock'); expect(milestoneIcon.attributes('href')).toContain('clock');
expect(milestoneTitle.innerText.trim()).toContain('Milestone title'); expect(milestoneTitle.text()).toContain('Milestone title');
}); });
it('renders date icon and due date', () => { it('renders due date component', () => {
const dueDateIconEl = tokenMetadata.querySelector('.item-due-date svg use'); expect(tokenMetadata.find('.js-due-date-slot').exists()).toBe(true);
const dueDateEl = tokenMetadata.querySelector('.item-due-date time');
expect(dueDateIconEl.getAttribute('xlink:href')).toContain('calendar');
expect(dueDateEl.innerText.trim()).toContain('Dec 31');
}); });
it('renders weight icon and value', () => { it('renders weight component', () => {
const dueDateIconEl = tokenMetadata.querySelector('.item-weight svg use'); expect(tokenMetadata.find('.js-weight-slot').exists()).toBe(true);
const dueDateEl = tokenMetadata.querySelector('.item-weight span');
expect(dueDateIconEl.getAttribute('xlink:href')).toContain('weight');
expect(dueDateEl.innerText.trim()).toContain('10');
}); });
}); });
describe('token assignees', () => { describe('token assignees', () => {
it('renders assignees avatars', () => { it('renders assignees avatars', () => {
const assigneesEl = vm.$el.querySelector('.item-assignees'); expect(wrapper.findAll('.item-assignees .user-avatar-link').length).toBe(2);
expect(wrapper.find('.item-assignees .avatar-counter').text()).toContain('+2');
expect(assigneesEl.querySelectorAll('.user-avatar-link').length).toBe(2);
expect(assigneesEl.querySelector('.avatar-counter').innerText.trim()).toContain('+2');
}); });
}); });
...@@ -152,30 +160,35 @@ describe('issueItem', () => { ...@@ -152,30 +160,35 @@ describe('issueItem', () => {
let removeBtn; let removeBtn;
beforeEach(done => { beforeEach(done => {
vm.canRemove = true; wrapper.setProps({ canRemove: true });
Vue.nextTick(() => { Vue.nextTick(() => {
removeBtn = vm.$refs.removeButton; removeBtn = wrapper.find({ ref: 'removeButton' });
done(); done();
}); });
}); });
it('renders if canRemove', () => { it('renders if canRemove', () => {
expect(removeBtn).toBeDefined(); expect(removeBtn.exists()).toBe(true);
}); });
it('renders disabled button when removeDisabled', done => { it('renders disabled button when removeDisabled', done => {
vm.removeDisabled = true; wrapper.vm.removeDisabled = true;
Vue.nextTick(() => { Vue.nextTick(() => {
expect(removeBtn.hasAttribute('disabled')).toEqual(true); expect(removeBtn.attributes('disabled')).toEqual('disabled');
done(); done();
}); });
}); });
it('triggers onRemoveRequest when clicked', () => { it('triggers onRemoveRequest when clicked', () => {
spyOn(vm, '$emit'); removeBtn.trigger('click');
removeBtn.click();
const { relatedIssueRemoveRequest } = wrapper.emitted();
expect(vm.$emit).toHaveBeenCalledWith('relatedIssueRemoveRequest', props.idKey); expect(relatedIssueRemoveRequest.length).toBe(1);
expect(relatedIssueRemoveRequest[0]).toEqual([props.idKey]);
}); });
}); });
}); });
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