summaryrefslogtreecommitdiff
path: root/spec/javascripts/issue_show/components/edited_spec.js
blob: a0d0750ae348d880f05cccf37c69f73b3c96dbdd (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
import Vue from 'vue';
import edited from '~/issue_show/components/edited.vue';

function formatText(text) {
  return text.trim().replace(/\s\s+/g, ' ');
}

describe('edited', () => {
  const EditedComponent = Vue.extend(edited);

  it('should render an edited at+by string', () => {
    const editedComponent = new EditedComponent({
      propsData: {
        updatedAt: '2017-05-15T12:31:04.428Z',
        updatedByName: 'Some User',
        updatedByPath: '/some_user',
      },
    }).$mount();

    expect(formatText(editedComponent.$el.innerText)).toMatch(/Edited[\s\S]+?by Some User/);
    expect(editedComponent.$el.querySelector('.author_link').href).toMatch(/\/some_user$/);
    expect(editedComponent.$el.querySelector('time')).toBeTruthy();
  });

  it('if no updatedAt is provided, no time element will be rendered', () => {
    const editedComponent = new EditedComponent({
      propsData: {
        updatedByName: 'Some User',
        updatedByPath: '/some_user',
      },
    }).$mount();

    expect(formatText(editedComponent.$el.innerText)).toMatch(/Edited by Some User/);
    expect(editedComponent.$el.querySelector('.author_link').href).toMatch(/\/some_user$/);
    expect(editedComponent.$el.querySelector('time')).toBeFalsy();
  });

  it('if no updatedByName and updatedByPath is provided, no user element will be rendered', () => {
    const editedComponent = new EditedComponent({
      propsData: {
        updatedAt: '2017-05-15T12:31:04.428Z',
      },
    }).$mount();

    expect(formatText(editedComponent.$el.innerText)).not.toMatch(/by Some User/);
    expect(editedComponent.$el.querySelector('.author_link')).toBeFalsy();
    expect(editedComponent.$el.querySelector('time')).toBeTruthy();
  });
});