|
7 | 7 |
|
8 | 8 | import React from 'react'; |
9 | 9 | import { chartPluginMock } from '@kbn/charts-plugin/public/mocks'; |
10 | | -import { coreMock as mockCoreMock } from '@kbn/core/public/mocks'; |
| 10 | +import { coreMock } from '@kbn/core/public/mocks'; |
11 | 11 | import { __IntlProvider as IntlProvider } from '@kbn/i18n-react'; |
12 | 12 | import { ALERT_RULE_PARAMETERS } from '@kbn/rule-data-utils'; |
13 | 13 | import type { ParsedTechnicalFields } from '@kbn/rule-registry-plugin/common'; |
@@ -51,27 +51,46 @@ jest.mock('../../../rule_condition_chart/rule_condition_chart', () => ({ |
51 | 51 | RuleConditionChart: jest.fn(() => <div data-test-subj="RuleConditionChart" />), |
52 | 52 | })); |
53 | 53 |
|
54 | | -jest.mock('../../../../utils/kibana_react', () => ({ |
55 | | - useKibana: () => ({ |
56 | | - services: { |
57 | | - ...mockCoreMock.createStart(), |
58 | | - charts: mockedChartStartContract, |
59 | | - aiops: { |
60 | | - EmbeddableChangePointChart: jest.fn(), |
| 54 | +jest.mock('./log_rate_analysis', () => ({ |
| 55 | + LogRateAnalysis: jest.fn(() => <div data-test-subj="LogRateAnalysis" />), |
| 56 | +})); |
| 57 | + |
| 58 | +const mockServices = { |
| 59 | + ...coreMock.createStart(), |
| 60 | + charts: mockedChartStartContract, |
| 61 | + aiops: { |
| 62 | + EmbeddableChangePointChart: jest.fn(), |
| 63 | + }, |
| 64 | + data: { |
| 65 | + search: { |
| 66 | + searchSource: { |
| 67 | + create: jest.fn().mockResolvedValue({ |
| 68 | + getField: jest.fn().mockReturnValue({ id: 'test-index' }), |
| 69 | + }), |
61 | 70 | }, |
62 | | - data: { |
63 | | - search: jest.fn(), |
| 71 | + }, |
| 72 | + }, |
| 73 | + share: { |
| 74 | + url: { |
| 75 | + locators: { |
| 76 | + get: jest |
| 77 | + .fn() |
| 78 | + .mockReturnValue({ getRedirectUrl: jest.fn().mockReturnValue('/view-in-app-url') }), |
64 | 79 | }, |
65 | | - share: { |
66 | | - url: { |
67 | | - locators: { |
68 | | - get: jest |
69 | | - .fn() |
70 | | - .mockReturnValue({ getRedirectUrl: jest.fn().mockReturnValue('/view-in-app-url') }), |
71 | | - }, |
72 | | - }, |
| 80 | + }, |
| 81 | + }, |
| 82 | + application: { |
| 83 | + capabilities: { |
| 84 | + aiops: { |
| 85 | + enabled: false, |
73 | 86 | }, |
74 | 87 | }, |
| 88 | + }, |
| 89 | +}; |
| 90 | + |
| 91 | +jest.mock('../../../../utils/kibana_react', () => ({ |
| 92 | + useKibana: () => ({ |
| 93 | + services: mockServices, |
75 | 94 | }), |
76 | 95 | })); |
77 | 96 |
|
@@ -146,4 +165,54 @@ describe('AlertDetailsAppSection', () => { |
146 | 165 | 'Equation result for min (system.memory.used.pct) + min (system.memory.used.pct) + min (system.memory.used.pct)' |
147 | 166 | ); |
148 | 167 | }); |
| 168 | + |
| 169 | + it('should not render LogRateAnalysis when aiops is disabled', () => { |
| 170 | + const result = renderComponent(); |
| 171 | + expect(result.queryByTestId('LogRateAnalysis')).not.toBeInTheDocument(); |
| 172 | + }); |
| 173 | + |
| 174 | + it('should not render LogRateAnalysis when aiops is disabled and has evaluation values', () => { |
| 175 | + const result = renderComponent({}, { |
| 176 | + 'kibana.alert.evaluation.values': [2500, 5], |
| 177 | + } as Object); |
| 178 | + expect(result.queryByTestId('LogRateAnalysis')).not.toBeInTheDocument(); |
| 179 | + }); |
| 180 | + |
| 181 | + it('should render LogRateAnalysis when aiops is enabled and has evaluation values', () => { |
| 182 | + mockServices.application.capabilities.aiops.enabled = true; |
| 183 | + const result = renderComponent({}, { |
| 184 | + 'kibana.alert.evaluation.values': [2500, 5], |
| 185 | + } as Object); |
| 186 | + expect(result.getByTestId('LogRateAnalysis')).toBeTruthy(); |
| 187 | + }); |
| 188 | + |
| 189 | + it('should not render LogRateAnalysis when hasEvaluationValues is false', () => { |
| 190 | + mockServices.application.capabilities.aiops.enabled = true; |
| 191 | + const result = renderComponent({}, { |
| 192 | + 'kibana.alert.evaluation.values': [null, null], |
| 193 | + } as Object); |
| 194 | + expect(result.queryByTestId('LogRateAnalysis')).not.toBeInTheDocument(); |
| 195 | + }); |
| 196 | + |
| 197 | + it('should render LogRateAnalysis when hasEvaluationValues has some null but also some values', () => { |
| 198 | + mockServices.application.capabilities.aiops.enabled = true; |
| 199 | + const result = renderComponent({}, { |
| 200 | + 'kibana.alert.evaluation.values': [null, 5], |
| 201 | + } as Object); |
| 202 | + expect(result.getByTestId('LogRateAnalysis')).toBeTruthy(); |
| 203 | + }); |
| 204 | + |
| 205 | + it('should render LogRateAnalysis even when criteria array is empty if conditions are met', () => { |
| 206 | + mockServices.application.capabilities.aiops.enabled = true; |
| 207 | + const result = renderComponent({}, { |
| 208 | + [ALERT_RULE_PARAMETERS]: { |
| 209 | + ...buildCustomThresholdRule().params, |
| 210 | + criteria: [], |
| 211 | + } as Object, |
| 212 | + 'kibana.alert.evaluation.values': [2500, 5], |
| 213 | + } as Object); |
| 214 | + // Even with empty criteria, it renders the container and LogRateAnalysis if aiops is enabled |
| 215 | + expect(result.queryByTestId('thresholdAlertOverviewSection')).toBeInTheDocument(); |
| 216 | + expect(result.queryByTestId('LogRateAnalysis')).toBeInTheDocument(); |
| 217 | + }); |
149 | 218 | }); |
0 commit comments