diff --git a/plugins/stack-overflow/src/search/StackOverflowSearchResultListItem/StackOverflowSearchResultListItem.test.tsx b/plugins/stack-overflow/src/search/StackOverflowSearchResultListItem/StackOverflowSearchResultListItem.test.tsx
index 61e901591e..9e27149efb 100644
--- a/plugins/stack-overflow/src/search/StackOverflowSearchResultListItem/StackOverflowSearchResultListItem.test.tsx
+++ b/plugins/stack-overflow/src/search/StackOverflowSearchResultListItem/StackOverflowSearchResultListItem.test.tsx
@@ -15,9 +15,15 @@
*/
import React from 'react';
-import { renderInTestApp } from '@backstage/test-utils';
+import {
+ MockAnalyticsApi,
+ renderInTestApp,
+ TestApiProvider,
+} from '@backstage/test-utils';
+import userEvent from '@testing-library/user-event';
import { screen } from '@testing-library/react';
import { StackOverflowSearchResultListItem } from './StackOverflowSearchResultListItem';
+import { analyticsApiRef } from '@backstage/core-plugin-api';
describe('', () => {
it('should render without exploding', async () => {
@@ -40,4 +46,36 @@ describe('', () => {
screen.getByText(/Customizing Spotify backstage UI/i).closest('a'),
).toHaveAttribute('href', 'https://stackoverflow.com/questions/7');
});
+
+ it('should capture analytics for rank', async () => {
+ const analyticsSpy = new MockAnalyticsApi();
+
+ await renderInTestApp(
+
+
+ ,
+ ,
+ );
+
+ await userEvent.click(
+ screen.getByText(/Customizing Spotify backstage UI/i),
+ );
+
+ expect(analyticsSpy.getEvents()[0]).toMatchObject({
+ action: 'discover',
+ attributes: { to: 'https://stackoverflow.com/questions/7' },
+ context: { extension: 'App', pluginId: 'root', routeRef: 'unknown' },
+ subject: 'Customizing Spotify backstage UI',
+ value: 1,
+ });
+ });
});