blob: 583fb0143ca6be0b8bbe60cd095b2b491c7234ea [file] [log] [blame]
Copybara854996b2021-09-07 19:36:02 +00001/* Copyright 2016 The Chromium Authors. All Rights Reserved.
2 *
3 * Use of this source code is governed by a BSD-style
4 * license that can be found in the LICENSE file or at
5 * https://developers.google.com/open-source/licenses/bsd
6 */
7
8const feedData = {
9 'open': [{name: 'New', doc: 'Newly reported'},
10 {name: 'Started', doc: 'Work has begun'}],
11 'closed': [{name: 'Fixed', doc: 'Problem was fixed'},
12 {name: 'Invalid', doc: 'Bad issue report'}],
13 'labels': [{name: 'Type-Defect', doc: 'Something is broken'},
14 {name: 'Type-Enhancement', doc: 'It could be better'},
15 {name: 'Priority-High', doc: 'Urgent'},
16 {name: 'Priority-Low', doc: 'Not so urgent'},
17 {name: 'Hot', doc: ''},
18 {name: 'Cold', doc: ''}],
19 'members': [{name: 'jrobbins', doc: ''},
20 {name: 'jrobbins@chromium.org', doc: ''}],
21 'excl_prefixes': [],
22 'strict': false,
23};
24
25function setUp() {
26 TKR_autoCompleteFeedName = 'issueOptions';
27}
28
29/**
30 * The assertEquals method cannot do element-by-element comparisons.
31 * A search of how other teams write JS unit tests turned up this
32 * way to compare arrays.
33 */
34function assertElementsEqual(arrayA, arrayB) {
35 assertEquals(arrayA.join(' ;; '), arrayB.join(' ;; '));
36}
37
38function completionsEqual(strings, completions) {
39 if (strings.length != completions.length) {
40 return false;
41 }
42 for (let i = 0; i < strings.length; i++) {
43 if (strings[i] != completions[i].value) {
44 return false;
45 }
46 }
47 return true;
48}
49
50function assertHasCompletion(s, acStore) {
51 const ch = s.charAt(0).toLowerCase();
52 const firstCharMapArray = acStore.firstCharMap_[ch];
53 assertNotNull(!firstCharMapArray);
54 for (let i = 0; i < firstCharMapArray.length; i++) {
55 if (s == firstCharMapArray[i].value) return;
56 }
57 fail('completion ' + s + ' not found in acStore[' +
58 acStoreToString(acStore) + ']');
59}
60
61function assertHasAllCompletions(stringArray, acStore) {
62 for (let i = 0; i < stringArray.length; i++) {
63 assertHasCompletion(stringArray[i], acStore);
64 }
65}
66
67function acStoreToString(acStore) {
68 const allCompletions = [];
69 for (const ch in acStore.firstCharMap_) {
70 if (acStore.firstCharMap_.hasOwnProperty(ch)) {
71 const firstCharArray = acStore.firstCharMap_[ch];
72 for (let i = 0; i < firstCharArray.length; i++) {
73 allCompletions[firstCharArray[i].value] = true;
74 }
75 }
76 }
77 const parts = [];
78 for (const comp in allCompletions) {
79 if (allCompletions.hasOwnProperty(comp)) {
80 parts.push(comp);
81 }
82 }
83 return parts.join(', ');
84}
85
86function testSetUpStatusStore() {
87 TKR_setUpStatusStore(feedData.open, feedData.closed);
88 assertElementsEqual(
89 ['New', 'Started', 'Fixed', 'Invalid'],
90 TKR_statusWords);
91 assertHasAllCompletions(
92 ['New', 'Started', 'Fixed', 'Invalid'],
93 TKR_statusStore);
94}
95
96function testSetUpSearchStore() {
97 TKR_setUpSearchStore(
98 feedData.labels, feedData.members, feedData.open, feedData.closed);
99 assertHasAllCompletions(
100 ['status:New', 'status:Started', 'status:Fixed', 'status:Invalid',
101 '-status:New', '-status:Started', '-status:Fixed', '-status:Invalid',
102 'Type=Defect', '-Type=Defect', 'Type=Enhancement', '-Type=Enhancement',
103 'label:Hot', 'label:Cold', '-label:Hot', '-label:Cold',
104 'owner:jrobbins', 'cc:jrobbins', '-owner:jrobbins', '-cc:jrobbins',
105 'summary:', 'opened-after:today-1', 'commentby:me', 'reporter:me'],
106 TKR_searchStore);
107}
108
109function testSetUpQuickEditStore() {
110 TKR_setUpQuickEditStore(
111 feedData.labels, feedData.members, feedData.open, feedData.closed);
112 assertHasAllCompletions(
113 ['status=New', 'status=Started', 'status=Fixed', 'status=Invalid',
114 'Type=Defect', 'Type=Enhancement', 'Hot', 'Cold', '-Hot', '-Cold',
115 'owner=jrobbins', 'owner=me', 'cc=jrobbins', 'cc=me', 'cc=-jrobbins',
116 'cc=-me', 'summary=""', 'owner=----'],
117 TKR_quickEditStore);
118}
119
120function testSetUpLabelStore() {
121 TKR_setUpLabelStore(feedData.labels);
122 assertHasAllCompletions(
123 ['Type-Defect', 'Type-Enhancement', 'Hot', 'Cold'],
124 TKR_labelStore);
125}
126
127function testSetUpMembersStore() {
128 TKR_setUpMemberStore(feedData.members);
129 assertHasAllCompletions(
130 ['jrobbins', 'jrobbins@chromium.org'],
131 TKR_memberListStore);
132}