implement analytics too
Signed-off-by: Fredrik Adelöw <freben@gmail.com>
This commit is contained in:
@@ -20,7 +20,7 @@ import userEvent from '@testing-library/user-event';
|
||||
import { configApiRef } from '@backstage/core-plugin-api';
|
||||
import { ConfigReader } from '@backstage/core-app-api';
|
||||
import {
|
||||
MockAnalyticsApi,
|
||||
mockApis,
|
||||
TestApiProvider,
|
||||
renderInTestApp,
|
||||
} from '@backstage/test-utils';
|
||||
@@ -273,7 +273,7 @@ describe('SearchBar', () => {
|
||||
});
|
||||
|
||||
it('Does not capture analytics event if not enabled in app', async () => {
|
||||
const analyticsApiMock = new MockAnalyticsApi();
|
||||
const analyticsApiMock = mockApis.analytics();
|
||||
|
||||
await renderInTestApp(
|
||||
<TestApiProvider
|
||||
@@ -296,7 +296,7 @@ describe('SearchBar', () => {
|
||||
|
||||
await waitFor(() => expect(textbox).toHaveValue(value));
|
||||
|
||||
expect(analyticsApiMock.getEvents()).toHaveLength(0);
|
||||
expect(analyticsApiMock.captureEvent).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it('Renders custom search icon', async () => {
|
||||
|
||||
@@ -24,7 +24,7 @@ import DocsIcon from '@material-ui/icons/InsertDriveFile';
|
||||
import {
|
||||
renderInTestApp,
|
||||
TestApiProvider,
|
||||
MockAnalyticsApi,
|
||||
mockApis,
|
||||
} from '@backstage/test-utils';
|
||||
import { createPlugin, analyticsApiRef } from '@backstage/core-plugin-api';
|
||||
|
||||
@@ -40,7 +40,7 @@ import {
|
||||
|
||||
const query = jest.fn().mockResolvedValue({ results: [] });
|
||||
const searchApiMock = { query };
|
||||
const analyticsApiMock = new MockAnalyticsApi();
|
||||
const analyticsApiMock = mockApis.analytics();
|
||||
|
||||
describe('SearchResultGroup', () => {
|
||||
const results = [
|
||||
|
||||
@@ -20,7 +20,7 @@ import { screen, waitFor } from '@testing-library/react';
|
||||
import {
|
||||
TestApiProvider,
|
||||
renderInTestApp,
|
||||
MockAnalyticsApi,
|
||||
mockApis,
|
||||
} from '@backstage/test-utils';
|
||||
import { analyticsApiRef, createPlugin } from '@backstage/core-plugin-api';
|
||||
|
||||
@@ -31,7 +31,7 @@ import { SearchResultList } from './SearchResultList';
|
||||
|
||||
const query = jest.fn().mockResolvedValue({ results: [] });
|
||||
const searchApiMock = { query };
|
||||
const analyticsApiMock = new MockAnalyticsApi();
|
||||
const analyticsApiMock = mockApis.analytics();
|
||||
|
||||
describe('SearchResultList', () => {
|
||||
const results = [
|
||||
|
||||
@@ -422,9 +422,7 @@ describe('SearchContext', () => {
|
||||
|
||||
describe('analytics', () => {
|
||||
it('captures analytics events if enabled in app', async () => {
|
||||
const analyticsApiMock = {
|
||||
captureEvent: jest.fn(),
|
||||
} satisfies typeof analyticsApiRef.T;
|
||||
const analyticsApiMock = mockApis.analytics();
|
||||
|
||||
searchApiMock.query.mockResolvedValue({
|
||||
results: [],
|
||||
@@ -481,9 +479,7 @@ describe('SearchContext', () => {
|
||||
});
|
||||
|
||||
it('captures analytics events even if number of results does not exist', async () => {
|
||||
const analyticsApiMock = {
|
||||
captureEvent: jest.fn(),
|
||||
} satisfies typeof analyticsApiRef.T;
|
||||
const analyticsApiMock = mockApis.analytics();
|
||||
|
||||
searchApiMock.query.mockResolvedValue({
|
||||
results: [],
|
||||
|
||||
@@ -23,7 +23,7 @@ import ListItemText from '@material-ui/core/ListItemText';
|
||||
import {
|
||||
renderInTestApp,
|
||||
TestApiProvider,
|
||||
MockAnalyticsApi,
|
||||
mockApis,
|
||||
} from '@backstage/test-utils';
|
||||
import {
|
||||
createPlugin,
|
||||
@@ -38,7 +38,7 @@ import {
|
||||
SearchResultListItemExtensionOptions,
|
||||
} from './extensions';
|
||||
|
||||
const analyticsApiMock = new MockAnalyticsApi();
|
||||
const analyticsApiMock = mockApis.analytics();
|
||||
|
||||
const results = [
|
||||
{
|
||||
@@ -118,7 +118,7 @@ describe('extensions', () => {
|
||||
screen.getByRole('link', { name: /Search Result 1/ }),
|
||||
);
|
||||
|
||||
expect(analyticsApiMock.getEvents()[0]).toMatchObject({
|
||||
expect(analyticsApiMock.captureEvent).toHaveBeenCalledWith({
|
||||
action: 'discover',
|
||||
subject: 'Search Result 1',
|
||||
context: { routeRef: 'unknown', pluginId: 'root', extension: 'App' },
|
||||
@@ -141,7 +141,7 @@ describe('extensions', () => {
|
||||
|
||||
await userEvent.click(screen.getByRole('listitem'));
|
||||
|
||||
expect(analyticsApiMock.getEvents()[0]).toMatchObject({
|
||||
expect(analyticsApiMock.captureEvent).toHaveBeenCalledWith({
|
||||
action: 'discover',
|
||||
subject: 'Search Result 1',
|
||||
context: { routeRef: 'unknown', pluginId: 'root', extension: 'App' },
|
||||
|
||||
Reference in New Issue
Block a user