1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
|
import { shallowMount } from '@vue/test-utils';
import { formatDate, getTimeago } from '~/lib/utils/datetime_utility';
import TimeAgoTooltip from '~/vue_shared/components/time_ago_tooltip.vue';
describe('Time ago with tooltip component', () => {
let vm;
const buildVm = (propsData = {}, scopedSlots = {}) => {
vm = shallowMount(TimeAgoTooltip, {
propsData,
scopedSlots,
});
};
const timestamp = '2017-05-08T14:57:39.781Z';
const timeAgoTimestamp = getTimeago().format(timestamp);
afterEach(() => {
vm.destroy();
});
it('should render timeago with a bootstrap tooltip', () => {
buildVm({
time: timestamp,
});
expect(vm.attributes('title')).toEqual(formatDate(timestamp));
expect(vm.text()).toEqual(timeAgoTimestamp);
});
it('should render provided html class', () => {
buildVm({
time: timestamp,
cssClass: 'foo',
});
expect(vm.classes()).toContain('foo');
});
it('should render with the datetime attribute', () => {
buildVm({ time: timestamp });
expect(vm.attributes('datetime')).toEqual(timestamp);
});
it('should render provided scope content with the correct timeAgo string', () => {
buildVm({ time: timestamp }, { default: `<span>The time is {{ props.timeAgo }}</span>` });
expect(vm.text()).toEqual(`The time is ${timeAgoTimestamp}`);
});
});
|