Skip to content

Commit

Permalink
add test for tracking route usage
Browse files Browse the repository at this point in the history
  • Loading branch information
alvarezmelissa87 committed Sep 22, 2023
1 parent 67fc696 commit 8c6bc9d
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ export interface LogRateAnalysisContentProps {
barHighlightColorOverride?: string;
/** Optional callback that exposes data of the completed analysis */
onAnalysisCompleted?: (d: LogRateAnalysisResultsData) => void;
/** Optional identifyer to indicate the plugin utilizing the component */
/** Optional identifier to indicate the plugin utilizing the component */
source?: string;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ export interface LogRateAnalysisContentWrapperProps {
onAnalysisCompleted?: (d: LogRateAnalysisResultsData) => void;
/** Optional flag to indicate whether kibana is running in serverless */
isServerless?: boolean;
/** Optional identifyer to indicate the plugin utilizing the component */
/** Optional identifier to indicate the plugin utilizing the component */
source?: string;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ interface LogRateAnalysisResultsProps {
barHighlightColorOverride?: string;
/** Optional callback that exposes data of the completed analysis */
onAnalysisCompleted?: (d: LogRateAnalysisResultsData) => void;
/** Optional identifyer to indicate the plugin utilizing the component */
/** Optional identifier to indicate the plugin utilizing the component */
source?: string;
}

Expand Down
32 changes: 32 additions & 0 deletions x-pack/plugins/aiops/server/lib/track_route_usage.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0; you may not use this file except in compliance with the Elastic License
* 2.0.
*/
import { usageCountersServiceMock } from '@kbn/usage-collection-plugin/server/usage_counters/usage_counters_service.mock';
import { trackAIOpsRouteUsage } from './track_route_usage';

describe('trackAIOpsRouteUsage', () => {
it('should call `usageCounter.incrementCounter`', () => {
const mockUsageCountersSetup = usageCountersServiceMock.createSetupContract();
const mockUsageCounter = mockUsageCountersSetup.createUsageCounter('test');

trackAIOpsRouteUsage('test_type', 'test_source', mockUsageCounter);
expect(mockUsageCounter.incrementCounter).toHaveBeenCalledWith({
counterName: 'test_source',
counterType: 'test_type',
incrementBy: 1,
});
});

it('should do nothing if no usage counter is provided', () => {
let err;
try {
trackAIOpsRouteUsage('test', undefined);
} catch (e) {
err = e;
}
expect(err).toBeUndefined();
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,7 @@ export const LogRateAnalysis: FC<AlertDetailsLogRateAnalysisSectionProps> = ({ r
</EuiFlexItem>
<EuiFlexItem>
<LogRateAnalysisContent
source="observability_alerts"
source="observability_alert_details"
dataView={dataView}
timeRange={timeRange}
esSearchQuery={esSearchQuery}
Expand Down

0 comments on commit 8c6bc9d

Please sign in to comment.