implement analytics too

Signed-off-by: Fredrik Adelöw <freben@gmail.com>
This commit is contained in:
Fredrik Adelöw
2024-10-08 17:51:14 +02:00
parent 40bfc240c7
commit 811ff0cddc
23 changed files with 196 additions and 153 deletions
@@ -16,12 +16,11 @@
import { TechDocsNotFound } from './TechDocsNotFound';
import React from 'react';
import { render, screen, waitFor } from '@testing-library/react';
import { screen, waitFor } from '@testing-library/react';
import {
MockAnalyticsApi,
mockApis,
TestApiProvider,
renderInTestApp,
wrapInTestApp,
} from '@backstage/test-utils';
import { analyticsApiRef } from '@backstage/core-plugin-api';
@@ -58,18 +57,16 @@ describe('<TechDocsNotFound />', () => {
});
it('should trigger analytics event not-found', async () => {
const mockAnalyticsApi = new MockAnalyticsApi();
const mockAnalyticsApi = mockApis.analytics();
render(
wrapInTestApp(
<TestApiProvider apis={[[analyticsApiRef, mockAnalyticsApi]]}>
<TechDocsNotFound />
</TestApiProvider>,
),
await renderInTestApp(
<TestApiProvider apis={[[analyticsApiRef, mockAnalyticsApi]]}>
<TechDocsNotFound />
</TestApiProvider>,
);
await waitFor(() => {
expect(mockAnalyticsApi.getEvents()[0]).toMatchObject({
expect(mockAnalyticsApi.captureEvent).toHaveBeenCalledWith({
action: 'not-found',
subject: '/the/pathname?the=search#the-anchor',
attributes: {
@@ -77,6 +74,7 @@ describe('<TechDocsNotFound />', () => {
namespace: 'namespace',
kind: 'kind',
},
context: expect.anything(),
});
});
});