blob: 3fd26716f4a07d9d022dd08900e25ecb1c76d36f [file] [log] [blame]
Copybara854996b2021-09-07 19:36:02 +00001// 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
5import {assert} from 'chai';
6import sinon from 'sinon';
7import {ChopsFilterChips} from './chops-filter-chips.js';
8
9/** @type {ChopsFilterChips} */
10let element;
11
12describe('chops-filter-chips', () => {
13 beforeEach(() => {
14 // @ts-ignore
15 element = document.createElement('chops-filter-chips');
16 document.body.appendChild(element);
17 });
18
19 afterEach(() => {
20 document.body.removeChild(element);
21 });
22
23 it('initializes', () => {
24 assert.instanceOf(element, ChopsFilterChips);
25 });
26
27 it('renders', async () => {
28 element.options = ['one', 'two'];
29 element.selected = {two: true};
30 await element.updateComplete;
31
32 const firstChip = element.shadowRoot.firstElementChild;
33 assert.deepEqual(firstChip.className, '');
34 assert.deepEqual(firstChip.thumbnail, '');
35
36 const lastChip = element.shadowRoot.lastElementChild;
37 assert.deepEqual(lastChip.className, 'selected');
38 assert.deepEqual(lastChip.thumbnail, 'check');
39 });
40
41 it('click', async () => {
42 const onChangeStub = sinon.stub();
43
44 element.options = ['one'];
45 await element.updateComplete;
46
47 element.addEventListener('change', onChangeStub);
48 element.shadowRoot.firstElementChild.click();
49
50 assert.isTrue(element.selected.one);
51 sinon.assert.calledOnce(onChangeStub);
52
53 element.shadowRoot.firstElementChild.click();
54
55 assert.isFalse(element.selected.one);
56 sinon.assert.calledTwice(onChangeStub);
57 });
58});