summaryrefslogtreecommitdiff
path: root/spec/frontend/vue_mr_widget/components/mr_widget_author_spec.js
blob: 8a42e2e2ce7fd1108b669cdfddac4eaa2d817c45 (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
62
import { shallowMount } from '@vue/test-utils';
import { nextTick } from 'vue';
import MrWidgetAuthor from '~/vue_merge_request_widget/components/mr_widget_author.vue';

window.gl = window.gl || {};

describe('MrWidgetAuthor', () => {
  let wrapper;
  let oldWindowGl;
  const mockAuthor = {
    name: 'Administrator',
    username: 'root',
    webUrl: 'http://localhost:3000/root',
    avatarUrl: 'http://www.gravatar.com/avatar/e64c7d89f26bd1972efa854d13d7dd61?s=80&d=identicon',
  };

  beforeEach(() => {
    oldWindowGl = window.gl;
    window.gl = {
      mrWidgetData: {
        defaultAvatarUrl: 'no_avatar.png',
      },
    };
    wrapper = shallowMount(MrWidgetAuthor, {
      propsData: {
        author: mockAuthor,
      },
    });
  });

  afterEach(() => {
    wrapper.destroy();
    window.gl = oldWindowGl;
  });

  it('renders link with the author web url', () => {
    expect(wrapper.attributes('href')).toBe('http://localhost:3000/root');
  });

  it('renders image with avatar url', () => {
    expect(wrapper.find('img').attributes('src')).toBe(
      'http://www.gravatar.com/avatar/e64c7d89f26bd1972efa854d13d7dd61?s=80&d=identicon',
    );
  });

  it('renders image with default avatar url when no avatarUrl is present in author', async () => {
    wrapper.setProps({
      author: {
        ...mockAuthor,
        avatarUrl: null,
      },
    });

    await nextTick();

    expect(wrapper.find('img').attributes('src')).toBe('no_avatar.png');
  });

  it('renders author name', () => {
    expect(wrapper.find('span').text()).toBe('Administrator');
  });
});