Copybara | 854996b | 2021-09-07 19:36:02 +0000 | [diff] [blame] | 1 | // 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 | |
| 5 | import {assert} from 'chai'; |
| 6 | import {MrCommentContent} from './mr-comment-content.js'; |
| 7 | |
| 8 | |
| 9 | let element; |
| 10 | |
| 11 | describe('mr-comment-content', () => { |
| 12 | beforeEach(() => { |
| 13 | element = document.createElement('mr-comment-content'); |
| 14 | document.body.appendChild(element); |
| 15 | |
| 16 | document.body.style.setProperty('--mr-toggled-font-family', 'Some-font'); |
| 17 | }); |
| 18 | |
| 19 | afterEach(() => { |
| 20 | document.body.removeChild(element); |
| 21 | |
| 22 | document.body.style.removeProperty('--mr-toggled-font-family'); |
| 23 | }); |
| 24 | |
| 25 | it('initializes', () => { |
| 26 | assert.instanceOf(element, MrCommentContent); |
| 27 | }); |
| 28 | |
| 29 | it('changes rendered font based on --mr-toggled-font-family', async () => { |
| 30 | element.content = 'A comment'; |
| 31 | |
| 32 | await element.updateComplete; |
| 33 | |
| 34 | const fontFamily = window.getComputedStyle(element).getPropertyValue( |
| 35 | 'font-family'); |
| 36 | |
| 37 | assert.equal(fontFamily, 'Some-font'); |
| 38 | }); |
| 39 | |
| 40 | it('does not render spurious spaces', async () => { |
| 41 | element.content = |
| 42 | 'Some text before a go/link and more text before <b>some bold text</b>.'; |
| 43 | |
| 44 | await element.updateComplete; |
| 45 | |
| 46 | const textContents = Array.from(element.shadowRoot.children).map( |
| 47 | (child) => child.textContent); |
| 48 | |
| 49 | assert.deepEqual(textContents, [ |
| 50 | 'Some text before a', |
| 51 | ' ', |
| 52 | 'go/link', |
| 53 | ' and more text before ', |
| 54 | 'some bold text', |
| 55 | '.', |
| 56 | ]); |
| 57 | |
| 58 | assert.deepEqual( |
| 59 | element.shadowRoot.textContent, |
| 60 | 'Some text before a go/link and more text before some bold text.'); |
| 61 | }); |
| 62 | |
| 63 | it('does render markdown', async () => { |
| 64 | element.prefs = new Map([['render_markdown', true]]); |
| 65 | element.content = '### this is a header'; |
| 66 | element.projectName = 'monkeyrail'; |
| 67 | |
| 68 | await element.updateComplete; |
| 69 | |
| 70 | const headerText = element.shadowRoot.querySelector('h3').textContent; |
| 71 | assert.equal(headerText, 'this is a header'); |
| 72 | }); |
| 73 | |
| 74 | it('does not render markdown when prefs are set to false', async () => { |
| 75 | element.prefs = new Map([['render_markdown', false]]); |
| 76 | element.projectName = 'monkeyrail'; |
| 77 | element.content = '### this is a header'; |
| 78 | |
| 79 | await element.updateComplete; |
| 80 | |
| 81 | const commentText = element.shadowRoot.textContent; |
| 82 | assert.equal(commentText, '### this is a header'); |
| 83 | }); |
| 84 | }); |