blob: d6d7fbf72042b731a12cfa8d4645805db00509a2 [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 sinon from 'sinon';
6import {assert} from 'chai';
7import {MrGridControls} from './mr-grid-controls.js';
8import {SERVER_LIST_ISSUES_LIMIT} from 'shared/consts/index.js';
9
10let element;
11
12describe('mr-grid-controls', () => {
13 beforeEach(() => {
14 element = document.createElement('mr-grid-controls');
15 document.body.appendChild(element);
16
17 element._page = sinon.stub();
18 });
19
20 afterEach(() => {
21 document.body.removeChild(element);
22 });
23
24 it('initializes', () => {
25 assert.instanceOf(element, MrGridControls);
26 });
27
28 it('selecting row updates y param', async () => {
29 const stub = sinon.stub(element, '_changeUrlParams');
30
31 await element.updateComplete;
32
33 const dropdownRows = element.shadowRoot.querySelector('.row-selector');
34
35 dropdownRows.selection = 'Status';
36 dropdownRows.dispatchEvent(new Event('change'));
37 sinon.assert.calledWith(stub, {y: 'Status'});
38 });
39
40 it('setting row to None deletes y param', async () => {
41 element.queryParams = {y: 'Remove', x: 'Keep'};
42 element.projectName = 'chromium';
43
44 await element.updateComplete;
45
46 const dropdownRows = element.shadowRoot.querySelector('.row-selector');
47
48 dropdownRows.selection = 'None';
49 dropdownRows.dispatchEvent(new Event('change'));
50
51 sinon.assert.calledWith(element._page,
52 '/p/chromium/issues/list?x=Keep');
53 });
54
55 it('selecting col updates x param', async () => {
56 const stub = sinon.stub(element, '_changeUrlParams');
57 await element.updateComplete;
58
59 const dropdownCols = element.shadowRoot.querySelector('.col-selector');
60
61 dropdownCols.selection = 'Blocking';
62 dropdownCols.dispatchEvent(new Event('change'));
63 sinon.assert.calledWith(stub, {x: 'Blocking'});
64 });
65
66 it('setting col to None deletes x param', async () => {
67 element.queryParams = {y: 'Keep', x: 'Remove'};
68 element.projectName = 'chromium';
69
70 await element.updateComplete;
71
72 const dropdownCols = element.shadowRoot.querySelector('.col-selector');
73
74 dropdownCols.selection = 'None';
75 dropdownCols.dispatchEvent(new Event('change'));
76
77 sinon.assert.calledWith(element._page,
78 '/p/chromium/issues/list?y=Keep');
79 });
80
81 it('cellOptions computes URLs with queryParams and projectName', async () => {
82 element.projectName = 'chromium';
83 element.queryParams = {q: 'hello-world'};
84
85 assert.deepEqual(element.cellOptions, [
86 {text: 'Tile', value: 'tiles',
87 url: '/p/chromium/issues/list?q=hello-world'},
88 {text: 'IDs', value: 'ids',
89 url: '/p/chromium/issues/list?q=hello-world&cells=ids'},
90 {text: 'Counts', value: 'counts',
91 url: '/p/chromium/issues/list?q=hello-world&cells=counts'},
92 ]);
93 });
94
95 describe('displays appropriate messaging for issue count', () => {
96 it('for one issue', () => {
97 element.issueCount = 1;
98 assert.equal(element.totalIssuesDisplay, '1 issue shown');
99 });
100
101 it('for less than 100,000 issues', () => {
102 element.issueCount = 50;
103 assert.equal(element.totalIssuesDisplay, '50 issues shown');
104 });
105
106 it('for 100,000 issues or more', () => {
107 element.issueCount = SERVER_LIST_ISSUES_LIMIT;
108 assert.equal(element.totalIssuesDisplay, '100,000+ issues shown');
109 });
110 });
111});