|
1 |
| -import { render, screen, waitFor } from '@testing-library/react'; |
| 1 | +import { render, screen, waitFor, cleanup } from '@testing-library/react'; |
2 | 2 |
|
3 | 3 | import { CoreApp } from '@grafana/data';
|
4 | 4 | import { config } from '@grafana/runtime';
|
@@ -39,6 +39,15 @@ jest.mock('@grafana/runtime', () => ({
|
39 | 39 | }));
|
40 | 40 |
|
41 | 41 | describe('Azure Monitor QueryEditor', () => {
|
| 42 | + beforeEach(() => { |
| 43 | + config.featureToggles = {}; |
| 44 | + }); |
| 45 | + |
| 46 | + afterEach(() => { |
| 47 | + cleanup(); |
| 48 | + jest.clearAllMocks(); |
| 49 | + }); |
| 50 | + |
42 | 51 | it('renders the Metrics query editor when the query type is Metrics', async () => {
|
43 | 52 | const mockDatasource = createMockDatasource();
|
44 | 53 | const mockQuery = {
|
@@ -67,6 +76,65 @@ describe('Azure Monitor QueryEditor', () => {
|
67 | 76 | );
|
68 | 77 | });
|
69 | 78 |
|
| 79 | + it('renders the Logs code editor when there is an existing query and the builder is enabled', async () => { |
| 80 | + config.featureToggles.azureMonitorLogsBuilderEditor = true; |
| 81 | + const mockDatasource = createMockDatasource(); |
| 82 | + const mockQuery = { |
| 83 | + ...createMockQuery(), |
| 84 | + queryType: AzureQueryType.LogAnalytics, |
| 85 | + }; |
| 86 | + |
| 87 | + render(<QueryEditor query={mockQuery} datasource={mockDatasource} onChange={() => {}} onRunQuery={() => {}} />); |
| 88 | + await waitFor(() => { |
| 89 | + expect( |
| 90 | + screen.queryByTestId(selectors.components.queryEditor.logsQueryEditor.container.input) |
| 91 | + ).toBeInTheDocument(); |
| 92 | + expect( |
| 93 | + screen.queryByTestId(selectors.components.queryEditor.logsQueryBuilder.container.input) |
| 94 | + ).not.toBeInTheDocument(); |
| 95 | + }); |
| 96 | + }); |
| 97 | + |
| 98 | + it('renders the Logs code editor when there is no existing query and the builder is disabled', async () => { |
| 99 | + config.featureToggles.azureMonitorLogsBuilderEditor = false; |
| 100 | + const mockDatasource = createMockDatasource(); |
| 101 | + const mockQuery = { |
| 102 | + ...createMockQuery(), |
| 103 | + queryType: AzureQueryType.LogAnalytics, |
| 104 | + }; |
| 105 | + delete mockQuery.azureLogAnalytics?.query; |
| 106 | + |
| 107 | + render(<QueryEditor query={mockQuery} datasource={mockDatasource} onChange={() => {}} onRunQuery={() => {}} />); |
| 108 | + await waitFor(() => { |
| 109 | + expect( |
| 110 | + screen.queryByTestId(selectors.components.queryEditor.logsQueryEditor.container.input) |
| 111 | + ).toBeInTheDocument(); |
| 112 | + expect( |
| 113 | + screen.queryByTestId(selectors.components.queryEditor.logsQueryBuilder.container.input) |
| 114 | + ).not.toBeInTheDocument(); |
| 115 | + }); |
| 116 | + }); |
| 117 | + |
| 118 | + it('renders the Logs builder when there is no existing query and the builder is enabled', async () => { |
| 119 | + config.featureToggles.azureMonitorLogsBuilderEditor = true; |
| 120 | + const mockDatasource = createMockDatasource(); |
| 121 | + const mockQuery = { |
| 122 | + ...createMockQuery(), |
| 123 | + queryType: AzureQueryType.LogAnalytics, |
| 124 | + }; |
| 125 | + delete mockQuery.azureLogAnalytics?.query; |
| 126 | + |
| 127 | + render(<QueryEditor query={mockQuery} datasource={mockDatasource} onChange={() => {}} onRunQuery={() => {}} />); |
| 128 | + await waitFor(() => { |
| 129 | + expect( |
| 130 | + screen.queryByTestId(selectors.components.queryEditor.logsQueryEditor.container.input) |
| 131 | + ).toBeInTheDocument(); |
| 132 | + expect( |
| 133 | + screen.queryByTestId(selectors.components.queryEditor.logsQueryBuilder.container.input) |
| 134 | + ).not.toBeInTheDocument(); |
| 135 | + }); |
| 136 | + }); |
| 137 | + |
70 | 138 | it('renders the ARG query editor when the query type is ARG', async () => {
|
71 | 139 | const mockDatasource = createMockDatasource();
|
72 | 140 | const mockQuery = {
|
|
0 commit comments