Skip to content

Commit

Permalink
Merge branch 'master' into KIT-3312
Browse files Browse the repository at this point in the history
  • Loading branch information
jpmarceau authored Jul 26, 2024
2 parents c72a957 + bcecc55 commit a7e1651
Show file tree
Hide file tree
Showing 9 changed files with 123 additions and 108 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,7 @@ import {facetResponseActiveValuesSelector} from '../../features/facets/facet-set
import {facetSetReducer as facetSet} from '../../features/facets/facet-set/facet-set-slice';
import {FacetSlice} from '../../features/facets/facet-set/facet-set-state';
import {FacetValue} from '../../features/facets/facet-set/interfaces/response';
import {
breadcrumbResetAll,
logClearBreadcrumbs,
} from '../../features/facets/generic/facet-generic-analytics-actions';
import {logClearBreadcrumbs} from '../../features/facets/generic/facet-generic-analytics-actions';
import {
toggleExcludeDateFacetValue,
toggleSelectDateFacetValue,
Expand Down Expand Up @@ -393,7 +390,6 @@ export function buildBreadcrumbManager(
dispatch(
executeSearch({
legacy: logClearBreadcrumbs(),
next: breadcrumbResetAll(),
})
);
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import {
setId,
streamAnswer,
} from '../../../features/generated-answer/generated-answer-actions';
import {rephraseGeneratedAnswer} from '../../../features/generated-answer/generated-answer-analytics-actions';
import {generatedAnswerReducer as generatedAnswer} from '../../../features/generated-answer/generated-answer-slice';
import {executeSearch} from '../../../features/search/search-actions';
import {
Expand Down Expand Up @@ -167,6 +168,7 @@ export function buildSearchAPIGeneratedAnswer(
engine.dispatch(
executeSearch({
legacy: analyticsClient.logRephraseGeneratedAnswer(responseFormat),
next: rephraseGeneratedAnswer(),
})
);
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ import {logFacetBreadcrumb} from '../../../features/facets/facet-set/facet-set-i
import {facetResponseActiveValuesSelector} from '../../../features/facets/facet-set/facet-set-selectors';
import {facetSetReducer as facetSet} from '../../../features/facets/facet-set/facet-set-slice';
import {FacetSlice} from '../../../features/facets/facet-set/facet-set-state';
import {breadcrumbResetAll} from '../../../features/facets/generic/facet-generic-analytics-actions';
import {logClearBreadcrumbs} from '../../../features/facets/generic/facet-generic-insight-analytics-actions';
import {
toggleExcludeDateFacetValue,
Expand Down Expand Up @@ -296,7 +295,6 @@ export function buildBreadcrumbManager(
dispatch(
executeSearch({
legacy: logClearBreadcrumbs(),
next: breadcrumbResetAll(),
})
);
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import {
executeSearch,
fetchQuerySuggestions,
} from '../../../features/insight-search/insight-search-actions';
import {searchboxSubmit} from '../../../features/query/query-analytics-actions';
import {logSearchboxSubmit} from '../../../features/query/query-insight-analytics-actions';
import {Controller} from '../../controller/headless-controller';
import {
Expand Down Expand Up @@ -86,7 +87,7 @@ export function buildSearchBox(
return {
...searchBox,
submit() {
searchBox.submit(logSearchboxSubmit());
searchBox.submit(logSearchboxSubmit(), searchboxSubmit());
},
get state() {
return searchBox.state;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,9 @@ import {
makeAnalyticsAction,
LegacySearchAction,
} from '../../analytics/analytics-utils';
import {SearchPageEvents} from '../../analytics/search-action-cause';
import {SearchAction} from '../../search/search-actions';

//TODO: KIT-2859
export const logClearBreadcrumbs = (): LegacySearchAction =>
makeAnalyticsAction('analytics/facet/deselectAllBreadcrumbs', (client) => {
return client.makeBreadcrumbResetAll();
});

export const breadcrumbResetAll = (): SearchAction => ({
actionCause: SearchPageEvents.breadcrumbResetAll,
});
Original file line number Diff line number Diff line change
Expand Up @@ -114,10 +114,7 @@ export const executeSearch = createAsyncThunk<
config: AsyncThunkConfig
) => {
const state = config.getState();
if (
state.configuration.analytics.analyticsMode === 'legacy' ||
!analyticsAction.next
) {
if (state.configuration.analytics.analyticsMode === 'legacy') {
return legacyExecuteSearch(state, config, analyticsAction.legacy);
}

Expand All @@ -127,7 +124,9 @@ export const executeSearch = createAsyncThunk<
...config,
});

const eventDescription = buildEventDescription(analyticsAction.next);
const eventDescription = analyticsAction.next
? buildEventDescription(analyticsAction.next)
: undefined;
const request = await buildInsightSearchRequest(state, eventDescription);
const fetched = await processor.fetchFromAPI(request);

Expand All @@ -147,10 +146,7 @@ export const fetchPage = createAsyncThunk<
) => {
const state = config.getState();

if (
state.configuration.analytics.analyticsMode === 'legacy' ||
!analyticsAction.next
) {
if (state.configuration.analytics.analyticsMode === 'legacy') {
return legacyFetchPage(state, config, analyticsAction.legacy);
}

Expand All @@ -160,7 +156,9 @@ export const fetchPage = createAsyncThunk<
...config,
});

const eventDescription = buildEventDescription(analyticsAction.next);
const eventDescription = analyticsAction.next
? buildEventDescription(analyticsAction.next)
: undefined;
const request = await buildInsightSearchRequest(state, eventDescription);
const fetched = await processor.fetchFromAPI(request);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,7 @@ import {
logFacetUpdateSort,
} from '../features/facets/facet-set/facet-set-analytics-actions';
import {FacetSortCriterion} from '../features/facets/facet-set/interfaces/request';
import {
breadcrumbResetAll,
logClearBreadcrumbs,
} from '../features/facets/generic/facet-generic-analytics-actions';
import {logClearBreadcrumbs} from '../features/facets/generic/facet-generic-analytics-actions';
import {registerDateFacet} from '../features/facets/range-facets/date-facet-set/date-facet-actions';
import {
dateBreadcrumbFacet,
Expand Down Expand Up @@ -277,14 +274,13 @@ describe('Analytics Search Migration', () => {
it('analytics/facet/deselectAllBreadcrumbs', async () => {
const action = executeSearch({
legacy: logClearBreadcrumbs(),
next: breadcrumbResetAll(),
});

legacySearchEngine.dispatch(action);
nextSearchEngine.dispatch(action);
await clearMicrotaskQueue();

assertNextEqualsLegacy(callSpy);
assertNextEqualsLegacy(callSpy, [...excludedBaseProperties, 'actionCause']);
});

it('analytics/facet/exclude', async () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ import {
logFacetUpdateSort,
} from '../features/facets/facet-set/facet-set-insight-analytics-actions';
import {FacetSortCriterion} from '../features/facets/facet-set/interfaces/request';
import {breadcrumbResetAll} from '../features/facets/generic/facet-generic-analytics-actions';
import {logClearBreadcrumbs} from '../features/facets/generic/facet-generic-insight-analytics-actions';
import {registerDateFacet} from '../features/facets/range-facets/date-facet-set/date-facet-actions';
import {dateBreadcrumbFacet} from '../features/facets/range-facets/date-facet-set/date-facet-analytics-actions';
Expand Down Expand Up @@ -182,14 +181,13 @@ describe('Analytics Search Migration', () => {
it('analytics/facet/deselectAllBreadcrumbs', async () => {
const action = executeSearch({
legacy: logClearBreadcrumbs(),
next: breadcrumbResetAll(),
});

legacyInsightEngine.dispatch(action);
nextInsightEngine.dispatch(action);
await clearMicrotaskQueue();

assertNextEqualsLegacy(callSpy);
assertNextEqualsLegacy(callSpy, [...excludedBaseProperties, 'actionCause']);
});

it('analytics/facet/sortChange', async () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -153,13 +153,23 @@ describe('quantic-generated-answer', () => {
Expect.generatedAnswerIsStreaming(false);
});

it('should perform a search query with the default rephrase button', () => {
cy.wait(InterceptAliases.Search);
Expect.searchQueryContainsCorrectRephraseOption(
defaultRephraseOption,
param.useCase === 'search' ? 'interfaceLoad' : 'searchboxSubmit',
['text/markdown', 'text/plain']
);
analyticsModeTest.forEach((analytics) => {
describe(analytics.label, () => {
before(() => {
analyticsMode = analytics.mode;
});

it('should perform a search query with the default rephrase button', () => {
cy.wait(InterceptAliases.Search);
Expect.searchQueryContainsCorrectRephraseOption(
defaultRephraseOption,
param.useCase === 'search'
? 'interfaceLoad'
: 'searchboxSubmit',
['text/markdown', 'text/plain']
);
});
});
});

it('should perform a search query with the default fields to include in citations', () => {
Expand All @@ -182,31 +192,39 @@ describe('quantic-generated-answer', () => {
});
});

describe('when a value is provided to the answer style attribute', () => {
const streamId = crypto.randomUUID();

beforeEach(() => {
mockSearchWithGeneratedAnswer(streamId, param.useCase);
mockStreamResponse(streamId, genQaMessageTypePayload);
visitGeneratedAnswer({
answerStyle: bulletRephraseOption,
useCase: param.useCase,
analyticsModeTest.forEach((analytics) => {
describe(analytics.label, () => {
before(() => {
analyticsMode = analytics.mode;
});
});

it('should send a search query with the right rephrase option as a parameter', () => {
scope('when loading the page', () => {
Expect.displayRephraseButtons(true);
Expect.rephraseButtonIsSelected(stepRephraseOption, false);
Expect.rephraseButtonIsSelected(conciseRephraseOption, false);
Expect.rephraseButtonIsSelected(bulletRephraseOption, true);
Expect.searchQueryContainsCorrectRephraseOption(
bulletRephraseOption,
param.useCase === 'search'
? 'interfaceLoad'
: 'searchboxSubmit',
['text/markdown', 'text/plain']
);
describe('when a value is provided to the answer style attribute', () => {
const streamId = crypto.randomUUID();

beforeEach(() => {
mockSearchWithGeneratedAnswer(streamId, param.useCase);
mockStreamResponse(streamId, genQaMessageTypePayload);
visitGeneratedAnswer({
answerStyle: bulletRephraseOption,
useCase: param.useCase,
});
});

it('should send a search query with the right rephrase option as a parameter', () => {
scope('when loading the page', () => {
Expect.displayRephraseButtons(true);
Expect.rephraseButtonIsSelected(stepRephraseOption, false);
Expect.rephraseButtonIsSelected(conciseRephraseOption, false);
Expect.rephraseButtonIsSelected(bulletRephraseOption, true);
Expect.searchQueryContainsCorrectRephraseOption(
bulletRephraseOption,
param.useCase === 'search'
? 'interfaceLoad'
: 'searchboxSubmit',
['text/markdown', 'text/plain']
);
});
});
});
});
});
Expand Down Expand Up @@ -559,56 +577,70 @@ describe('quantic-generated-answer', () => {
});
});

rephraseOptions.forEach((option) => {
const rephraseOption = option;
analyticsModeTest.forEach((analytics) => {
describe(analytics.label, () => {
before(() => {
analyticsMode = analytics.mode;
});

describe(`when clicking the ${rephraseOption} rephrase button`, () => {
const streamId = crypto.randomUUID();
const secondStreamId = crypto.randomUUID();
rephraseOptions.forEach((option) => {
const rephraseOption = option;

beforeEach(() => {
mockSearchWithGeneratedAnswer(streamId, param.useCase);
mockStreamResponse(streamId, genQaMessageTypePayload);
visitGeneratedAnswer({useCase: param.useCase});
});
describe(`when clicking the ${rephraseOption} rephrase button`, () => {
const streamId = crypto.randomUUID();
const secondStreamId = crypto.randomUUID();

it(`should send a new search query with the rephrase option ${option} as a parameter`, () => {
scope('when loading the page', () => {
Expect.displayRephraseButtonWithLabel(rephraseOption);
const expectedRephraseButtonSelected =
option === defaultRephraseOption;
Expect.rephraseButtonIsSelected(
rephraseOption,
expectedRephraseButtonSelected
);
});
beforeEach(() => {
mockSearchWithGeneratedAnswer(streamId, param.useCase);
mockStreamResponse(streamId, genQaMessageTypePayload);
visitGeneratedAnswer({useCase: param.useCase});
});

scope('when selecting the rephrase button', () => {
mockSearchWithGeneratedAnswer(secondStreamId, param.useCase);
mockStreamResponse(secondStreamId, genQaMessageTypePayload);

Actions.clickRephraseButton(rephraseOption);
Expect.displayRephraseButtonWithLabel(rephraseOption);
Expect.rephraseButtonIsSelected(rephraseOption, true);
rephraseOptions
.filter((item) => {
return item !== rephraseOption;
})
.forEach((unselectedOption) => {
Expect.displayRephraseButtonWithLabel(unselectedOption);
Expect.rephraseButtonIsSelected(unselectedOption, false);
it(`should send a new search query with the rephrase option ${option} as a parameter`, () => {
scope('when loading the page', () => {
Expect.displayRephraseButtonWithLabel(rephraseOption);
const expectedRephraseButtonSelected =
option === defaultRephraseOption;
Expect.rephraseButtonIsSelected(
rephraseOption,
expectedRephraseButtonSelected
);
});
Expect.searchQueryContainsCorrectRephraseOption(
rephraseOption,
'rephraseGeneratedAnswer',
['text/markdown', 'text/plain']
);
if (analyticsMode === 'legacy') {
Expect.logRephraseGeneratedAnswer(
rephraseOption,
secondStreamId
);
}

scope('when selecting the rephrase button', () => {
mockSearchWithGeneratedAnswer(
secondStreamId,
param.useCase
);
mockStreamResponse(secondStreamId, genQaMessageTypePayload);

Actions.clickRephraseButton(rephraseOption);
Expect.displayRephraseButtonWithLabel(rephraseOption);
Expect.rephraseButtonIsSelected(rephraseOption, true);
rephraseOptions
.filter((item) => {
return item !== rephraseOption;
})
.forEach((unselectedOption) => {
Expect.displayRephraseButtonWithLabel(unselectedOption);
Expect.rephraseButtonIsSelected(
unselectedOption,
false
);
});
Expect.searchQueryContainsCorrectRephraseOption(
rephraseOption,
'rephraseGeneratedAnswer',
['text/markdown', 'text/plain']
);
if (analyticsMode === 'legacy') {
Expect.logRephraseGeneratedAnswer(
rephraseOption,
secondStreamId
);
}
});
});
});
});
});
Expand Down

0 comments on commit a7e1651

Please sign in to comment.