summaryrefslogtreecommitdiff
path: root/spec/frontend/members/components/table/created_at_spec.js
blob: 793c122587d28a0da52536d0411bb2016d36d80f (plain)
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
52
53
54
55
56
57
58
59
60
61
import { within } from '@testing-library/dom';
import { mount, createWrapper } from '@vue/test-utils';
import { useFakeDate } from 'helpers/fake_date';
import CreatedAt from '~/members/components/table/created_at.vue';
import TimeAgoTooltip from '~/vue_shared/components/time_ago_tooltip.vue';

describe('CreatedAt', () => {
  // March 15th, 2020
  useFakeDate(2020, 2, 15);

  const date = '2020-03-01T00:00:00.000';
  const dateTimeAgo = '2 weeks ago';

  let wrapper;

  const createComponent = (propsData) => {
    wrapper = mount(CreatedAt, {
      propsData: {
        date,
        ...propsData,
      },
    });
  };

  const getByText = (text, options) =>
    createWrapper(within(wrapper.element).getByText(text, options));

  afterEach(() => {
    wrapper.destroy();
  });

  describe('created at text', () => {
    beforeEach(() => {
      createComponent();
    });

    it('displays created at text', () => {
      expect(getByText(dateTimeAgo).exists()).toBe(true);
    });

    it('uses `TimeAgoTooltip` component to display tooltip', () => {
      expect(wrapper.findComponent(TimeAgoTooltip).exists()).toBe(true);
    });
  });

  describe('when `createdBy` prop is provided', () => {
    it('displays a link to the user that created the member', () => {
      createComponent({
        createdBy: {
          name: 'Administrator',
          webUrl: 'https://gitlab.com/root',
        },
      });

      const link = getByText('Administrator');

      expect(link.exists()).toBe(true);
      expect(link.attributes('href')).toBe('https://gitlab.com/root');
    });
  });
});