summaryrefslogtreecommitdiff
path: root/spec/javascripts/vue_shared/components/issue/issue_assignees_spec.js
blob: 9eac75fac967787d80b7561448a1f46fa6062859 (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
import Vue from 'vue';

import IssueAssignees from '~/vue_shared/components/issue/issue_assignees.vue';

import mountComponent from 'spec/helpers/vue_mount_component_helper';
import { mockAssigneesList } from 'spec/boards/mock_data';

const createComponent = (assignees = mockAssigneesList, cssClass = '') => {
  const Component = Vue.extend(IssueAssignees);

  return mountComponent(Component, {
    assignees,
    cssClass,
  });
};

describe('IssueAssigneesComponent', () => {
  let vm;

  beforeEach(() => {
    vm = createComponent();
  });

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

  describe('data', () => {
    it('returns default data props', () => {
      expect(vm.maxVisibleAssignees).toBe(2);
      expect(vm.maxAssigneeAvatars).toBe(3);
      expect(vm.maxAssignees).toBe(99);
    });
  });

  describe('computed', () => {
    describe('countOverLimit', () => {
      it('should return difference between assignees count and maxVisibleAssignees', () => {
        expect(vm.countOverLimit).toBe(mockAssigneesList.length - vm.maxVisibleAssignees);
      });
    });

    describe('assigneesToShow', () => {
      it('should return assignees containing only 2 items when count more than maxAssigneeAvatars', () => {
        expect(vm.assigneesToShow.length).toBe(2);
      });

      it('should return all assignees as it is when count less than maxAssigneeAvatars', () => {
        vm.assignees = mockAssigneesList.slice(0, 3); // Set 3 Assignees

        expect(vm.assigneesToShow.length).toBe(3);
      });
    });

    describe('assigneesCounterTooltip', () => {
      it('should return string containing count of remaining assignees when count more than maxAssigneeAvatars', () => {
        expect(vm.assigneesCounterTooltip).toBe('3 more assignees');
      });
    });

    describe('shouldRenderAssigneesCounter', () => {
      it('should return `false` when assignees count less than maxAssigneeAvatars', () => {
        vm.assignees = mockAssigneesList.slice(0, 3); // Set 3 Assignees

        expect(vm.shouldRenderAssigneesCounter).toBe(false);
      });

      it('should return `true` when assignees count more than maxAssigneeAvatars', () => {
        expect(vm.shouldRenderAssigneesCounter).toBe(true);
      });
    });

    describe('assigneeCounterLabel', () => {
      it('should return count of additional assignees total assignees count more than maxAssigneeAvatars', () => {
        expect(vm.assigneeCounterLabel).toBe('+3');
      });
    });
  });

  describe('methods', () => {
    describe('avatarUrlTitle', () => {
      it('returns string containing alt text for assignee avatar', () => {
        expect(vm.avatarUrlTitle(mockAssigneesList[0])).toBe('Avatar for Terrell Graham');
      });
    });
  });

  describe('template', () => {
    it('renders component root element with class `issue-assignees`', () => {
      expect(vm.$el.classList.contains('issue-assignees')).toBe(true);
    });

    it('renders assignee avatars', () => {
      expect(vm.$el.querySelectorAll('.user-avatar-link').length).toBe(2);
    });

    it('renders assignee tooltips', () => {
      const tooltipText = vm.$el
        .querySelectorAll('.user-avatar-link')[0]
        .querySelector('.js-assignee-tooltip').innerText;

      expect(tooltipText).toContain('Assignee');
      expect(tooltipText).toContain('Terrell Graham');
      expect(tooltipText).toContain('@monserrate.gleichner');
    });

    it('renders additional assignees count', () => {
      const avatarCounterEl = vm.$el.querySelector('.avatar-counter');

      expect(avatarCounterEl.innerText.trim()).toBe('+3');
      expect(avatarCounterEl.getAttribute('data-original-title')).toBe('3 more assignees');
    });
  });
});