From bab2ae85a5c28dd68cae01697feda3c040ba0eff Mon Sep 17 00:00:00 2001 From: Emma Indal Date: Mon, 14 Nov 2022 10:40:50 +0100 Subject: [PATCH] write test for capturing rank prop Signed-off-by: Emma Indal --- ...StackOverflowSearchResultListItem.test.tsx | 40 ++++++++++++++++++- 1 file changed, 39 insertions(+), 1 deletion(-) 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, + }); + }); });