summaryrefslogtreecommitdiff
path: root/spec/javascripts/vue_mr_widget/components/mr_widget_author_spec.js
blob: a750bc78f365f2a09a7c2bfe94df169c8641946f (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
import Vue from 'vue';
import authorComponent from '~/vue_merge_request_widget/components/mr_widget_author';

const author = {
  webUrl: 'http://foo.bar',
  avatarUrl: 'http://gravatar.com/foo',
  name: 'fatihacet',
};
const createComponent = () => {
  const Component = Vue.extend(authorComponent);

  return new Component({
    el: document.createElement('div'),
    propsData: { author },
  });
};

describe('MRWidgetAuthor', () => {
  describe('props', () => {
    it('should have props', () => {
      const authorProp = authorComponent.props.author;

      expect(authorProp).toBeDefined();
      expect(authorProp.type instanceof Object).toBeTruthy();
      expect(authorProp.required).toBeTruthy();
    });
  });

  describe('template', () => {
    it('should have correct elements', () => {
      const el = createComponent().$el;

      expect(el.tagName).toEqual('A');
      expect(el.getAttribute('href')).toEqual(author.webUrl);
      expect(el.querySelector('img').getAttribute('src')).toEqual(author.avatarUrl);
      expect(el.querySelector('.author').innerText.trim()).toEqual(author.name);
    });
  });
});