debian-mirror-gitlab/spec/javascripts/vue_shared/directives/tooltip_spec.js

90 lines
2 KiB
JavaScript
Raw Normal View History

2018-05-09 12:01:36 +05:30
import $ from 'jquery';
2017-09-10 17:25:29 +05:30
import Vue from 'vue';
import tooltip from '~/vue_shared/directives/tooltip';
describe('Tooltip directive', () => {
let vm;
afterEach(() => {
if (vm) {
vm.$destroy();
}
});
describe('with a single tooltip', () => {
beforeEach(() => {
2018-12-13 13:39:08 +05:30
setFixtures('<div id="dummy-element"></div>');
vm = new Vue({
el: '#dummy-element',
2017-09-10 17:25:29 +05:30
directives: {
tooltip,
},
2018-12-13 13:39:08 +05:30
data() {
return {
tooltip: 'some text',
};
},
template: '<div v-tooltip :title="tooltip"></div>',
2017-09-10 17:25:29 +05:30
});
});
it('should have tooltip plugin applied', () => {
expect($(vm.$el).data('bs.tooltip')).toBeDefined();
});
2018-12-13 13:39:08 +05:30
it('displays the title as tooltip', () => {
$(vm.$el).tooltip('show');
const tooltipElement = document.querySelector('.tooltip-inner');
expect(tooltipElement.innerText).toContain('some text');
});
it('updates a visible tooltip', done => {
$(vm.$el).tooltip('show');
const tooltipElement = document.querySelector('.tooltip-inner');
vm.tooltip = 'other text';
Vue.nextTick()
.then(() => {
expect(tooltipElement).toContainText('other text');
done();
})
.catch(done.fail);
});
2017-09-10 17:25:29 +05:30
});
describe('with multiple tooltips', () => {
beforeEach(() => {
const SomeComponent = Vue.extend({
directives: {
tooltip,
},
template: `
<div>
<div
v-tooltip
class="js-look-for-tooltip"
title="foo">
</div>
<div
v-tooltip
title="bar">
</div>
</div>
`,
});
vm = new SomeComponent().$mount();
});
it('should have tooltip plugin applied to all instances', () => {
2018-12-13 13:39:08 +05:30
expect(
$(vm.$el)
.find('.js-look-for-tooltip')
.data('bs.tooltip'),
).toBeDefined();
2017-09-10 17:25:29 +05:30
});
});
});