blob: 843000be91af567fae841f2385e64aeaa63cf8dd [file] [log] [blame]
Copybara854996b2021-09-07 19:36:02 +00001// 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
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});