Commit 91327e62 authored by Kushal Pandya's avatar Kushal Pandya

Merge branch 'prepare-timego-tooltip-for-vb-upgrade' into 'master'

Prepare timeago-tooltip for bootstrap-vue upgrade

See merge request gitlab-org/gitlab!20238
parents 9a259ef0 ff39fdb1
import Vue from 'vue'; import { shallowMount, createLocalVue } from '@vue/test-utils';
import timeagoTooltip from '~/vue_shared/components/time_ago_tooltip.vue'; import TimeAgoTooltip from '~/vue_shared/components/time_ago_tooltip.vue';
import { formatDate, getTimeago } from '~/lib/utils/datetime_utility'; import { formatDate, getTimeago } from '~/lib/utils/datetime_utility';
describe('Time ago with tooltip component', () => { describe('Time ago with tooltip component', () => {
let TimeagoTooltip;
let vm; let vm;
beforeEach(() => { const buildVm = (propsData = {}) => {
TimeagoTooltip = Vue.extend(timeagoTooltip); vm = shallowMount(TimeAgoTooltip, {
attachToDocument: true,
sync: false,
propsData,
localVue: createLocalVue(),
}); });
};
const timestamp = '2017-05-08T14:57:39.781Z';
afterEach(() => { afterEach(() => {
vm.$destroy(); vm.destroy();
}); });
it('should render timeago with a bootstrap tooltip', () => { it('should render timeago with a bootstrap tooltip', () => {
vm = new TimeagoTooltip({ buildVm({
propsData: { time: timestamp,
time: '2017-05-08T14:57:39.781Z', });
},
}).$mount();
expect(vm.$el.tagName).toEqual('TIME');
expect(vm.$el.getAttribute('data-original-title')).toEqual(
formatDate('2017-05-08T14:57:39.781Z'),
);
const timeago = getTimeago(); const timeago = getTimeago();
expect(vm.$el.textContent.trim()).toEqual(timeago.format('2017-05-08T14:57:39.781Z')); expect(vm.attributes('data-original-title')).toEqual(formatDate(timestamp));
expect(vm.text()).toEqual(timeago.format(timestamp));
}); });
it('should render provided html class', () => { it('should render provided html class', () => {
vm = new TimeagoTooltip({ buildVm({
propsData: { time: timestamp,
time: '2017-05-08T14:57:39.781Z',
cssClass: 'foo', cssClass: 'foo',
}, });
}).$mount();
expect(vm.$el.classList.contains('foo')).toEqual(true); expect(vm.classes()).toContain('foo');
}); });
}); });
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment