blob: 1bd3ae91e374f59632372f4273079c99c338996b [file] [log] [blame]
Copybara854996b2021-09-07 19:36:02 +00001// Copyright 2019 The Chromium Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5import {assert} from 'chai';
6import {MrIssueLink} from './mr-issue-link.js';
7
8let element;
9
10describe('mr-issue-link', () => {
11 beforeEach(() => {
12 element = document.createElement('mr-issue-link');
13 document.body.appendChild(element);
14 });
15
16 afterEach(() => {
17 document.body.removeChild(element);
18 });
19
20 it('initializes', () => {
21 assert.instanceOf(element, MrIssueLink);
22 });
23
24 it('strikethrough when closed', async () => {
25 await element.updateComplete;
26 const link = element.shadowRoot.querySelector('#bugLink');
27 assert.isFalse(
28 window.getComputedStyle(link).getPropertyValue(
29 'text-decoration').includes('line-through'));
30 element.issue = {statusRef: {meansOpen: false}};
31
32 await element.updateComplete;
33
34 assert.isTrue(
35 window.getComputedStyle(link).getPropertyValue(
36 'text-decoration').includes('line-through'));
37 });
38
39 it('shortens link text when short is true', () => {
40 element.issue = {
41 projectName: 'test',
42 localId: 13,
43 };
44
45 assert.equal(element._linkText, 'Issue test:13');
46
47 element.short = true;
48
49 assert.equal(element._linkText, 'test:13');
50 });
51
52 it('shows projectName only when different from global', async () => {
53 element.issue = {
54 projectName: 'test',
55 localId: 11,
56 };
57 await element.updateComplete;
58
59 const link = element.shadowRoot.querySelector('#bugLink');
60 assert.equal(link.textContent.trim(), 'Issue test:11');
61
62 element.projectName = 'test';
63 await element.updateComplete;
64
65 assert.equal(link.textContent.trim(), 'Issue 11');
66
67 element.projectName = 'other';
68 await element.updateComplete;
69
70 await element.updateComplete;
71
72 assert.equal(link.textContent.trim(), 'Issue test:11');
73 });
74
75 it('shows links for issues', async () => {
76 element.issue = {
77 projectName: 'test',
78 localId: 11,
79 };
80
81 await element.updateComplete;
82
83 const link = element.shadowRoot.querySelector('#bugLink');
84 assert.include(link.href.trim(), '/p/test/issues/detail?id=11');
85 assert.equal(link.title, '');
86 });
87
88 it('shows links for federated issues', async () => {
89 element.issue = {
90 extIdentifier: 'b/5678',
91 };
92
93 await element.updateComplete;
94
95 const link = element.shadowRoot.querySelector('#bugLink');
96 assert.include(link.href.trim(), 'https://issuetracker.google.com/issues/5678');
97 assert.equal(link.title, '');
98 });
99
100 it('displays an icon for federated references', async () => {
101 element.issue = {
102 extIdentifier: 'b/5678',
103 };
104
105 await element.updateComplete;
106
107 const dropdown = element.shadowRoot.querySelector('mr-dropdown');
108 assert.isNotNull(dropdown);
109 const anchor = dropdown.shadowRoot.querySelector('.anchor');
110 assert.isNotNull(anchor);
111 assert.include(anchor.innerText, 'info_outline');
112 });
113
114 it('displays an info popup for federated references', async () => {
115 element.issue = {
116 extIdentifier: 'b/5678',
117 };
118
119 await element.updateComplete;
120
121 const dropdown = element.shadowRoot.querySelector('mr-dropdown');
122 const anchor = dropdown.shadowRoot.querySelector('.anchor');
123 anchor.click();
124
125 await dropdown.updateComplete;
126
127 assert.isTrue(dropdown.opened);
128
129 const cue = dropdown.querySelector('mr-fed-ref-cue');
130 assert.isNotNull(cue);
131 const message = cue.shadowRoot.querySelector('#message');
132 assert.isNotNull(message);
133 assert.include(message.innerText, 'Buganizer issue tracker');
134 });
135
136 it('shows title when summary is defined', async () => {
137 element.issue = {
138 projectName: 'test',
139 localId: 11,
140 summary: 'Summary',
141 };
142
143 await element.updateComplete;
144 const link = element.shadowRoot.querySelector('#bugLink');
145 assert.equal(link.title, 'Summary');
146 });
147});