summaryrefslogtreecommitdiff
path: root/spec/javascripts/boards/issue_card_header_spec.js
blob: 7771809555075ea660195ac82f4529ceb963f184 (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
import Vue from 'vue';
import headerComponent from '~/boards/components/issue_card_header';

const propData = {
  confidential: true,
  title: 'this is a title',
  issueId: 23,
  assignee: {
    username: 'batman',
    name: 'Bruce Wayne',
    avatar: 'https://batman.gravatar',
  },
  issueLinkBase: 'linkBase',
  rootPath: 'rootPath',
};

const createComponent = (propsData) => {
  const Component = Vue.extend(headerComponent);

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

describe('IssueCardHeader', () => {
  describe('props', () => {
    const props = headerComponent.props;

    it('should have confidential prop', () => {
      const { confidential } = props;
      const ConfidentialClass = confidential.type;

      expect(confidential).toBeDefined();
      expect(new ConfidentialClass() instanceof Boolean).toBeTruthy();
      expect(confidential.required).toBeTruthy();
    });

    it('should have title prop', () => {
      const { title } = props;
      const TitleClass = title.type;

      expect(title).toBeDefined();
      expect(new TitleClass() instanceof String).toBeTruthy();
      expect(title.required).toBeTruthy();
    });

    it('should have issueId prop', () => {
      const { issueId } = props;
      const IssueIdClass = issueId.type;

      expect(issueId).toBeDefined();
      expect(new IssueIdClass() instanceof Number).toBeTruthy();
      expect(issueId.required).toBeTruthy();
    });

    it('should have assignee prop', () => {
      const { assignee } = props;

      expect(assignee).toBeDefined();
      expect(assignee instanceof Object).toBeTruthy();
      expect(assignee.required).toBeTruthy();
    });

    it('should have issueLinkBase prop', () => {
      const { issueLinkBase } = props;
      const IssueLinkBaseClass = issueLinkBase.type;

      expect(issueLinkBase).toBeDefined();
      expect(new IssueLinkBaseClass() instanceof String).toBeTruthy();
      expect(issueLinkBase.required).toBeTruthy();
    });

    it('should have rootPath prop', () => {
      const { rootPath } = props;
      const RootPathClass = rootPath.type;

      expect(rootPath).toBeDefined();
      expect(new RootPathClass() instanceof String).toBeTruthy();
      expect(rootPath.required).toBeTruthy();
    });
  });

  describe('computed', () => {
    describe('hasAssignee', () => {
      it('should return whether there is an assignee', () => {
        const data = Object.assign({}, propData);

        let vm = createComponent(data);
        expect(vm.hasAssignee).toEqual(true);

        data.assignee = {};
        vm = createComponent(data);
        expect(vm.hasAssignee).toEqual(false);
      });
    });
  });

  describe('template', () => {
    it('should have correct elements', () => {
      const el = createComponent(propData).$el;
      expect(el.tagName).toEqual('DIV');
      expect(el.classList.contains('card-header')).toEqual(true);

      const confidentialIcon = el.querySelector('.confidential-icon');
      expect(confidentialIcon.tagName).toEqual('I');
      expect(confidentialIcon.classList.contains('fa')).toEqual(true);
      expect(confidentialIcon.classList.contains('fa-eye-slash')).toEqual(true);

      const cardTitle = el.querySelector('.card-title');
      expect(cardTitle.tagName).toEqual('H4');

      const cardTitleLink = cardTitle.querySelector('a');
      expect(cardTitleLink.getAttribute('href')).toEqual(`${propData.issueLinkBase}/${propData.issueId}`);
      expect(cardTitleLink.getAttribute('title')).toEqual(propData.title);
      expect(cardTitleLink.innerText).toEqual(propData.title);

      const cardNumber = cardTitle.querySelector('.card-number');
      expect(cardNumber.tagName).toEqual('SPAN');
      expect(cardNumber.innerText).toEqual(`#${propData.issueId}`);

      const cardAssignee = el.querySelector('.card-assignee');
      expect(cardAssignee.tagName).toEqual('A');
      expect(cardAssignee.getAttribute('href')).toEqual(`${propData.rootPath}${propData.assignee.username}`);
      expect(cardAssignee.getAttribute('title')).toEqual(`Assigned to ${propData.assignee.name}`);

      const cardAssigneeImage = cardAssignee.querySelector('img');
      expect(cardAssigneeImage.getAttribute('src')).toEqual(propData.assignee.avatar);
      expect(cardAssigneeImage.getAttribute('alt')).toEqual(`Avatar for ${propData.assignee.name}`);
    });

    it('should not display confidential icon if confidential is false', () => {
      const data = Object.assign({}, propData);
      data.confidential = false;
      const el = createComponent(data).$el;

      expect(el.querySelector('.confidential-icon')).toEqual(null);
    });

    it('should not render assignee if there is no assignee', () => {
      const data = Object.assign({}, propData);
      data.assignee = {};
      const el = createComponent(data).$el;

      expect(el.querySelector('.card-assignee')).toEqual(null);
    });
  });
});