blob: 241091b84bdb1d3efe7d9ac079c9994e6c31e0e0 [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 {MrGridPage} from './mr-grid-page.js';
8
9let element;
10
11describe('mr-grid-page', () => {
12 beforeEach(() => {
13 element = document.createElement('mr-grid-page');
14 document.body.appendChild(element);
15 });
16
17 afterEach(() => {
18 document.body.removeChild(element);
19 });
20
21 it('initializes', () => {
22 assert.instanceOf(element, MrGridPage);
23 });
24
25 it('progress bar updates properly', async () => {
26 await element.updateComplete;
27 element.progress = .2499;
28 await element.updateComplete;
29 const title =
30 element.shadowRoot.querySelector('progress').getAttribute('title');
31 assert.equal(title, '25%');
32 });
33
34 it('displays error when no issues match query', async () => {
35 await element.updateComplete;
36 element.progress = 1;
37 element.totalIssues = 0;
38 await element.updateComplete;
39 const error =
40 element.shadowRoot.querySelector('.empty-search').textContent;
41 assert.equal(error.trim(), 'Your search did not generate any results.');
42 });
43
44 it('calls to fetchIssueList made when _currentQuery changes', async () => {
45 await element.updateComplete;
46 const issueListCall = sinon.stub(element, '_fetchMatchingIssues');
47 element._queryParams = {x: 'Blocked'};
48 await element.updateComplete;
49 sinon.assert.notCalled(issueListCall);
50
51 element._presentationConfigLoaded = true;
52 element._currentQuery = 'cc:me';
53 await element.updateComplete;
54 sinon.assert.calledOnce(issueListCall);
55 });
56
57 it('calls to fetchIssueList made when _currentCan changes', async () => {
58 await element.updateComplete;
59 const issueListCall = sinon.stub(element, '_fetchMatchingIssues');
60 element._queryParams = {y: 'Blocked'};
61 await element.updateComplete;
62 sinon.assert.notCalled(issueListCall);
63
64 element._presentationConfigLoaded = true;
65 element._currentCan = 1;
66 await element.updateComplete;
67 sinon.assert.calledOnce(issueListCall);
68 });
69
70 describe('_shouldFetchMatchingIssues', () => {
71 it('default returns false', () => {
72 const result = element._shouldFetchMatchingIssues(new Map());
73 assert.isFalse(result);
74 });
75
76 it('returns true for projectName', () => {
77 element._queryParams = {q: ''};
78 const changedProps = new Map();
79 changedProps.set('projectName', 'anything');
80 const result = element._shouldFetchMatchingIssues(changedProps);
81 assert.isTrue(result);
82 });
83
84 it('returns true when _currentQuery changes', () => {
85 element._presentationConfigLoaded = true;
86
87 element._currentQuery = 'owner:me';
88 const changedProps = new Map();
89 changedProps.set('_currentQuery', '');
90
91 const result = element._shouldFetchMatchingIssues(changedProps);
92 assert.isTrue(result);
93 });
94
95 it('returns true when _currentCan changes', () => {
96 element._presentationConfigLoaded = true;
97
98 element._currentCan = 1;
99 const changedProps = new Map();
100 changedProps.set('_currentCan', 2);
101
102 const result = element._shouldFetchMatchingIssues(changedProps);
103 assert.isTrue(result);
104 });
105
106 it('returns false when presentation config not loaded', () => {
107 element._presentationConfigLoaded = false;
108
109 const changedProps = new Map();
110 changedProps.set('projectName', 'anything');
111 const result = element._shouldFetchMatchingIssues(changedProps);
112
113 assert.isFalse(result);
114 });
115
116 it('returns true when presentationConfig fetch completes', () => {
117 element._presentationConfigLoaded = true;
118
119 const changedProps = new Map();
120 changedProps.set('_presentationConfigLoaded', false);
121 const result = element._shouldFetchMatchingIssues(changedProps);
122
123 assert.isTrue(result);
124 });
125 });
126});