Skip to content

Commit 55d0cb0

Browse files
authored
Bug 2045215 - [Perfherder][Comment_0] Alerts reassigned to a different summary are included in comment 0 when filing a new bug (#9772)
* fix: filter the textualSummary shown alerts * refactor: use alertStatusMap for readability and move the filter logic to a reusable method * fix: duplicate import * test: adding test coverage for filterValidAlerts * test: refactor test for better readability
1 parent f5a9701 commit 55d0cb0

2 files changed

Lines changed: 50 additions & 7 deletions

File tree

‎tests/ui/perfherder/alerts-view/status_dropdown_test.jsx‎

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import testPerformanceTags from '../../mock/performance_tags';
66
import repos from '../../mock/repositories';
77
import StatusDropdown from '../../../../ui/perfherder/alerts/StatusDropdown';
88
import issueTrackers from '../../../../treeherder/perf/fixtures/issue_tracker';
9+
import { alertStatusMap } from '../../../../ui/perfherder/perf-helpers/constants';
910

1011
let testAlertSummary = testAlertSummaries[0];
1112
const testAlerts = testAlertSummary.alerts;
@@ -257,3 +258,32 @@ test("'Request backout' is not offered for a summary with no severity", async ()
257258
});
258259
expect(queryByText('Request backout')).toBeNull();
259260
});
261+
262+
test('filterValidAlerts returns only valid alerts (acknowledged, untriaged, and valid reassigned)', () => {
263+
const alertSummary = { id: 100 };
264+
const dropdown = new StatusDropdown({
265+
alertSummary,
266+
frameworks: [],
267+
filteredAlerts: [
268+
{ id: 1, status: alertStatusMap.acknowledged },
269+
{ id: 2, status: alertStatusMap.untriaged },
270+
{ id: 3, status: alertStatusMap.reassigned, summary_id: 99 },
271+
{ id: 4, status: alertStatusMap.reassigned, summary_id: 100 },
272+
{ id: 5, status: alertStatusMap.invalid },
273+
],
274+
});
275+
276+
const validAlerts = dropdown.filterValidAlerts();
277+
278+
expect(validAlerts).toHaveLength(3);
279+
expect(validAlerts.map(a => a.id)).toEqual([1, 2, 3]);
280+
});
281+
282+
test('filterValidAlerts defaults to an empty array if filteredAlerts is undefined', () => {
283+
const dropdown = new StatusDropdown({
284+
alertSummary: { id: 100 },
285+
frameworks: [],
286+
});
287+
288+
expect(dropdown.filterValidAlerts()).toEqual([]);
289+
});

‎ui/perfherder/alerts/StatusDropdown.jsx‎

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -104,12 +104,21 @@ export default class StatusDropdown extends React.Component {
104104
return Array.from(new Set(names)).join(', ');
105105
};
106106

107+
filterValidAlerts = () => {
108+
const { filteredAlerts = [], alertSummary } = this.props;
109+
return filteredAlerts.filter(
110+
(alert) =>
111+
alert.status === alertStatusMap.acknowledged ||
112+
alert.status === alertStatusMap.untriaged ||
113+
(alert.status === alertStatusMap.reassigned && alert.summary_id !== alertSummary.id),
114+
);
115+
};
116+
107117
fileBug = async (culpritId) => {
108118
const {
109119
alertSummary,
110120
repoModel,
111121
updateViewState,
112-
filteredAlerts = [],
113122
frameworks,
114123
user,
115124
} = this.props;
@@ -128,9 +137,11 @@ export default class StatusDropdown extends React.Component {
128137
updateViewState,
129138
);
130139

140+
const validAlerts = this.filterValidAlerts();
141+
131142
const textualSummary = new TextualSummary(
132143
frameworks,
133-
filteredAlerts,
144+
validAlerts,
134145
alertSummary,
135146
null,
136147
await browsertimeAlertsExtraData.enrichAndRetrieveAlerts(),
@@ -236,7 +247,6 @@ export default class StatusDropdown extends React.Component {
236247
const {
237248
alertSummary,
238249
repoModel,
239-
filteredAlerts = [],
240250
frameworks,
241251
updateViewState,
242252
user,
@@ -256,9 +266,11 @@ export default class StatusDropdown extends React.Component {
256266
updateViewState,
257267
);
258268

269+
const validAlerts = this.filterValidAlerts();
270+
259271
const textualSummary = new TextualSummary(
260272
frameworks,
261-
filteredAlerts,
273+
validAlerts,
262274
alertSummary,
263275
null,
264276
await browsertimeAlertsExtraData.enrichAndRetrieveAlerts(),
@@ -290,7 +302,7 @@ export default class StatusDropdown extends React.Component {
290302

291303
// can't access the clipboardData on event unless it's done from react's
292304
// onCopy, onCut or onPaste props so using this workaround
293-
navigator.clipboard.writeText(commentText).then(() => {});
305+
navigator.clipboard.writeText(commentText).then(() => { });
294306
};
295307

296308
async getBugTemplate(framework, updateViewState) {
@@ -346,7 +358,6 @@ export default class StatusDropdown extends React.Component {
346358
alertSummary,
347359
repoModel,
348360
updateViewState,
349-
filteredAlerts = [],
350361
frameworks,
351362
user,
352363
} = this.props;
@@ -368,9 +379,11 @@ export default class StatusDropdown extends React.Component {
368379
return { failureStatus: 'Failed to retrieve bug template' };
369380
}
370381

382+
const validAlerts = this.filterValidAlerts();
383+
371384
const textualSummary = new TextualSummary(
372385
frameworks,
373-
filteredAlerts,
386+
validAlerts,
374387
alertSummary,
375388
null,
376389
await browsertimeAlertsExtraData.enrichAndRetrieveAlerts(),

0 commit comments

Comments
 (0)