blob: e3fe9d23beeffe457bf40021336314be3533fbc2 [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 {MrEditDescription} from './mr-edit-description.js';
7
8let element;
9
10describe('mr-edit-description', () => {
11 beforeEach(() => {
12 element = document.createElement('mr-edit-description');
13
14 document.body.appendChild(element);
15 element.commentsByApproval = new Map([
16 ['', [
17 {
18 descriptionNum: 1,
19 content: 'first description',
20 },
21 {
22 content: 'first comment',
23 },
24 {
25 descriptionNum: 2,
26 content: '<b>last</b> description',
27 },
28 {
29 content: 'second comment',
30 },
31 {
32 content: 'third comment',
33 },
34 ]], ['foo', [
35 {
36 descriptionNum: 1,
37 content: 'first foo survey',
38 approvalRef: {
39 fieldName: 'foo',
40 },
41 },
42 {
43 descriptionNum: 2,
44 content: 'last foo survey',
45 approvalRef: {
46 fieldName: 'foo',
47 },
48 },
49 ]], ['bar', [
50 {
51 descriptionNum: 1,
52 content: 'bar survey',
53 approvalRef: {
54 fieldName: 'bar',
55 },
56 },
57 ]],
58 ]);
59 });
60
61 afterEach(() => {
62 document.body.removeChild(element);
63 });
64
65 it('initializes', () => {
66 assert.instanceOf(element, MrEditDescription);
67 });
68
69 it('selects last issue description', async () => {
70 element.fieldName = '';
71 element.reset();
72
73 await element.updateComplete;
74
75 assert.equal(element._editedDescription, 'last description');
76 assert.equal(element._title, 'Description');
77 });
78
79 it('selects last survey', async () => {
80 element.fieldName = 'foo';
81 element.reset();
82
83 await element.updateComplete;
84
85 assert.equal(element._editedDescription, 'last foo survey');
86 assert.equal(element._title, 'foo Survey');
87 });
88
89 it('toggle sendEmail', async () => {
90 element.reset();
91 await element.updateComplete;
92
93 const sendEmail = element.shadowRoot.querySelector('#sendEmail');
94
95 await sendEmail.updateComplete;
96
97 sendEmail.click();
98 await element.updateComplete;
99 assert.isFalse(element._sendEmail);
100
101 sendEmail.click();
102 await element.updateComplete;
103 assert.isTrue(element._sendEmail);
104
105 sendEmail.click();
106 await element.updateComplete;
107 assert.isFalse(element._sendEmail);
108 });
109
110 it('renders valid markdown description with preview class', async () => {
111 element.projectName = 'monkeyrail';
112 element._prefs = new Map([['render_markdown', true]]);
113 element.reset();
114
115 element._editedDescription = '# h1';
116
117 await element.updateComplete;
118
119 const previewMarkdown = element.shadowRoot.querySelector('.markdown-preview');
120 assert.isNotNull(previewMarkdown);
121
122 const headerText = previewMarkdown.querySelector('h1').textContent;
123 assert.equal(headerText, 'h1');
124 });
125
126 it('does not show preview when markdown is disabled', async () => {
127 element.projectName = 'disabled_project';
128 element._prefs = new Map([['render_markdown', true]]);
129 element.reset();
130
131 await element.updateComplete;
132
133 const previewMarkdown = element.shadowRoot.querySelector('.markdown-preview');
134 assert.isNull(previewMarkdown);
135 });
136});