blob: ce012b40deabe7bae1b7bab8e5c3bb18ddfa732e [file] [log] [blame]
Adrià Vilanova Martínezf19ea432024-01-23 20:20:52 +01001// Copyright 2019 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';
7import {ChopsChip} from './chops-chip.js';
8
9let element;
10
11describe('chops-chip', () => {
12 beforeEach(() => {
13 element = document.createElement('chops-chip');
14 document.body.appendChild(element);
15 });
16
17 afterEach(() => {
18 document.body.removeChild(element);
19 });
20
21 it('initializes', () => {
22 assert.instanceOf(element, ChopsChip);
23 });
24
25 it('icon is visible when defined', async () => {
26 await element.updateComplete;
27 assert.isNull(element.shadowRoot.querySelector('button'));
28
29 element.buttonIcon = 'close';
30
31 await element.updateComplete;
32
33 assert.isNotNull(element.shadowRoot.querySelector('button'));
34 });
35
36 it('clicking icon fires event', async () => {
37 const onClickStub = sinon.stub();
38
39 element.buttonIcon = 'close';
40
41 await element.updateComplete;
42
43 element.addEventListener('click-button', onClickStub);
44
45 assert.isFalse(onClickStub.calledOnce);
46
47 const icon = element.shadowRoot.querySelector('button');
48 icon.click();
49
50 assert.isTrue(onClickStub.calledOnce);
51 });
52});