Commit 11ee50ee authored by Kushal Pandya's avatar Kushal Pandya

Merge branch '220457-convert-jest-tests-to-use-vtu-in-ee-spec-frontend-issuable' into 'master'

Convert Jest tests to use VTU in 'spec/frontend/issuable'

See merge request gitlab-org/gitlab!43502
parents b02482b9 687e6f1e
...@@ -90,6 +90,7 @@ export default { ...@@ -90,6 +90,7 @@ export default {
:size="12" :size="12"
:title="stateTitle" :title="stateTitle"
:aria-label="state" :aria-label="state"
data-testid="referenceIcon"
/> />
{{ displayReference }} {{ displayReference }}
</component> </component>
...@@ -105,6 +106,7 @@ export default { ...@@ -105,6 +106,7 @@ export default {
:title="removeButtonLabel" :title="removeButtonLabel"
:aria-label="removeButtonLabel" :aria-label="removeButtonLabel"
:disabled="removeDisabled" :disabled="removeDisabled"
data-testid="removeBtn"
type="button" type="button"
class="js-issue-token-remove-button" class="js-issue-token-remove-button"
@click="onRemoveRequest" @click="onRemoveRequest"
......
...@@ -111,7 +111,7 @@ const mixins = { ...@@ -111,7 +111,7 @@ const mixins = {
return this.isMergeRequest && this.pipelineStatus && Object.keys(this.pipelineStatus).length; return this.isMergeRequest && this.pipelineStatus && Object.keys(this.pipelineStatus).length;
}, },
isOpen() { isOpen() {
return this.state === 'opened'; return this.state === 'opened' || this.state === 'reopened';
}, },
isClosed() { isClosed() {
return this.state === 'closed'; return this.state === 'closed';
......
...@@ -11,7 +11,10 @@ describe('RelatedIssuesList', () => { ...@@ -11,7 +11,10 @@ describe('RelatedIssuesList', () => {
let wrapper; let wrapper;
afterEach(() => { afterEach(() => {
if (wrapper) {
wrapper.destroy(); wrapper.destroy();
wrapper = null;
}
}); });
describe('related item contents', () => { describe('related item contents', () => {
......
...@@ -48,7 +48,10 @@ describe('AddIssuableForm', () => { ...@@ -48,7 +48,10 @@ describe('AddIssuableForm', () => {
const input = findFormInput(wrapper); const input = findFormInput(wrapper);
if (input) input.blur(); if (input) input.blur();
if (wrapper) {
wrapper.destroy(); wrapper.destroy();
wrapper = null;
}
}); });
describe('with data', () => { describe('with data', () => {
......
import Vue from 'vue'; import { shallowMount } from '@vue/test-utils';
import { PathIdSeparator } from '~/related_issues/constants'; import { PathIdSeparator } from '~/related_issues/constants';
import issueToken from '~/related_issues/components/issue_token.vue'; import IssueToken from '~/related_issues/components/issue_token.vue';
describe('IssueToken', () => { describe('IssueToken', () => {
const idKey = 200; const idKey = 200;
const displayReference = 'foo/bar#123'; const displayReference = 'foo/bar#123';
const title = 'some title';
const pathIdSeparator = PathIdSeparator.Issue;
const eventNamespace = 'pendingIssuable'; const eventNamespace = 'pendingIssuable';
let IssueToken; const path = '/foo/bar/issues/123';
let vm; const pathIdSeparator = PathIdSeparator.Issue;
const title = 'some title';
beforeEach(() => { let wrapper;
IssueToken = Vue.extend(issueToken);
const defaultProps = {
idKey,
displayReference,
pathIdSeparator,
};
const createComponent = (props = {}) => {
wrapper = shallowMount(IssueToken, {
propsData: { ...defaultProps, ...props },
}); });
};
afterEach(() => { afterEach(() => {
if (vm) { if (wrapper) {
vm.$destroy(); wrapper.destroy();
wrapper = null;
} }
}); });
const findLink = () => wrapper.find({ ref: 'link' });
const findReference = () => wrapper.find({ ref: 'reference' });
const findReferenceIcon = () => wrapper.find('[data-testid="referenceIcon"]');
const findRemoveBtn = () => wrapper.find('[data-testid="removeBtn"]');
const findTitle = () => wrapper.find({ ref: 'title' });
describe('with reference supplied', () => { describe('with reference supplied', () => {
beforeEach(() => { beforeEach(() => {
vm = new IssueToken({ createComponent();
propsData: {
idKey,
eventNamespace,
displayReference,
pathIdSeparator,
},
}).$mount();
}); });
it('shows reference', () => { it('shows reference', () => {
expect(vm.$el.textContent.trim()).toEqual(displayReference); expect(wrapper.text()).toContain(displayReference);
}); });
it('does not link without path specified', () => { it('does not link without path specified', () => {
expect(vm.$refs.link.tagName.toLowerCase()).toEqual('span'); expect(findLink().element.tagName).toBe('SPAN');
expect(vm.$refs.link.getAttribute('href')).toBeNull(); expect(findLink().attributes('href')).toBeUndefined();
}); });
}); });
describe('with reference and title supplied', () => { describe('with reference and title supplied', () => {
beforeEach(() => { it('shows reference and title', () => {
vm = new IssueToken({ createComponent({
propsData: {
idKey,
eventNamespace,
displayReference,
pathIdSeparator,
title, title,
},
}).$mount();
}); });
it('shows reference and title', () => { expect(findReference().text()).toBe(displayReference);
expect(vm.$refs.reference.textContent.trim()).toEqual(displayReference); expect(findTitle().text()).toBe(title);
expect(vm.$refs.title.textContent.trim()).toEqual(title);
}); });
}); });
describe('with path supplied', () => { describe('with path and title supplied', () => {
const path = '/foo/bar/issues/123'; it('links reference and title', () => {
beforeEach(() => { createComponent({
vm = new IssueToken({
propsData: {
idKey,
eventNamespace,
displayReference,
pathIdSeparator,
title,
path, path,
}, title,
}).$mount();
}); });
it('links reference and title', () => { expect(findLink().attributes('href')).toBe(path);
expect(vm.$refs.link.getAttribute('href')).toEqual(path);
}); });
}); });
describe('with state supplied', () => { describe('with state supplied', () => {
describe("`state: 'opened'`", () => { it.each`
beforeEach(() => { state | icon | cssClass
vm = new IssueToken({ ${'opened'} | ${'issue-open-m'} | ${'issue-token-state-icon-open'}
propsData: { ${'reopened'} | ${'issue-open-m'} | ${'issue-token-state-icon-open'}
idKey, ${'closed'} | ${'issue-close'} | ${'issue-token-state-icon-closed'}
eventNamespace, `('shows "$icon" icon when "$state"', ({ state, icon, cssClass }) => {
displayReference, createComponent({
pathIdSeparator, path,
state: 'opened', state,
},
}).$mount();
});
it('shows green circle icon', () => {
expect(vm.$el.querySelector('.issue-token-state-icon-open.fa.fa-circle-o')).toBeDefined();
});
});
describe("`state: 'reopened'`", () => {
beforeEach(() => {
vm = new IssueToken({
propsData: {
idKey,
eventNamespace,
displayReference,
pathIdSeparator,
state: 'reopened',
},
}).$mount();
});
it('shows green circle icon', () => {
expect(vm.$el.querySelector('.issue-token-state-icon-open.fa.fa-circle-o')).toBeDefined();
});
});
describe("`state: 'closed'`", () => {
beforeEach(() => {
vm = new IssueToken({
propsData: {
idKey,
eventNamespace,
displayReference,
pathIdSeparator,
state: 'closed',
},
}).$mount();
}); });
it('shows red minus icon', () => { expect(findReferenceIcon().props('name')).toBe(icon);
expect(vm.$el.querySelector('.issue-token-state-icon-closed.fa.fa-minus')).toBeDefined(); expect(findReferenceIcon().classes()).toContain(cssClass);
});
}); });
}); });
describe('with reference, title, state', () => { describe('with reference, title, state', () => {
const state = 'opened'; const state = 'opened';
beforeEach(() => {
vm = new IssueToken({ it('shows reference, title, and state', () => {
propsData: { createComponent({
idKey,
eventNamespace,
displayReference,
pathIdSeparator,
title, title,
state, state,
},
}).$mount();
}); });
it('shows reference, title, and state', () => { expect(findReferenceIcon().attributes('aria-label')).toBe(state);
const stateIcon = vm.$refs.reference.querySelector('svg'); expect(findReference().text()).toBe(displayReference);
expect(findTitle().text()).toBe(title);
expect(stateIcon.getAttribute('aria-label')).toEqual(state);
expect(vm.$refs.reference.textContent.trim()).toEqual(displayReference);
expect(vm.$refs.title.textContent.trim()).toEqual(title);
}); });
}); });
describe('with canRemove', () => { describe('with canRemove', () => {
describe('`canRemove: false` (default)', () => { describe('`canRemove: false` (default)', () => {
beforeEach(() => {
vm = new IssueToken({
propsData: {
idKey,
eventNamespace,
displayReference,
pathIdSeparator,
},
}).$mount();
});
it('does not have remove button', () => { it('does not have remove button', () => {
expect(vm.$el.querySelector('.issue-token-remove-button')).toBeNull(); createComponent();
expect(findRemoveBtn().exists()).toBe(false);
}); });
}); });
describe('`canRemove: true`', () => { describe('`canRemove: true`', () => {
beforeEach(() => { beforeEach(() => {
vm = new IssueToken({ createComponent({
propsData: {
idKey,
eventNamespace, eventNamespace,
displayReference,
pathIdSeparator,
canRemove: true, canRemove: true,
}, });
}).$mount();
}); });
it('has remove button', () => { it('has remove button', () => {
expect(vm.$el.querySelector('.issue-token-remove-button')).toBeDefined(); expect(findRemoveBtn().exists()).toBe(true);
});
});
}); });
describe('methods', () => { it('emits event when clicked', () => {
beforeEach(() => { findRemoveBtn().trigger('click');
vm = new IssueToken({
propsData: {
idKey,
eventNamespace,
displayReference,
pathIdSeparator,
},
}).$mount();
});
it('when getting checked', () => { const emitted = wrapper.emitted(`${eventNamespace}RemoveRequest`);
jest.spyOn(vm, '$emit').mockImplementation(() => {});
vm.onRemoveRequest();
expect(vm.$emit).toHaveBeenCalledWith('pendingIssuableRemoveRequest', vm.idKey); expect(emitted).toHaveLength(1);
}); expect(emitted[0]).toEqual([idKey]);
}); });
describe('tooltip', () => { it('tooltip should not be escaped', () => {
beforeEach(() => { expect(findRemoveBtn().attributes('data-original-title')).toBe(
vm = new IssueToken({ `Remove ${displayReference}`,
propsData: { );
idKey,
eventNamespace,
displayReference,
pathIdSeparator,
canRemove: true,
},
}).$mount();
}); });
it('should not be escaped', () => {
const { originalTitle } = vm.$refs.removeButton.dataset;
expect(originalTitle).toEqual(`Remove ${displayReference}`);
}); });
}); });
}); });
...@@ -18,7 +18,10 @@ describe('RelatedIssuesBlock', () => { ...@@ -18,7 +18,10 @@ describe('RelatedIssuesBlock', () => {
const findIssueCountBadgeAddButton = () => wrapper.find(GlButton); const findIssueCountBadgeAddButton = () => wrapper.find(GlButton);
afterEach(() => { afterEach(() => {
if (wrapper) {
wrapper.destroy(); wrapper.destroy();
wrapper = null;
}
}); });
describe('with defaults', () => { describe('with defaults', () => {
......
...@@ -14,7 +14,10 @@ describe('RelatedIssuesList', () => { ...@@ -14,7 +14,10 @@ describe('RelatedIssuesList', () => {
let wrapper; let wrapper;
afterEach(() => { afterEach(() => {
if (wrapper) {
wrapper.destroy(); wrapper.destroy();
wrapper = null;
}
}); });
describe('with defaults', () => { describe('with defaults', () => {
......
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