debian-mirror-gitlab/spec/frontend/issuable_suggestions/components/app_spec.js

101 lines
2.3 KiB
JavaScript
Raw Normal View History

2019-02-15 15:39:39 +05:30
import { shallowMount } from '@vue/test-utils';
import App from '~/issuable_suggestions/components/app.vue';
import Suggestion from '~/issuable_suggestions/components/item.vue';
describe('Issuable suggestions app component', () => {
2020-01-01 13:55:28 +05:30
let wrapper;
2019-02-15 15:39:39 +05:30
function createComponent(search = 'search') {
2020-01-01 13:55:28 +05:30
wrapper = shallowMount(App, {
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', () => {
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: '' });
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', () => {
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', () => {
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', () => {
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(() => {
expect(wrapper.findAll(Suggestion).length).toBe(2);
});
2019-02-15 15:39:39 +05:30
});
it('adds margin class to first item', () => {
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', () => {
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
});
});
});