Adrià Vilanova Martínez | f19ea43 | 2024-01-23 20:20:52 +0100 | [diff] [blame] | 1 | // Copyright 2019 The Chromium Authors |
Copybara | 854996b | 2021-09-07 19:36:02 +0000 | [diff] [blame] | 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
| 5 | import {assert} from 'chai'; |
| 6 | import {MrIssueLink} from './mr-issue-link.js'; |
Adrià Vilanova Martínez | f19ea43 | 2024-01-23 20:20:52 +0100 | [diff] [blame] | 7 | import sinon from 'sinon'; |
Copybara | 854996b | 2021-09-07 19:36:02 +0000 | [diff] [blame] | 8 | |
| 9 | let element; |
| 10 | |
| 11 | describe('mr-issue-link', () => { |
| 12 | beforeEach(() => { |
Adrià Vilanova Martínez | f19ea43 | 2024-01-23 20:20:52 +0100 | [diff] [blame] | 13 | window.ga = sinon.stub(); |
Copybara | 854996b | 2021-09-07 19:36:02 +0000 | [diff] [blame] | 14 | element = document.createElement('mr-issue-link'); |
| 15 | document.body.appendChild(element); |
| 16 | }); |
| 17 | |
| 18 | afterEach(() => { |
| 19 | document.body.removeChild(element); |
| 20 | }); |
| 21 | |
| 22 | it('initializes', () => { |
| 23 | assert.instanceOf(element, MrIssueLink); |
| 24 | }); |
| 25 | |
| 26 | it('strikethrough when closed', async () => { |
| 27 | await element.updateComplete; |
| 28 | const link = element.shadowRoot.querySelector('#bugLink'); |
| 29 | assert.isFalse( |
| 30 | window.getComputedStyle(link).getPropertyValue( |
| 31 | 'text-decoration').includes('line-through')); |
| 32 | element.issue = {statusRef: {meansOpen: false}}; |
| 33 | |
| 34 | await element.updateComplete; |
| 35 | |
| 36 | assert.isTrue( |
| 37 | window.getComputedStyle(link).getPropertyValue( |
| 38 | 'text-decoration').includes('line-through')); |
| 39 | }); |
| 40 | |
| 41 | it('shortens link text when short is true', () => { |
| 42 | element.issue = { |
| 43 | projectName: 'test', |
| 44 | localId: 13, |
| 45 | }; |
| 46 | |
| 47 | assert.equal(element._linkText, 'Issue test:13'); |
| 48 | |
| 49 | element.short = true; |
| 50 | |
| 51 | assert.equal(element._linkText, 'test:13'); |
| 52 | }); |
| 53 | |
| 54 | it('shows projectName only when different from global', async () => { |
| 55 | element.issue = { |
| 56 | projectName: 'test', |
| 57 | localId: 11, |
| 58 | }; |
| 59 | await element.updateComplete; |
| 60 | |
| 61 | const link = element.shadowRoot.querySelector('#bugLink'); |
| 62 | assert.equal(link.textContent.trim(), 'Issue test:11'); |
| 63 | |
| 64 | element.projectName = 'test'; |
| 65 | await element.updateComplete; |
| 66 | |
| 67 | assert.equal(link.textContent.trim(), 'Issue 11'); |
| 68 | |
| 69 | element.projectName = 'other'; |
| 70 | await element.updateComplete; |
| 71 | |
| 72 | await element.updateComplete; |
| 73 | |
| 74 | assert.equal(link.textContent.trim(), 'Issue test:11'); |
| 75 | }); |
| 76 | |
| 77 | it('shows links for issues', async () => { |
| 78 | element.issue = { |
| 79 | projectName: 'test', |
| 80 | localId: 11, |
| 81 | }; |
| 82 | |
| 83 | await element.updateComplete; |
| 84 | |
| 85 | const link = element.shadowRoot.querySelector('#bugLink'); |
| 86 | assert.include(link.href.trim(), '/p/test/issues/detail?id=11'); |
| 87 | assert.equal(link.title, ''); |
| 88 | }); |
| 89 | |
| 90 | it('shows links for federated issues', async () => { |
| 91 | element.issue = { |
| 92 | extIdentifier: 'b/5678', |
| 93 | }; |
| 94 | |
| 95 | await element.updateComplete; |
| 96 | |
| 97 | const link = element.shadowRoot.querySelector('#bugLink'); |
| 98 | assert.include(link.href.trim(), 'https://issuetracker.google.com/issues/5678'); |
| 99 | assert.equal(link.title, ''); |
| 100 | }); |
| 101 | |
Copybara | 854996b | 2021-09-07 19:36:02 +0000 | [diff] [blame] | 102 | it('shows title when summary is defined', async () => { |
| 103 | element.issue = { |
| 104 | projectName: 'test', |
| 105 | localId: 11, |
| 106 | summary: 'Summary', |
| 107 | }; |
| 108 | |
| 109 | await element.updateComplete; |
| 110 | const link = element.shadowRoot.querySelector('#bugLink'); |
| 111 | assert.equal(link.title, 'Summary'); |
| 112 | }); |
| 113 | }); |