| 
									
										
											  
											
												Prometheus: Create Prometheus library (#81641)
* Move to the library
* copy from library
* move them in src
* have additional files
* add unmigrated/dulicated code and files
* migrate from brendan's pr
module.ts, query_hints.ts, tracking.ts, and remove plugin.json
* migrate from brendan's pr
metric_find_query.test.ts
* migrate from brendan's pr
language_utils.test.ts
* migrate from brendan's pr
index.ts in root and in configuration
* migrate from brendan's pr
datasource.test.ts
* migrate from brendan's pr
typings folder
* migrate from brendan's pr
querycache folder
* migrate from brendan's pr
monaco-query-field folder
* migrate from brendan's pr
components folder without monaco-query-field folder
* migrate from brendan's pr
configuration/overhaul folder
* migrate from brendan's pr
AlertingSettingsOverhaul.tsx
* Remove azure related code
* migrate from brendan's pr
ConfigEditor.tsx, DataSourceHttpSettingsOverhaul.tsx, ExemplarSetting.tsx, configuration/mocks.ts, PromSettings.test.tsx, PromSettings.tsx
* migrate from brendan's pr
useFlag.ts
* migrate from brendan's pr
metrics-modal folder
* migrate from brendan's pr
files inside components folder
* migrate from brendan's pr
LabelFilters* files because they are now under components folder
* migrate from brendan's pr
files under querybuilder/shared folder
* migrate from brendan's pr
aggregations.ts, QueryPattern.tsx, QueryPatternsModal.tsx, state.ts, testUtils.ts under querybuilder folder
* Apply Ivana's PR https://github.com/grafana/grafana/pull/81656
* Apply jack's suggestions in this PR https://github.com/grafana/grafana/pull/77762
* Apply Ivana's PR https://github.com/grafana/grafana/pull/81656
* Fix type import
* add monaco-promql to transformIgnorePatterns to run prometheus frontend library tests
* remove Loki specific tests because we removed Loki code to decouple Loki
* add prometheus specific references
* We are moving these betterer issues from core Prometheus to the Library and we promise to remove all issues in the future, thank you
* include prometheus library in package.json
* add yarn lock with prometheus frontend library
* decouple final core import from metric_find_query.test.ts
* run prettier
* fix core imports in promqail
* fix lint errors
* run prettier
* add grafana-ui to devdeps to fix lint errors
* update yarn.lock
* grafana-ui fix
* trying to fix grafana-ui type errors with lerna drone check
* trying to fix grafana-ui type errors with lerna drone check
* trying to fix grafana-ui type errors with lerna drone check
* trying to fix grafana-ui type errors with lerna drone check
* try to pass typecheck
---------
Co-authored-by: Brendan O'Handley <brendan.ohandley@grafana.com>
											
										 
											2024-02-02 22:30:14 +08:00
										 |  |  | import { render, screen } from '@testing-library/react'; | 
					
						
							|  |  |  | import { noop } from 'lodash'; | 
					
						
							|  |  |  | import React from 'react'; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | import { CoreApp } from '@grafana/data'; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | import { PrometheusDatasource } from '../datasource'; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | import { PromQueryEditorByApp } from './PromQueryEditorByApp'; | 
					
						
							| 
									
										
										
										
											2024-02-06 22:27:09 +08:00
										 |  |  | import { alertingTestIds } from './PromQueryEditorForAlerting'; | 
					
						
							| 
									
										
											  
											
												Prometheus: Create Prometheus library (#81641)
* Move to the library
* copy from library
* move them in src
* have additional files
* add unmigrated/dulicated code and files
* migrate from brendan's pr
module.ts, query_hints.ts, tracking.ts, and remove plugin.json
* migrate from brendan's pr
metric_find_query.test.ts
* migrate from brendan's pr
language_utils.test.ts
* migrate from brendan's pr
index.ts in root and in configuration
* migrate from brendan's pr
datasource.test.ts
* migrate from brendan's pr
typings folder
* migrate from brendan's pr
querycache folder
* migrate from brendan's pr
monaco-query-field folder
* migrate from brendan's pr
components folder without monaco-query-field folder
* migrate from brendan's pr
configuration/overhaul folder
* migrate from brendan's pr
AlertingSettingsOverhaul.tsx
* Remove azure related code
* migrate from brendan's pr
ConfigEditor.tsx, DataSourceHttpSettingsOverhaul.tsx, ExemplarSetting.tsx, configuration/mocks.ts, PromSettings.test.tsx, PromSettings.tsx
* migrate from brendan's pr
useFlag.ts
* migrate from brendan's pr
metrics-modal folder
* migrate from brendan's pr
files inside components folder
* migrate from brendan's pr
LabelFilters* files because they are now under components folder
* migrate from brendan's pr
files under querybuilder/shared folder
* migrate from brendan's pr
aggregations.ts, QueryPattern.tsx, QueryPatternsModal.tsx, state.ts, testUtils.ts under querybuilder folder
* Apply Ivana's PR https://github.com/grafana/grafana/pull/81656
* Apply jack's suggestions in this PR https://github.com/grafana/grafana/pull/77762
* Apply Ivana's PR https://github.com/grafana/grafana/pull/81656
* Fix type import
* add monaco-promql to transformIgnorePatterns to run prometheus frontend library tests
* remove Loki specific tests because we removed Loki code to decouple Loki
* add prometheus specific references
* We are moving these betterer issues from core Prometheus to the Library and we promise to remove all issues in the future, thank you
* include prometheus library in package.json
* add yarn lock with prometheus frontend library
* decouple final core import from metric_find_query.test.ts
* run prettier
* fix core imports in promqail
* fix lint errors
* run prettier
* add grafana-ui to devdeps to fix lint errors
* update yarn.lock
* grafana-ui fix
* trying to fix grafana-ui type errors with lerna drone check
* trying to fix grafana-ui type errors with lerna drone check
* trying to fix grafana-ui type errors with lerna drone check
* trying to fix grafana-ui type errors with lerna drone check
* try to pass typecheck
---------
Co-authored-by: Brendan O'Handley <brendan.ohandley@grafana.com>
											
										 
											2024-02-02 22:30:14 +08:00
										 |  |  | import { Props } from './monaco-query-field/MonacoQueryFieldProps'; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | // the monaco-based editor uses lazy-loading and that does not work
 | 
					
						
							|  |  |  | // well with this test, and we do not need the monaco-related
 | 
					
						
							|  |  |  | // functionality in this test anyway, so we mock it out.
 | 
					
						
							|  |  |  | jest.mock('./monaco-query-field/MonacoQueryFieldLazy', () => { | 
					
						
							|  |  |  |   const fakeQueryField = (props: Props) => { | 
					
						
							|  |  |  |     return <input onBlur={(e) => props.onBlur(e.currentTarget.value)} data-testid={'dummy-code-input'} type={'text'} />; | 
					
						
							|  |  |  |   }; | 
					
						
							|  |  |  |   return { | 
					
						
							|  |  |  |     MonacoQueryFieldLazy: fakeQueryField, | 
					
						
							|  |  |  |   }; | 
					
						
							|  |  |  | }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | function setup(app: CoreApp): { onRunQuery: jest.Mock } { | 
					
						
							|  |  |  |   const dataSource = { | 
					
						
							|  |  |  |     createQuery: jest.fn((q) => q), | 
					
						
							|  |  |  |     getInitHints: () => [], | 
					
						
							|  |  |  |     getPrometheusTime: jest.fn((date, roundup) => 123), | 
					
						
							|  |  |  |     getQueryHints: jest.fn(() => []), | 
					
						
							|  |  |  |     getDebounceTimeInMilliseconds: jest.fn(() => 300), | 
					
						
							|  |  |  |     languageProvider: { | 
					
						
							|  |  |  |       start: () => Promise.resolve([]), | 
					
						
							|  |  |  |       syntax: () => {}, | 
					
						
							|  |  |  |       getLabelKeys: () => [], | 
					
						
							|  |  |  |       metrics: [], | 
					
						
							|  |  |  |     }, | 
					
						
							|  |  |  |   } as unknown as PrometheusDatasource; | 
					
						
							|  |  |  |   const onRunQuery = jest.fn(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   render( | 
					
						
							|  |  |  |     <PromQueryEditorByApp | 
					
						
							|  |  |  |       app={app} | 
					
						
							|  |  |  |       onChange={noop} | 
					
						
							|  |  |  |       onRunQuery={onRunQuery} | 
					
						
							|  |  |  |       datasource={dataSource} | 
					
						
							|  |  |  |       query={{ refId: 'A', expr: '' }} | 
					
						
							|  |  |  |     /> | 
					
						
							|  |  |  |   ); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   return { | 
					
						
							|  |  |  |     onRunQuery, | 
					
						
							|  |  |  |   }; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | describe('PromQueryEditorByApp', () => { | 
					
						
							|  |  |  |   it('should render simplified query editor for cloud alerting', async () => { | 
					
						
							|  |  |  |     setup(CoreApp.CloudAlerting); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     expect(await screen.findByTestId(alertingTestIds.editor)).toBeInTheDocument(); | 
					
						
							|  |  |  |   }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   it('should render editor selector for unkown apps', () => { | 
					
						
							|  |  |  |     setup(CoreApp.Unknown); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     expect(screen.getByTestId('QueryEditorModeToggle')).toBeInTheDocument(); | 
					
						
							|  |  |  |     expect(screen.queryByTestId(alertingTestIds.editor)).toBeNull(); | 
					
						
							|  |  |  |   }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   it('should render editor selector for explore', () => { | 
					
						
							|  |  |  |     setup(CoreApp.Explore); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     expect(screen.getByTestId('QueryEditorModeToggle')).toBeInTheDocument(); | 
					
						
							|  |  |  |     expect(screen.queryByTestId(alertingTestIds.editor)).toBeNull(); | 
					
						
							|  |  |  |   }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   it('should render editor selector for dashboard', () => { | 
					
						
							|  |  |  |     setup(CoreApp.Dashboard); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     expect(screen.getByTestId('QueryEditorModeToggle')).toBeInTheDocument(); | 
					
						
							|  |  |  |     expect(screen.queryByTestId(alertingTestIds.editor)).toBeNull(); | 
					
						
							|  |  |  |   }); | 
					
						
							|  |  |  | }); |