blob: c3280571fd3bcd0c0524cd2ce9a37646ff6be262 [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 {MrIssueMetadata} from './mr-issue-metadata.js';
7
8let element;
9
10describe('mr-issue-metadata', () => {
11 beforeEach(() => {
12 element = document.createElement('mr-issue-metadata');
13 document.body.appendChild(element);
14 });
15
16 afterEach(() => {
17 document.body.removeChild(element);
18 });
19
20 it('initializes', () => {
21 assert.instanceOf(element, MrIssueMetadata);
22 });
23
24 it('labels render', async () => {
25 element.issue = {
26 labelRefs: [
27 {label: 'test'},
28 {label: 'hello-world', isDerived: true},
29 ],
30 };
31
32 element.labelDefMap = new Map([
33 ['test', {label: 'test', docstring: 'this is a docstring'}],
34 ]);
35
36 await element.updateComplete;
37
38 const labels = element.shadowRoot.querySelectorAll('.label');
39
40 assert.equal(labels.length, 2);
41 assert.equal(labels[0].textContent.trim(), 'test');
42 assert.equal(labels[0].getAttribute('title'), 'test = this is a docstring');
43 assert.isUndefined(labels[0].dataset.derived);
44
45 assert.equal(labels[1].textContent.trim(), 'hello-world');
46 assert.equal(labels[1].getAttribute('title'), 'Derived: hello-world');
47 assert.isDefined(labels[1].dataset.derived);
48 });
49
50 it('update hotlist button is shown to users', async () => {
51 element.user = {userId: 1234};
52 await element.updateComplete;
53 assert.isNotNull(element.shadowRoot.querySelector('#user-hotlists'));
54 });
55
56 it('update hotlist button is not shown to anon', async () => {
57 await element.updateComplete;
58 assert.isNull(element.shadowRoot.querySelector('#user-hotlists'));
59 });
60});