debian-mirror-gitlab/spec/frontend/issues/new/components/title_suggestions_spec.js

115 lines
3.5 KiB
JavaScript
Raw Normal View History

2019-02-15 15:39:39 +05:30
import { shallowMount } from '@vue/test-utils';
2022-01-26 12:08:38 +05:30
import TitleSuggestions from '~/issues/new/components/title_suggestions.vue';
import TitleSuggestionsItem from '~/issues/new/components/title_suggestions_item.vue';
2019-02-15 15:39:39 +05:30
2022-01-26 12:08:38 +05:30
describe('Issue title suggestions component', () => {
2020-01-01 13:55:28 +05:30
let wrapper;
2019-02-15 15:39:39 +05:30
function createComponent(search = 'search') {
2022-01-26 12:08:38 +05:30
wrapper = shallowMount(TitleSuggestions, {
2019-02-15 15:39:39 +05:30
propsData: {
search,
projectPath: 'project',
},
});
}
2020-01-01 13:55:28 +05:30
beforeEach(() => {
createComponent();
});
2019-02-15 15:39:39 +05:30
afterEach(() => {
2020-01-01 13:55:28 +05:30
wrapper.destroy();
2019-02-15 15:39:39 +05:30
});
it('does not render with empty search', () => {
2020-01-01 13:55:28 +05:30
wrapper.setProps({ search: '' });
2019-02-15 15:39:39 +05:30
2020-03-13 15:44:24 +05:30
return wrapper.vm.$nextTick().then(() => {
expect(wrapper.isVisible()).toBe(false);
});
2019-02-15 15:39:39 +05:30
});
describe('with data', () => {
let data;
beforeEach(() => {
data = { issues: [{ id: 1 }, { id: 2 }] };
});
it('renders component', () => {
2022-03-02 08:16:31 +05:30
// setData usage is discouraged. See https://gitlab.com/groups/gitlab-org/-/epics/7330 for details
// eslint-disable-next-line no-restricted-syntax
2020-01-01 13:55:28 +05:30
wrapper.setData(data);
2019-02-15 15:39:39 +05:30
2020-03-13 15:44:24 +05:30
return wrapper.vm.$nextTick(() => {
2020-11-24 15:15:51 +05:30
expect(wrapper.findAll('li').length).toBe(data.issues.length);
2020-03-13 15:44:24 +05:30
});
2019-02-15 15:39:39 +05:30
});
it('does not render with empty search', () => {
2020-01-01 13:55:28 +05:30
wrapper.setProps({ search: '' });
2022-03-02 08:16:31 +05:30
// setData usage is discouraged. See https://gitlab.com/groups/gitlab-org/-/epics/7330 for details
// eslint-disable-next-line no-restricted-syntax
2020-01-01 13:55:28 +05:30
wrapper.setData(data);
2019-02-15 15:39:39 +05:30
2020-03-13 15:44:24 +05:30
return wrapper.vm.$nextTick(() => {
expect(wrapper.isVisible()).toBe(false);
});
2019-02-15 15:39:39 +05:30
});
it('does not render when loading', () => {
2022-03-02 08:16:31 +05:30
// setData usage is discouraged. See https://gitlab.com/groups/gitlab-org/-/epics/7330 for details
// eslint-disable-next-line no-restricted-syntax
2020-01-01 13:55:28 +05:30
wrapper.setData({
2019-02-15 15:39:39 +05:30
...data,
loading: 1,
});
2020-03-13 15:44:24 +05:30
return wrapper.vm.$nextTick(() => {
expect(wrapper.isVisible()).toBe(false);
});
2019-02-15 15:39:39 +05:30
});
it('does not render with empty issues data', () => {
2022-03-02 08:16:31 +05:30
// setData usage is discouraged. See https://gitlab.com/groups/gitlab-org/-/epics/7330 for details
// eslint-disable-next-line no-restricted-syntax
2020-01-01 13:55:28 +05:30
wrapper.setData({ issues: [] });
2019-02-15 15:39:39 +05:30
2020-03-13 15:44:24 +05:30
return wrapper.vm.$nextTick(() => {
expect(wrapper.isVisible()).toBe(false);
});
2019-02-15 15:39:39 +05:30
});
it('renders list of issues', () => {
2022-03-02 08:16:31 +05:30
// setData usage is discouraged. See https://gitlab.com/groups/gitlab-org/-/epics/7330 for details
// eslint-disable-next-line no-restricted-syntax
2020-01-01 13:55:28 +05:30
wrapper.setData(data);
2019-02-15 15:39:39 +05:30
2020-01-01 13:55:28 +05:30
return wrapper.vm.$nextTick(() => {
2022-01-26 12:08:38 +05:30
expect(wrapper.findAll(TitleSuggestionsItem).length).toBe(2);
2020-01-01 13:55:28 +05:30
});
2019-02-15 15:39:39 +05:30
});
it('adds margin class to first item', () => {
2022-03-02 08:16:31 +05:30
// setData usage is discouraged. See https://gitlab.com/groups/gitlab-org/-/epics/7330 for details
// eslint-disable-next-line no-restricted-syntax
2020-01-01 13:55:28 +05:30
wrapper.setData(data);
return wrapper.vm.$nextTick(() => {
2021-03-08 18:12:59 +05:30
expect(wrapper.findAll('li').at(0).classes()).toContain('gl-mb-3');
2020-01-01 13:55:28 +05:30
});
2019-02-15 15:39:39 +05:30
});
it('does not add margin class to last item', () => {
2022-03-02 08:16:31 +05:30
// setData usage is discouraged. See https://gitlab.com/groups/gitlab-org/-/epics/7330 for details
// eslint-disable-next-line no-restricted-syntax
2020-01-01 13:55:28 +05:30
wrapper.setData(data);
return wrapper.vm.$nextTick(() => {
2021-03-08 18:12:59 +05:30
expect(wrapper.findAll('li').at(1).classes()).not.toContain('gl-mb-3');
2020-01-01 13:55:28 +05:30
});
2019-02-15 15:39:39 +05:30
});
});
});