mirror of
https://github.com/grafana/grafana.git
synced 2025-01-06 22:23:19 -06:00
55055d0b9b
* Fix RuleEditor flaky test for existing grafana managed alert * Fix RuleEditor flaky test for creating a new grafana managed alert * Fix tests for cloud rules * Split tests for different rule types * Move common clickSelectOption method to helpers * Remove from RuleEditorCloudRules.test.tsx a repeated cloud rule test * Move existing grafana rule test case to a new file * Split RuleEditorCloudRules test: move checking only allowed data sources test case to a new test file * Re-use common ui const * Re-use renderRuleEditor method * Create getDiscoverFeaturesMock to reduce code
51 lines
2.0 KiB
TypeScript
51 lines
2.0 KiB
TypeScript
import { render } from '@testing-library/react';
|
|
import React from 'react';
|
|
import { Provider } from 'react-redux';
|
|
import { Router, Route } from 'react-router-dom';
|
|
import { byRole, byTestId } from 'testing-library-selector';
|
|
|
|
import { selectors } from '@grafana/e2e-selectors';
|
|
import { locationService } from '@grafana/runtime';
|
|
import RuleEditor from 'app/features/alerting/unified/RuleEditor';
|
|
import { configureStore } from 'app/store/configureStore';
|
|
|
|
export const ui = {
|
|
inputs: {
|
|
name: byRole('textbox', { name: /rule name name for the alert rule\./i }),
|
|
alertType: byTestId('alert-type-picker'),
|
|
dataSource: byTestId('datasource-picker'),
|
|
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'),
|
|
},
|
|
buttons: {
|
|
save: byRole('button', { name: 'Save' }),
|
|
addAnnotation: byRole('button', { name: /Add info/ }),
|
|
addLabel: byRole('button', { name: /Add label/ }),
|
|
// alert type buttons
|
|
grafanaManagedAlert: byRole('button', { name: /Grafana managed/ }),
|
|
lotexAlert: byRole('button', { name: /Mimir or Loki alert/ }),
|
|
lotexRecordingRule: byRole('button', { name: /Mimir or Loki recording rule/ }),
|
|
},
|
|
};
|
|
|
|
export function renderRuleEditor(identifier?: string) {
|
|
const store = configureStore();
|
|
|
|
locationService.push(identifier ? `/alerting/${identifier}/edit` : `/alerting/new`);
|
|
|
|
return render(
|
|
<Provider store={store}>
|
|
<Router history={locationService.getHistory()}>
|
|
<Route path={['/alerting/new', '/alerting/:id/edit']} component={RuleEditor} />
|
|
</Router>
|
|
</Provider>
|
|
);
|
|
}
|