blob: 911c1a0e3b972a3ce5b2777cac63b49aa509c49c [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 {MrIssueHotlistsDialog} from './mr-issue-hotlists-dialog.js';
7
8let element;
9const EXAMPLE_USER_HOTLISTS = [
10 {name: 'Hotlist-1'},
11 {name: 'Hotlist-2'},
12 {name: 'ac-apple-1'},
13 {name: 'ac-frita-1'},
14];
15
16describe('mr-issue-hotlists-dialog', () => {
17 beforeEach(async () => {
18 element = document.createElement('mr-issue-hotlists-dialog');
19 document.body.appendChild(element);
20
21 await element.updateComplete;
22 });
23
24 afterEach(() => {
25 document.body.removeChild(element);
26 });
27
28 it('initializes', () => {
29 assert.instanceOf(element, MrIssueHotlistsDialog);
30 assert.include(element.shadowRoot.innerHTML, 'Dialog elements below');
31 });
32
33 it('filters hotlists', async () => {
34 element.userHotlists = EXAMPLE_USER_HOTLISTS;
35 element.open();
36 await element.updateComplete;
37
38 const initialHotlists = element.shadowRoot.querySelectorAll('.hotlist');
39 assert.equal(initialHotlists.length, 4);
40 const filterInput = element.shadowRoot.querySelector('#filter');
41 filterInput.value = 'list';
42 element.filterHotlists();
43 await element.updateComplete;
44 let visibleHotlists =
45 element.shadowRoot.querySelectorAll('.hotlist');
46 assert.equal(visibleHotlists.length, 2);
47
48 filterInput.value = '2';
49 element.filterHotlists();
50 await element.updateComplete;
51 visibleHotlists =
52 element.shadowRoot.querySelectorAll('.hotlist');
53 assert.equal(visibleHotlists.length, 1);
54 });
55
56 it('resets filter on open', async () => {
57 element.userHotlists = EXAMPLE_USER_HOTLISTS;
58 element.open();
59 await element.updateComplete;
60
61 const filterInput = element.shadowRoot.querySelector('#filter');
62 filterInput.value = 'ac';
63 element.filterHotlists();
64 await element.updateComplete;
65 let visibleHotlists =
66 element.shadowRoot.querySelectorAll('.hotlist');
67 assert.equal(visibleHotlists.length, 2);
68
69 element.close();
70 element.open();
71 await element.updateComplete;
72
73 assert.equal(filterInput.value, '');
74 visibleHotlists =
75 element.shadowRoot.querySelectorAll('.hotlist');
76 assert.equal(visibleHotlists.length, 4);
77 });
78});