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

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

108 lines
3.3 KiB
JavaScript
Raw Normal View History

2019-02-15 15:39:39 +05:30
import { shallowMount } from '@vue/test-utils';
2022-04-04 11:22:00 +05:30
import { nextTick } from 'vue';
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
});
2022-04-04 11:22:00 +05:30
it('does not render with empty search', async () => {
2020-01-01 13:55:28 +05:30
wrapper.setProps({ search: '' });
2019-02-15 15:39:39 +05:30
2022-04-04 11:22:00 +05:30
await nextTick();
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 }] };
});
2022-04-04 11:22:00 +05:30
it('renders component', async () => {
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
2022-04-04 11:22:00 +05:30
await nextTick();
expect(wrapper.findAll('li').length).toBe(data.issues.length);
2019-02-15 15:39:39 +05:30
});
2022-04-04 11:22:00 +05:30
it('does not render with empty search', async () => {
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
2022-04-04 11:22:00 +05:30
await nextTick();
expect(wrapper.isVisible()).toBe(false);
2019-02-15 15:39:39 +05:30
});
2022-04-04 11:22:00 +05:30
it('does not render when loading', async () => {
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,
});
2022-04-04 11:22:00 +05:30
await nextTick();
expect(wrapper.isVisible()).toBe(false);
2019-02-15 15:39:39 +05:30
});
2022-04-04 11:22:00 +05:30
it('does not render with empty issues data', async () => {
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
2022-04-04 11:22:00 +05:30
await nextTick();
expect(wrapper.isVisible()).toBe(false);
2019-02-15 15:39:39 +05:30
});
2022-04-04 11:22:00 +05:30
it('renders list of issues', async () => {
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
2022-04-04 11:22:00 +05:30
await nextTick();
2022-10-11 01:57:18 +05:30
expect(wrapper.findAllComponents(TitleSuggestionsItem).length).toBe(2);
2019-02-15 15:39:39 +05:30
});
2022-04-04 11:22:00 +05:30
it('adds margin class to first item', async () => {
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);
2022-04-04 11:22:00 +05:30
await nextTick();
expect(wrapper.findAll('li').at(0).classes()).toContain('gl-mb-3');
2019-02-15 15:39:39 +05:30
});
2022-04-04 11:22:00 +05:30
it('does not add margin class to last item', async () => {
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);
2022-04-04 11:22:00 +05:30
await nextTick();
expect(wrapper.findAll('li').at(1).classes()).not.toContain('gl-mb-3');
2019-02-15 15:39:39 +05:30
});
});
});