summaryrefslogtreecommitdiff
path: root/spec/javascripts/vue_shared/components/user_avatar_image_spec.js
blob: 8daa761027454fe4fa4ade9cddcb067c1427d972 (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
import Vue from 'vue';
import UserAvatarImage from '~/vue_shared/components/user_avatar/user_avatar_image.vue';

const UserAvatarImageComponent = Vue.extend(UserAvatarImage);

describe('User Avatar Image Component', function () {
  describe('Initialization', function () {
    beforeEach(function () {
      this.propsData = {
        size: 99,
        imgSrc: 'myavatarurl.com',
        imgAlt: 'mydisplayname',
        cssClasses: 'myextraavatarclass',
        tooltipText: 'tooltip text',
        tooltipPlacement: 'bottom',
      };

      this.userAvatarImage = new UserAvatarImageComponent({
        propsData: this.propsData,
      }).$mount();
    });

    it('should return a defined Vue component', function () {
      expect(this.userAvatarImage).toBeDefined();
    });

    it('should have <img> as a child element', function () {
      expect(this.userAvatarImage.$el.tagName).toBe('IMG');
    });

    it('should properly compute tooltipContainer', function () {
      expect(this.userAvatarImage.tooltipContainer).toBe('body');
    });

    it('should properly render tooltipContainer', function () {
      expect(this.userAvatarImage.$el.getAttribute('data-container')).toBe('body');
    });

    it('should properly compute avatarSizeClass', function () {
      expect(this.userAvatarImage.avatarSizeClass).toBe('s99');
    });

    it('should properly render img css', function () {
      const classList = this.userAvatarImage.$el.classList;
      const containsAvatar = classList.contains('avatar');
      const containsSizeClass = classList.contains('s99');
      const containsCustomClass = classList.contains('myextraavatarclass');

      expect(containsAvatar).toBe(true);
      expect(containsSizeClass).toBe(true);
      expect(containsCustomClass).toBe(true);
    });
  });
});