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

111 lines
2.4 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-09 13:42:32 +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-09 13:42:32 +05:30
return wrapper.vm.$nextTick(() => {
expect(wrapper.isEmpty()).toBe(false);
});
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-09 13:42:32 +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-09 13:42:32 +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-09 13:42:32 +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(() => {
expect(
wrapper
.findAll('li')
.at(0)
2020-07-28 23:09:34 +05:30
.is('.gl-mb-3'),
2020-01-01 13:55:28 +05:30
).toBe(true);
});
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(() => {
expect(
wrapper
.findAll('li')
.at(1)
2020-07-28 23:09:34 +05:30
.is('.gl-mb-3'),
2020-01-01 13:55:28 +05:30
).toBe(false);
});
2019-02-15 15:39:39 +05:30
});
});
});