Adrià Vilanova MartÃnez | f19ea43 | 2024-01-23 20:20:52 +0100 | [diff] [blame] | 1 | // Copyright 2019 The Chromium Authors |
Copybara | 854996b | 2021-09-07 19:36:02 +0000 | [diff] [blame] | 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 | import {ChopsChip} from './chops-chip.js'; |
| 8 | |
| 9 | let element; |
| 10 | |
| 11 | describe('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 | }); |