debian-mirror-gitlab/spec/frontend/vue_shared/components/tabs/tabs_spec.js

62 lines
1.7 KiB
JavaScript
Raw Normal View History

2018-11-08 19:23:39 +05:30
import Vue from 'vue';
import Tabs from '~/vue_shared/components/tabs/tabs';
import Tab from '~/vue_shared/components/tabs/tab.vue';
describe('Tabs component', () => {
let vm;
2020-05-24 23:13:21 +05:30
beforeEach(() => {
2018-11-08 19:23:39 +05:30
vm = new Vue({
components: {
Tabs,
Tab,
},
2020-05-24 23:13:21 +05:30
render(h) {
return h('div', [
h('tabs', [
h('tab', { attrs: { title: 'Testing', active: true } }, 'First tab'),
h('tab', [h('template', { slot: 'title' }, 'Test slot'), 'Second tab']),
]),
]);
},
2018-11-08 19:23:39 +05:30
}).$mount();
2020-05-24 23:13:21 +05:30
return vm.$nextTick();
2018-11-08 19:23:39 +05:30
});
describe('tab links', () => {
it('renders links for tabs', () => {
expect(vm.$el.querySelectorAll('a').length).toBe(2);
});
it('renders link titles from props', () => {
expect(vm.$el.querySelector('a').textContent).toContain('Testing');
});
it('renders link titles from slot', () => {
expect(vm.$el.querySelectorAll('a')[1].textContent).toContain('Test slot');
});
it('renders active class', () => {
expect(vm.$el.querySelector('a').classList).toContain('active');
});
2020-05-24 23:13:21 +05:30
it('updates active class on click', () => {
2018-11-08 19:23:39 +05:30
vm.$el.querySelectorAll('a')[1].click();
2020-05-24 23:13:21 +05:30
return vm.$nextTick(() => {
2018-11-08 19:23:39 +05:30
expect(vm.$el.querySelector('a').classList).not.toContain('active');
expect(vm.$el.querySelectorAll('a')[1].classList).toContain('active');
});
});
});
describe('content', () => {
it('renders content panes', () => {
expect(vm.$el.querySelectorAll('.tab-pane').length).toBe(2);
expect(vm.$el.querySelectorAll('.tab-pane')[0].textContent).toContain('First tab');
expect(vm.$el.querySelectorAll('.tab-pane')[1].textContent).toContain('Second tab');
});
});
});