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 {MrDescription} from './mr-description.js'; |
| 7 | |
| 8 | |
| 9 | let element; |
| 10 | |
| 11 | describe('mr-description', () => { |
| 12 | beforeEach(() => { |
| 13 | element = document.createElement('mr-description'); |
| 14 | document.body.appendChild(element); |
| 15 | }); |
| 16 | |
| 17 | afterEach(() => { |
| 18 | document.body.removeChild(element); |
| 19 | }); |
| 20 | |
| 21 | it('initializes', () => { |
| 22 | assert.instanceOf(element, MrDescription); |
| 23 | }); |
| 24 | |
| 25 | it('changes rendered description on select change', async () => { |
| 26 | element.descriptionList = [ |
| 27 | {content: 'description one', commenter: {displayName: 'name'}}, |
| 28 | {content: 'description two', commenter: {displayName: 'name'}}, |
| 29 | ]; |
| 30 | |
| 31 | await element.updateComplete; |
| 32 | await element.updateComplete; |
| 33 | |
| 34 | const commentContent = |
| 35 | element.shadowRoot.querySelector('mr-comment-content'); |
| 36 | assert.equal('description two', commentContent.content); |
| 37 | |
| 38 | element.selectedIndex = 0; |
| 39 | |
| 40 | await element.updateComplete; |
| 41 | |
| 42 | assert.equal('description one', commentContent.content); |
| 43 | }); |
| 44 | |
| 45 | it('hides selector when only one description', async () => { |
| 46 | element.descriptionList = [ |
| 47 | {content: 'Hello world', commenter: {displayName: 'name@email.com'}}, |
| 48 | {content: 'rutabaga', commenter: {displayName: 'name@email.com'}}, |
| 49 | ]; |
| 50 | |
| 51 | await element.updateComplete; |
| 52 | |
| 53 | const selectMenu = element.shadowRoot.querySelector('select'); |
| 54 | assert.isFalse(selectMenu.hidden); |
| 55 | |
| 56 | element.descriptionList = [ |
| 57 | {content: 'blehh', commenter: {displayName: 'name@email.com'}}, |
| 58 | ]; |
| 59 | |
| 60 | await element.updateComplete; |
| 61 | |
| 62 | assert.isTrue(selectMenu.hidden); |
| 63 | }); |
| 64 | |
| 65 | it('selector still renders when one description is deleted', async () => { |
| 66 | element.descriptionList = [ |
| 67 | {content: 'Hello world', commenter: {displayName: 'name@email.com'}}, |
| 68 | {isDeleted: true, commenter: {displayName: 'name@email.com'}}, |
| 69 | ]; |
| 70 | |
| 71 | await element.updateComplete; |
| 72 | |
| 73 | const selectMenu = element.shadowRoot.querySelector('select'); |
| 74 | assert.isFalse(selectMenu.hidden); |
| 75 | |
| 76 | const options = selectMenu.querySelectorAll('option'); |
| 77 | |
| 78 | assert.include(options[0].textContent, 'Description #1 by name@email.com'); |
| 79 | assert.include(options[1].textContent, 'Description #2'); |
| 80 | }); |
| 81 | }); |