-
Notifications
You must be signed in to change notification settings - Fork 35
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(headless): quick view event for insight use case made an Insight…
…Panel.ItemAction (#4136) ## [SFINT-5581](https://coveord.atlassian.net/browse/SFINT-5581) - Quick view event sent in the insight use case updated to be an `InsightPanel.ItemClick` event according to the latest schemas of the `@coveo/relay-event-types` library. - Unit tests added. [SFINT-5581]: https://coveord.atlassian.net/browse/SFINT-5581?atlOrigin=eyJpIjoiNWRkNTljNzYxNjVmNDY3MDlhMDU5Y2ZhYzA5YTRkZjUiLCJwIjoiZ2l0aHViLWNvbS1KU1cifQ
- Loading branch information
Showing
7 changed files
with
240 additions
and
10 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
24 changes: 24 additions & 0 deletions
24
...atures/result-preview/__snapshots__/result-preview-insight-analytics-actions.test.ts.snap
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
// Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
||
exports[`#logDocumentQuickview when analyticsMode is \`next\` should call relay.emit properly 1`] = ` | ||
[ | ||
"InsightPanel.ItemAction", | ||
{ | ||
"action": "preview", | ||
"context": { | ||
"caseNumber": "5678", | ||
"targetId": "1234", | ||
"targetType": "Case", | ||
}, | ||
"itemMetadata": { | ||
"author": "example author", | ||
"title": "example documentTitle", | ||
"uniqueFieldName": "permanentid", | ||
"uniqueFieldValue": "example contentIDValue", | ||
"url": "example documentUri", | ||
}, | ||
"position": 1, | ||
"searchUid": "example searchUid", | ||
}, | ||
] | ||
`; |
170 changes: 170 additions & 0 deletions
170
...ges/headless/src/features/result-preview/result-preview-insight-analytics-actions.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,170 @@ | ||
import {createRelay} from '@coveo/relay'; | ||
import {InsightEngine} from '../../app/insight-engine/insight-engine'; | ||
import {ThunkExtraArguments} from '../../app/thunk-extra-arguments'; | ||
import {buildMockInsightEngine} from '../../test/mock-engine-v2'; | ||
import {buildMockInsightState} from '../../test/mock-insight-state'; | ||
import {buildMockRaw} from '../../test/mock-raw'; | ||
import {buildMockResult} from '../../test/mock-result'; | ||
import {buildMockSearchResponse} from '../../test/mock-search-response'; | ||
import {buildMockSearchState} from '../../test/mock-search-state'; | ||
import {clearMicrotaskQueue} from '../../test/unit-test-utils'; | ||
import {getConfigurationInitialState} from '../configuration/configuration-state'; | ||
import {logDocumentQuickview} from './result-preview-insight-analytics-actions'; | ||
|
||
jest.mock('@coveo/relay'); | ||
jest.mock('coveo.analytics'); | ||
|
||
const mockLogDocumentQuickview = jest.fn(); | ||
const emit = jest.fn(); | ||
|
||
jest.mock('coveo.analytics', () => { | ||
const mockCoveoInsightClient = jest.fn(() => ({ | ||
disable: () => {}, | ||
logDocumentQuickview: mockLogDocumentQuickview, | ||
})); | ||
|
||
return { | ||
CoveoInsightClient: mockCoveoInsightClient, | ||
history: {HistoryStore: jest.fn()}, | ||
}; | ||
}); | ||
|
||
jest.mocked(createRelay).mockReturnValue({ | ||
emit, | ||
getMeta: jest.fn(), | ||
on: jest.fn(), | ||
off: jest.fn(), | ||
updateConfig: jest.fn(), | ||
clearStorage: jest.fn(), | ||
version: 'foo', | ||
}); | ||
|
||
const exampleSubject = 'example subject'; | ||
const exampleDescription = 'example description'; | ||
const exampleCaseId = '1234'; | ||
const exampleCaseNumber = '5678'; | ||
const caseContextState = { | ||
caseContext: { | ||
Case_Subject: exampleSubject, | ||
Case_Description: exampleDescription, | ||
}, | ||
caseId: exampleCaseId, | ||
caseNumber: exampleCaseNumber, | ||
}; | ||
|
||
const expectedDocumentInfo = { | ||
queryPipeline: '', | ||
documentUri: 'example documentUri', | ||
documentUriHash: 'example documentUriHash', | ||
collectionName: 'example collectionName', | ||
sourceName: 'example sourceName', | ||
documentPosition: 1, | ||
documentTitle: 'example documentTitle', | ||
documentUrl: 'example documentUrl', | ||
rankingModifier: 'example rankingModifier', | ||
documentAuthor: 'example author', | ||
}; | ||
|
||
const expectedDocumentIdentifier = { | ||
contentIDKey: 'permanentid', | ||
contentIDValue: 'example contentIDValue', | ||
}; | ||
|
||
const resultParams = { | ||
title: 'example documentTitle', | ||
uri: 'example documentUri', | ||
printableUri: 'printable-uri', | ||
clickUri: 'example documentUrl', | ||
uniqueId: 'unique-id', | ||
excerpt: 'excerpt', | ||
firstSentences: 'first-sentences', | ||
flags: 'flags', | ||
rankingModifier: 'example rankingModifier', | ||
raw: buildMockRaw({ | ||
author: 'example author', | ||
urihash: 'example documentUriHash', | ||
source: 'example sourceName', | ||
collection: 'example collectionName', | ||
permanentid: 'example contentIDValue', | ||
}), | ||
}; | ||
|
||
const testResult = buildMockResult(resultParams); | ||
|
||
describe('#logDocumentQuickview', () => { | ||
let engine: InsightEngine; | ||
const searchState = buildMockSearchState({ | ||
results: [testResult], | ||
response: buildMockSearchResponse({ | ||
searchUid: 'example searchUid', | ||
}), | ||
}); | ||
|
||
afterEach(() => { | ||
jest.clearAllMocks(); | ||
}); | ||
|
||
describe('when analyticsMode is `legacy`', () => { | ||
beforeEach(() => { | ||
engine = buildMockInsightEngine( | ||
buildMockInsightState({ | ||
search: searchState, | ||
configuration: { | ||
...getConfigurationInitialState(), | ||
analytics: { | ||
...getConfigurationInitialState().analytics, | ||
analyticsMode: 'legacy', | ||
}, | ||
}, | ||
}) | ||
); | ||
}); | ||
|
||
it('should call coveo.analytics.logDocumentQuickview properly', async () => { | ||
await logDocumentQuickview(testResult)()( | ||
engine.dispatch, | ||
() => engine.state, | ||
{} as ThunkExtraArguments | ||
); | ||
await clearMicrotaskQueue(); | ||
|
||
expect(mockLogDocumentQuickview).toHaveBeenCalledTimes(1); | ||
expect(mockLogDocumentQuickview.mock.calls[0][0]).toStrictEqual( | ||
expectedDocumentInfo | ||
); | ||
expect(mockLogDocumentQuickview.mock.calls[0][1]).toStrictEqual( | ||
expectedDocumentIdentifier | ||
); | ||
}); | ||
}); | ||
|
||
describe('when analyticsMode is `next`', () => { | ||
beforeEach(() => { | ||
engine = buildMockInsightEngine( | ||
buildMockInsightState({ | ||
search: searchState, | ||
configuration: { | ||
...getConfigurationInitialState(), | ||
analytics: { | ||
...getConfigurationInitialState().analytics, | ||
analyticsMode: 'next', | ||
}, | ||
}, | ||
insightCaseContext: caseContextState, | ||
}) | ||
); | ||
}); | ||
|
||
it('should call relay.emit properly', async () => { | ||
await logDocumentQuickview(testResult)()( | ||
engine.dispatch, | ||
() => engine.state, | ||
{} as ThunkExtraArguments | ||
); | ||
await clearMicrotaskQueue(); | ||
|
||
expect(emit).toHaveBeenCalledTimes(1); | ||
expect(emit.mock.calls[0]).toMatchSnapshot(); | ||
}); | ||
}); | ||
}); |
34 changes: 34 additions & 0 deletions
34
packages/headless/src/features/result-preview/result-preview-insight-analytics-actions.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import {InsightPanel} from '@coveo/relay-event-types'; | ||
import {Result} from '../../api/search/search/result'; | ||
import { | ||
ClickAction, | ||
analyticsEventItemMetadata, | ||
documentIdentifier, | ||
makeInsightAnalyticsActionFactory, | ||
partialDocumentInformation, | ||
validateResultPayload, | ||
} from '../analytics/analytics-utils'; | ||
import {analyticsEventCaseContext} from '../analytics/insight-analytics-utils'; | ||
|
||
export const logDocumentQuickview = (result: Result): ClickAction => { | ||
return makeInsightAnalyticsActionFactory('')({ | ||
prefix: 'analytics/resultPreview/open', | ||
__legacy__getBuilder: (client, state) => { | ||
validateResultPayload(result); | ||
const info = partialDocumentInformation(result, state); | ||
const id = documentIdentifier(result); | ||
client.logDocumentQuickview(info, id); | ||
}, | ||
analyticsType: 'InsightPanel.ItemAction', | ||
analyticsPayloadBuilder: (state): InsightPanel.ItemAction => { | ||
const information = partialDocumentInformation(result, state); | ||
return { | ||
action: 'preview', | ||
itemMetadata: analyticsEventItemMetadata(result, state), | ||
position: information.documentPosition, | ||
searchUid: state.search?.response.searchUid || '', | ||
context: analyticsEventCaseContext(state), | ||
}; | ||
}, | ||
}); | ||
}; |