2025-01-08 21:48:08 +08:00
|
|
|
import { Route, Routes } from 'react-router-dom-v5-compat';
|
2024-08-07 17:58:58 +08:00
|
|
|
import { render } from 'test/test-utils';
|
2024-03-11 15:47:56 +08:00
|
|
|
import { byRole, byTestId, byText } from 'testing-library-selector';
|
2022-12-07 23:15:33 +08:00
|
|
|
|
|
|
|
|
import { selectors } from '@grafana/e2e-selectors';
|
2024-10-11 18:08:50 +08:00
|
|
|
import { AppNotificationList } from 'app/core/components/AppNotifications/AppNotificationList';
|
2025-01-28 21:49:47 +08:00
|
|
|
import RuleEditor from 'app/features/alerting/unified/rule-editor/RuleEditor';
|
|
|
|
|
|
2025-01-08 21:48:08 +08:00
|
|
|
export enum GrafanaRuleFormStep {
|
|
|
|
|
Query = 2,
|
|
|
|
|
Notification = 5,
|
|
|
|
|
}
|
2023-02-02 16:53:06 +08:00
|
|
|
|
2022-12-07 23:15:33 +08:00
|
|
|
export const ui = {
|
2024-05-30 18:55:06 +08:00
|
|
|
loadingIndicator: byText('Loading rule...'),
|
2022-12-07 23:15:33 +08:00
|
|
|
inputs: {
|
2023-09-06 19:24:48 +08:00
|
|
|
name: byRole('textbox', { name: 'name' }),
|
2025-01-08 21:48:08 +08:00
|
|
|
metric: byRole('textbox', { name: 'metric' }),
|
2022-12-07 23:15:33 +08:00
|
|
|
alertType: byTestId('alert-type-picker'),
|
2024-02-06 17:20:07 +08:00
|
|
|
dataSource: byTestId(selectors.components.DataSourcePicker.inputV2),
|
2022-12-07 23:15:33 +08:00
|
|
|
folder: byTestId('folder-picker'),
|
|
|
|
|
folderContainer: byTestId(selectors.components.FolderPicker.containerV2),
|
|
|
|
|
namespace: byTestId('namespace-picker'),
|
|
|
|
|
group: byTestId('group-picker'),
|
|
|
|
|
annotationKey: (idx: number) => byTestId(`annotation-key-${idx}`),
|
|
|
|
|
annotationValue: (idx: number) => byTestId(`annotation-value-${idx}`),
|
|
|
|
|
labelKey: (idx: number) => byTestId(`label-key-${idx}`),
|
|
|
|
|
labelValue: (idx: number) => byTestId(`label-value-${idx}`),
|
|
|
|
|
expr: byTestId('expr'),
|
2024-03-11 15:47:56 +08:00
|
|
|
simplifiedRouting: {
|
|
|
|
|
contactPointRouting: byRole('radio', { name: /select contact point/i }),
|
|
|
|
|
contactPoint: byTestId('contact-point-picker'),
|
|
|
|
|
routingOptions: byText(/muting, grouping and timings \(optional\)/i),
|
|
|
|
|
},
|
2025-01-27 20:57:31 +08:00
|
|
|
switchModeBasic: (stepNo: GrafanaRuleFormStep) =>
|
|
|
|
|
byTestId(selectors.components.AlertRules.stepAdvancedModeSwitch(stepNo.toString())),
|
|
|
|
|
switchModeAdvanced: (stepNo: GrafanaRuleFormStep) =>
|
|
|
|
|
byTestId(selectors.components.AlertRules.stepAdvancedModeSwitch(stepNo.toString())),
|
2022-12-07 23:15:33 +08:00
|
|
|
},
|
|
|
|
|
buttons: {
|
2023-10-03 20:55:42 +08:00
|
|
|
saveAndExit: byRole('button', { name: 'Save rule and exit' }),
|
2023-05-04 23:05:26 +08:00
|
|
|
save: byRole('button', { name: 'Save rule' }),
|
2022-12-07 23:15:33 +08:00
|
|
|
addAnnotation: byRole('button', { name: /Add info/ }),
|
|
|
|
|
addLabel: byRole('button', { name: /Add label/ }),
|
2025-01-21 01:56:21 +08:00
|
|
|
preview: byRole('button', { name: /^Preview$/ }),
|
2022-12-07 23:15:33 +08:00
|
|
|
},
|
|
|
|
|
};
|
2025-01-08 21:48:08 +08:00
|
|
|
export function renderRuleEditor(identifier?: string, recording?: 'recording' | 'grafana-recording') {
|
2024-10-10 12:33:16 +08:00
|
|
|
return render(
|
2024-10-11 18:08:50 +08:00
|
|
|
<>
|
|
|
|
|
<AppNotificationList />
|
|
|
|
|
<Routes>
|
|
|
|
|
<Route path={'/alerting/new/:type'} element={<RuleEditor />} />
|
|
|
|
|
<Route path={'/alerting/:id/edit'} element={<RuleEditor />} />
|
|
|
|
|
</Routes>
|
|
|
|
|
</>,
|
2024-10-10 12:33:16 +08:00
|
|
|
{
|
|
|
|
|
historyOptions: {
|
2025-01-08 21:48:08 +08:00
|
|
|
initialEntries: [identifier ? `/alerting/${identifier}/edit` : `/alerting/new/${recording ?? 'alerting'}`],
|
2024-10-10 12:33:16 +08:00
|
|
|
},
|
|
|
|
|
}
|
|
|
|
|
);
|
2022-12-07 23:15:33 +08:00
|
|
|
}
|