123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133 |
- import { act, render, screen } from '@testing-library/react';
- import React from 'react';
- import { QueryEditorProps } from '@grafana/data';
- import { setupMockedDataSource } from '../__mocks__/CloudWatchDataSource';
- import { CloudWatchDatasource } from '../datasource';
- import { CloudWatchQuery, CloudWatchJsonData, MetricEditorMode, MetricQueryType } from '../types';
- import { PanelQueryEditor } from './PanelQueryEditor';
- // the following three fields are added to legacy queries in the dashboard migrator
- const migratedFields = {
- statistic: 'Average',
- metricEditorMode: MetricEditorMode.Builder,
- metricQueryType: MetricQueryType.Query,
- };
- const props: QueryEditorProps<CloudWatchDatasource, CloudWatchQuery, CloudWatchJsonData> = {
- datasource: setupMockedDataSource().datasource,
- onRunQuery: jest.fn(),
- onChange: jest.fn(),
- query: {} as CloudWatchQuery,
- };
- describe('PanelQueryEditor should render right editor', () => {
- describe('when using grafana 6.3.0 metric query', () => {
- it('should render the metrics query editor', async () => {
- const query = {
- ...migratedFields,
- dimensions: {
- InstanceId: 'i-123',
- },
- expression: '',
- highResolution: false,
- id: '',
- metricName: 'CPUUtilization',
- namespace: 'AWS/EC2',
- period: '',
- refId: 'A',
- region: 'default',
- returnData: false,
- };
- await act(async () => {
- render(<PanelQueryEditor {...props} query={query} />);
- });
- expect(screen.getByText('Metric name')).toBeInTheDocument();
- });
- });
- describe('when using grafana 7.0.0 style metrics query', () => {
- it('should render the metrics query editor', async () => {
- const query = {
- ...migratedFields,
- alias: '',
- apiMode: 'Logs',
- dimensions: {
- InstanceId: 'i-123',
- },
- expression: '',
- id: '',
- logGroupNames: [],
- matchExact: true,
- metricName: 'CPUUtilization',
- namespace: 'AWS/EC2',
- period: '',
- queryMode: 'Logs',
- refId: 'A',
- region: 'ap-northeast-2',
- statistics: 'Average',
- } as any;
- await act(async () => {
- render(<PanelQueryEditor {...props} query={query} />);
- });
- expect(screen.getByText('Choose Log Groups')).toBeInTheDocument();
- });
- });
- describe('when using grafana 7.0.0 style logs query', () => {
- it('should render the metrics query editor', async () => {
- const query = {
- ...migratedFields,
- alias: '',
- apiMode: 'Logs',
- dimensions: {
- InstanceId: 'i-123',
- },
- expression: '',
- id: '',
- logGroupNames: [],
- matchExact: true,
- metricName: 'CPUUtilization',
- namespace: 'AWS/EC2',
- period: '',
- queryMode: 'Logs',
- refId: 'A',
- region: 'ap-northeast-2',
- statistic: 'Average',
- } as any;
- await act(async () => {
- render(<PanelQueryEditor {...props} query={query} />);
- });
- expect(screen.getByText('Log Groups')).toBeInTheDocument();
- });
- });
- describe('when using grafana query from curated ec2 dashboard', () => {
- it('should render the metrics query editor', async () => {
- const query = {
- ...migratedFields,
- alias: 'Inbound',
- dimensions: {
- InstanceId: '*',
- },
- expression:
- "SUM(REMOVE_EMPTY(SEARCH('{AWS/EC2,InstanceId} MetricName=\"NetworkIn\"', 'Sum', $period)))/$period",
- id: '',
- matchExact: true,
- metricName: 'NetworkOut',
- namespace: 'AWS/EC2',
- period: '$period',
- refId: 'B',
- region: '$region',
- statistic: 'Average',
- } as any;
- await act(async () => {
- render(<PanelQueryEditor {...props} query={query} />);
- });
- expect(screen.getByText('Metric name')).toBeInTheDocument();
- });
- });
- });
|