summaryrefslogtreecommitdiff
path: root/spec/javascripts/vue_shared/components/user_popover/user_popover_spec.js
blob: e8b41e8eeff46989c08ead71fabd20df3069db0f (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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
import Vue from 'vue';
import userPopover from '~/vue_shared/components/user_popover/user_popover.vue';
import mountComponent from 'spec/helpers/vue_mount_component_helper';

const DEFAULT_PROPS = {
  loaded: true,
  user: {
    username: 'root',
    name: 'Administrator',
    location: 'Vienna',
    bio: null,
    organization: null,
    status: null,
  },
};

const UserPopover = Vue.extend(userPopover);

describe('User Popover Component', () => {
  const fixtureTemplate = 'merge_requests/diff_comment.html.raw';
  preloadFixtures(fixtureTemplate);

  let vm;

  beforeEach(() => {
    loadFixtures(fixtureTemplate);
  });

  afterEach(() => {
    vm.$destroy();
  });

  describe('Empty', () => {
    beforeEach(() => {
      vm = mountComponent(UserPopover, {
        target: document.querySelector('.js-user-link'),
        user: {
          name: null,
          username: null,
          location: null,
          bio: null,
          organization: null,
          status: null,
        },
      });
    });

    it('should return skeleton loaders', () => {
      expect(vm.$el.querySelectorAll('.animation-container').length).toBe(4);
    });
  });

  describe('basic data', () => {
    it('should show basic fields', () => {
      vm = mountComponent(UserPopover, {
        ...DEFAULT_PROPS,
        target: document.querySelector('.js-user-link'),
      });

      expect(vm.$el.textContent).toContain(DEFAULT_PROPS.user.name);
      expect(vm.$el.textContent).toContain(DEFAULT_PROPS.user.username);
      expect(vm.$el.textContent).toContain(DEFAULT_PROPS.user.location);
    });
  });

  describe('job data', () => {
    it('should show only bio if no organization is available', () => {
      const testProps = Object.assign({}, DEFAULT_PROPS);
      testProps.user.bio = 'Engineer';

      vm = mountComponent(UserPopover, {
        ...testProps,
        target: document.querySelector('.js-user-link'),
      });

      expect(vm.$el.textContent).toContain('Engineer');
    });

    it('should show only organization if no bio is available', () => {
      const testProps = Object.assign({}, DEFAULT_PROPS);
      testProps.user.organization = 'GitLab';

      vm = mountComponent(UserPopover, {
        ...testProps,
        target: document.querySelector('.js-user-link'),
      });

      expect(vm.$el.textContent).toContain('GitLab');
    });

    it('should display bio and organization in separate lines', () => {
      const testProps = Object.assign({}, DEFAULT_PROPS);
      testProps.user.bio = 'Engineer';
      testProps.user.organization = 'GitLab';

      vm = mountComponent(UserPopover, {
        ...DEFAULT_PROPS,
        target: document.querySelector('.js-user-link'),
      });

      expect(vm.$el.querySelector('.js-bio').textContent).toContain('Engineer');
      expect(vm.$el.querySelector('.js-organization').textContent).toContain('GitLab');
    });

    it('should not encode special characters in bio and organization', () => {
      const testProps = Object.assign({}, DEFAULT_PROPS);
      testProps.user.bio = 'Manager & Team Lead';
      testProps.user.organization = 'Me & my <funky> Company';

      vm = mountComponent(UserPopover, {
        ...DEFAULT_PROPS,
        target: document.querySelector('.js-user-link'),
      });

      expect(vm.$el.querySelector('.js-bio').textContent).toContain('Manager & Team Lead');
      expect(vm.$el.querySelector('.js-organization').textContent).toContain(
        'Me & my <funky> Company',
      );
    });
  });

  describe('status data', () => {
    it('should show only message', () => {
      const testProps = Object.assign({}, DEFAULT_PROPS);
      testProps.user.status = { message_html: 'Hello World' };

      vm = mountComponent(UserPopover, {
        ...DEFAULT_PROPS,
        target: document.querySelector('.js-user-link'),
      });

      expect(vm.$el.textContent).toContain('Hello World');
    });

    it('should show message and emoji', () => {
      const testProps = Object.assign({}, DEFAULT_PROPS);
      testProps.user.status = { emoji: 'basketball_player', message_html: 'Hello World' };

      vm = mountComponent(UserPopover, {
        ...DEFAULT_PROPS,
        target: document.querySelector('.js-user-link'),
        status: { emoji: 'basketball_player', message_html: 'Hello World' },
      });

      expect(vm.$el.textContent).toContain('Hello World');
      expect(vm.$el.innerHTML).toContain('<gl-emoji data-name="basketball_player"');
    });
  });
});