blob: ef4471a79f6a813a5714c53fe01c9a46f2c31208 [file] [log] [blame]
Adrià Vilanova Martínezf19ea432024-01-23 20:20:52 +01001// Copyright 2020 The Chromium Authors
Copybara854996b2021-09-07 19:36:02 +00002// 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 sinon from 'sinon';
7
8import {MrButtonBar} from './mr-button-bar.js';
9
10/** @type {MrButtonBar} */
11let element;
12
13describe('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});