go.chromium.org/luci@v0.0.0-20240309015107-7cdc2e660f33/analysis/frontend/ui/src/testing_tools/mocks/projects_mock.ts (about) 1 // Copyright 2022 The LUCI Authors. 2 // 3 // Licensed under the Apache License, Version 2.0 (the "License"); 4 // you may not use this file except in compliance with the License. 5 // You may obtain a copy of the License at 6 // 7 // http://www.apache.org/licenses/LICENSE-2.0 8 // 9 // Unless required by applicable law or agreed to in writing, software 10 // distributed under the License is distributed on an "AS IS" BASIS, 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 // See the License for the specific language governing permissions and 13 // limitations under the License. 14 15 import fetchMock from 'fetch-mock-jest'; 16 17 import { BugManagementPolicy, BuganizerPriority, ProjectConfig } from '@/proto/go.chromium.org/luci/analysis/proto/v1/projects.pb'; 18 import { DeepMutable } from '@/types/types'; 19 20 export const createMockExonerationsPolicy = (): DeepMutable<BugManagementPolicy> => { 21 return { 22 id: 'exonerations', 23 owners: ['exoneration-owner1@google.com', 'exoneration-owner2@google.com'], 24 humanReadableName: 'test variant(s) are being exonerated (ignored) in presubmit', 25 priority: BuganizerPriority.P2, 26 metrics: [{ 27 metricId: 'critical-failures-exonerated', 28 activationThreshold: { 29 threeDay: '75', 30 }, 31 deactivationThreshold: { 32 sevenDay: '1', 33 }, 34 }], 35 explanation: { 36 problemHtml: 'Test variant(s) in this cluster are too flaky to gate changes in CQ. As a result, functionality is not protected from breakage.', 37 actionHtml: '<ul><li>Review the exonerations tab to see which test variants are being exonerated.</li><li>View recent failures to help you debug the problem.</li></ul>', 38 }, 39 }; 40 }; 41 42 export const createMockProjectConfig = (): DeepMutable<ProjectConfig> => { 43 return { 44 name: 'projects/chromium/config', 45 bugManagement: { 46 policies: [createMockExonerationsPolicy(), { 47 id: 'cls-rejected', 48 owners: ['cls-rejected-owner1@google.com', 'cls-rejected-owner2@google.com'], 49 humanReadableName: 'many CL(s) are being rejected', 50 priority: BuganizerPriority.P0, 51 metrics: [{ 52 metricId: 'human-cls-failed-presubmit', 53 activationThreshold: { 54 threeDay: '10', 55 }, 56 deactivationThreshold: { 57 sevenDay: '1', 58 }, 59 }], 60 explanation: { 61 problemHtml: 'Many changelists are unable to submit because of failures on this test.', 62 actionHtml: '<ul><li>Consider disabling the test(s) while you investigate the root cause, to immediately unblock developers.</li><li>View recent failures to help you debug the problem.</li></ul>', 63 }, 64 }], 65 monorail: { 66 project: 'chromium', 67 displayPrefix: 'crbug.com', 68 }, 69 }, 70 }; 71 }; 72 73 export const mockFetchProjectConfig = (projectConfig?: ProjectConfig) => { 74 if (projectConfig === undefined) { 75 projectConfig = createMockProjectConfig(); 76 } 77 fetchMock.post('http://localhost/prpc/luci.analysis.v1.Projects/GetConfig', { 78 headers: { 79 'X-Prpc-Grpc-Code': '0', 80 }, 81 body: ')]}\'\n' + JSON.stringify(ProjectConfig.toJSON(projectConfig)), 82 }); 83 };