Copybara | 854996b | 2021-09-07 19:36:02 +0000 | [diff] [blame^] | 1 | // Copyright 2020 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 sinon from 'sinon'; |
| 7 | |
| 8 | import {MrButtonBar} from './mr-button-bar.js'; |
| 9 | |
| 10 | /** @type {MrButtonBar} */ |
| 11 | let element; |
| 12 | |
| 13 | describe('mr-button-bar', () => { |
| 14 | beforeEach(() => { |
| 15 | // @ts-ignore |
| 16 | element = document.createElement('mr-button-bar'); |
| 17 | document.body.appendChild(element); |
| 18 | }); |
| 19 | |
| 20 | afterEach(() => { |
| 21 | document.body.removeChild(element); |
| 22 | }); |
| 23 | |
| 24 | it('initializes', () => { |
| 25 | assert.instanceOf(element, MrButtonBar); |
| 26 | }); |
| 27 | |
| 28 | it('renders button items', async () => { |
| 29 | const handler = sinon.stub(); |
| 30 | |
| 31 | element.items = [{icon: 'emoji_nature', text: 'Pollinate', handler}]; |
| 32 | await element.updateComplete; |
| 33 | |
| 34 | const button = element.shadowRoot.querySelector('button'); |
| 35 | button.click(); |
| 36 | |
| 37 | assert.include(button.innerHTML, 'emoji_nature'); |
| 38 | assert.include(button.innerHTML, 'Pollinate'); |
| 39 | sinon.assert.calledOnce(handler); |
| 40 | }); |
| 41 | |
| 42 | it('renders dropdown items', async () => { |
| 43 | const items = [{icon: 'emoji_nature', text: 'Pollinate'}]; |
| 44 | element.items = [{icon: 'more_vert', text: 'More actions...', items}]; |
| 45 | await element.updateComplete; |
| 46 | |
| 47 | /** @type {MrDropdown} */ |
| 48 | const dropdown = element.shadowRoot.querySelector('mr-dropdown'); |
| 49 | assert.strictEqual(dropdown.icon, 'more_vert'); |
| 50 | assert.strictEqual(dropdown.label, 'More actions...'); |
| 51 | assert.strictEqual(dropdown.items, items); |
| 52 | }); |
| 53 | }); |