Skip to content

Commit

Permalink
refactor(headless): migrate logParametersChange (#3460)
Browse files Browse the repository at this point in the history
* change name of old function

https://coveord.atlassian.net/browse/KIT-2905

* new next function and tests

https://coveord.atlassian.net/browse/KIT-2905

* migrate searchBox/submit

https://coveord.atlassian.net/browse/KIT-2933

* revert optional legacy analytics

https://coveord.atlassian.net/browse/KIT-2933

* hard coded values in tests

https://coveord.atlassian.net/browse/KIT-2905

* insight case not using the right interface..

https://coveord.atlassian.net/browse/KIT-2933

* add support for search box submit

https://coveord.atlassian.net/browse/KIT-2905

* beter interfaces

https://coveord.atlassian.net/browse/KIT-2933

* never use coreSearchBox

https://coveord.atlassian.net/browse/KIT-2933

* fix test

https://coveord.atlassian.net/browse/KIT-2933

* remove firstResult and numberOfResult analytics check

https://coveord.atlassian.net/browse/KIT-2905

* put back interfaceLoad

https://coveord.atlassian.net/browse/KIT-2905

* Update search-parameter-analytics-actions.test.ts

https://coveord.atlassian.net/browse/KIT-2905

* refactor(headless): migrate searchboxAsYouType event (#3472)

refactor(headless): migrate searchboxAsYouType

https://coveord.atlassian.net/browse/KIT-2942

* ensure paramChanges uses fExcluded when relevant

https://coveord.atlassian.net/browse/KIT-2905

---------

Co-authored-by: Louis Bompart <lbompart@coveo.com>
  • Loading branch information
alexprudhomme and louis-bompart authored Jan 26, 2024
1 parent c133f5d commit c249e63
Show file tree
Hide file tree
Showing 4 changed files with 348 additions and 78 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,10 @@ import {getDebugInitialState} from '../../features/debug/debug-state';
import {getPaginationInitialState} from '../../features/pagination/pagination-state';
import {getQueryInitialState} from '../../features/query/query-state';
import {SearchParameters} from '../../features/search-parameters/search-parameter-actions';
import {logParametersChange} from '../../features/search-parameters/search-parameter-analytics-actions';
import {
legacyLogParametersChange,
parametersChange,
} from '../../features/search-parameters/search-parameter-analytics-actions';
import {executeSearch} from '../../features/search/search-actions';
import {StaticFilterValue} from '../../features/static-filter-set/static-filter-set-state';
import {SearchParametersState} from '../../state/search-app-state';
Expand Down Expand Up @@ -59,7 +62,10 @@ export function buildSearchParameterManager(

controller.synchronize(parameters);
dispatch(
executeSearch({legacy: logParametersChange(oldParams, newParams)})
executeSearch({
legacy: legacyLogParametersChange(oldParams, newParams),
next: parametersChange(oldParams, newParams),
})
);
},

Expand Down
Original file line number Diff line number Diff line change
@@ -1,22 +1,38 @@
import {buildMockSearchAppEngine} from '../../test';
import {logInterfaceChange} from '../analytics/analytics-actions';
import {
interfaceChange,
logInterfaceChange,
} from '../analytics/analytics-actions';
import {LegacySearchAction} from '../analytics/analytics-utils';
import {
logFacetClearAll,
logFacetDeselect,
logFacetSelect,
logFacetExclude,
facetDeselect,
facetClearAll,
facetExclude,
logFacetUnexclude,
} from '../facets/facet-set/facet-set-analytics-actions';
import {
logPageNumber,
logPagerResize,
} from '../pagination/pagination-analytics-actions';
import {logSearchboxSubmit} from '../query/query-analytics-actions';
import {logResultsSort} from '../sort-criteria/sort-criteria-analytics-actions';
import {logParametersChange} from './search-parameter-analytics-actions';
import {
logSearchboxSubmit,
searchboxSubmit,
} from '../query/query-analytics-actions';
import {
logResultsSort,
resultsSort,
} from '../sort-criteria/sort-criteria-analytics-actions';
import {
legacyLogParametersChange,
parametersChange,
} from './search-parameter-analytics-actions';
import {logParametersChange} from './search-parameter-insight-analytics-actions';

describe('logParametersChange', () => {
describe('legacyLogParametersChange', () => {
function expectIdenticalActionType(
action1: LegacySearchAction,
action2: LegacySearchAction
Expand All @@ -29,67 +45,67 @@ describe('logParametersChange', () => {

it('should log #logSearchboxSubmit when #q parameter changes', () => {
expectIdenticalActionType(
logParametersChange({}, {q: 'test'}),
legacyLogParametersChange({}, {q: 'test'}),
logSearchboxSubmit()
);
});

it('should log #logResultsSort when #sortCriteria parameter changes', () => {
expectIdenticalActionType(
logParametersChange({}, {sortCriteria: 'size ascending'}),
legacyLogParametersChange({}, {sortCriteria: 'size ascending'}),
logResultsSort()
);
});

it('should log #logPageNumber when #firstResult parameter changes', () => {
expectIdenticalActionType(
logParametersChange({}, {firstResult: 10}),
legacyLogParametersChange({}, {firstResult: 10}),
logPageNumber()
);
});

it('should log #logPagerResize when #firstResult parameter changes', () => {
expectIdenticalActionType(
logParametersChange({}, {numberOfResults: 25}),
legacyLogParametersChange({}, {numberOfResults: 25}),
logPagerResize()
);
});

testFacetSelectLogging('f', expectIdenticalActionType);
legacyTestFacetSelectLogging('f', expectIdenticalActionType);

testFacetSelectLogging('af', expectIdenticalActionType);
legacyTestFacetSelectLogging('af', expectIdenticalActionType);

testFacetSelectLogging('cf', expectIdenticalActionType);
legacyTestFacetSelectLogging('cf', expectIdenticalActionType);

testFacetExcludeLogging(expectIdenticalActionType);
legacyTestFacetExcludeLogging(expectIdenticalActionType);

it('should log a generic #logInterfaceChange when an unmanaged parameter', () => {
expectIdenticalActionType(
logParametersChange({}, {cq: 'hello'}),
legacyLogParametersChange({}, {cq: 'hello'}),
logInterfaceChange()
);
});
});

function testFacetSelectLogging(
function legacyTestFacetSelectLogging(
parameter: string,
expectIdenticalActionType: (
action1: LegacySearchAction,
action2: LegacySearchAction
) => void
) {
testFacetLogging(parameter, expectIdenticalActionType);
legacyTestFacetLogging(parameter, expectIdenticalActionType);

it(`should log #logFacetSelect when an ${parameter} parameter is added`, () => {
expectIdenticalActionType(
logParametersChange({}, {[parameter]: {author: ['Cervantes']}}),
legacyLogParametersChange({}, {[parameter]: {author: ['Cervantes']}}),
logFacetSelect({facetId: 'author', facetValue: 'Cervantes'})
);
});

it(`should log #logFacetSelect when an ${parameter} parameter is modified & a value added`, () => {
expectIdenticalActionType(
logParametersChange(
legacyLogParametersChange(
{[parameter]: {author: ['Cervantes']}},
{[parameter]: {author: ['Cervantes', 'Orwell']}}
),
Expand All @@ -98,13 +114,13 @@ function testFacetSelectLogging(
});
}

function testFacetExcludeLogging(
function legacyTestFacetExcludeLogging(
expectIdenticalActionType: (
action1: LegacySearchAction,
action2: LegacySearchAction
) => void
) {
it('should log #logFacetDeselect when an fExcluded parameter with a single value is removed', () => {
it('should log #logFacetUnexclude when an fExcluded parameter with a single value is removed', () => {
expectIdenticalActionType(
logParametersChange({fExcluded: {author: ['Cervantes']}}, {}),
logFacetUnexclude({facetId: 'author', facetValue: 'Cervantes'})
Expand All @@ -118,7 +134,7 @@ function testFacetExcludeLogging(
);
});

it('should log #logFacetDeselect when an fExcluded parameter is modified & a value removed', () => {
it('should log #logFacetUnexclude when an fExcluded parameter is modified & a value removed', () => {
expectIdenticalActionType(
logParametersChange(
{fExcluded: {author: ['Cervantes', 'Orwell']}},
Expand All @@ -130,14 +146,14 @@ function testFacetExcludeLogging(

it('should log #logFacetSelect when an fExcluded parameter is added', () => {
expectIdenticalActionType(
logParametersChange({}, {fExcluded: {author: ['Cervantes']}}),
legacyLogParametersChange({}, {fExcluded: {author: ['Cervantes']}}),
logFacetExclude({facetId: 'author', facetValue: 'Cervantes'})
);
});

it('should log #logFacetSelect when an fExcluded parameter is modified & a value added', () => {
expectIdenticalActionType(
logParametersChange(
legacyLogParametersChange(
{fExcluded: {author: ['Cervantes']}},
{fExcluded: {author: ['Cervantes', 'Orwell']}}
),
Expand All @@ -146,7 +162,7 @@ function testFacetExcludeLogging(
});
}

function testFacetLogging(
function legacyTestFacetLogging(
parameter: string,
expectIdenticalActionType: (
action1: LegacySearchAction,
Expand All @@ -155,25 +171,113 @@ function testFacetLogging(
) {
it(`should log #logFacetDeselect when an ${parameter} parameter with a single value is removed`, () => {
expectIdenticalActionType(
logParametersChange({[parameter]: {author: ['Cervantes']}}, {}),
legacyLogParametersChange({[parameter]: {author: ['Cervantes']}}, {}),
logFacetDeselect({facetId: 'author', facetValue: 'Cervantes'})
);
});

it(`should log #logFacetClearAll when an ${parameter} parameter with multiple values is removed`, () => {
expectIdenticalActionType(
logParametersChange({[parameter]: {author: ['Cervantes', 'Orwell']}}, {}),
legacyLogParametersChange(
{[parameter]: {author: ['Cervantes', 'Orwell']}},
{}
),
logFacetClearAll('author')
);
});

it(`should log #logFacetDeselect when an ${parameter} parameter is modified & a value removed`, () => {
expectIdenticalActionType(
logParametersChange(
legacyLogParametersChange(
{[parameter]: {author: ['Cervantes', 'Orwell']}},
{[parameter]: {author: ['Cervantes']}}
),
logFacetDeselect({facetId: 'author', facetValue: 'Orwell'})
);
});
}

// --------------------- KIT-2859 : Everything above this will get deleted ! :) ---------------------
const ANY_FACET_ID = 'author';
const ANY_FACET_VALUE = 'Cervantes';

function testFacetExcludeLogging() {
testFacetSelectLogging('fExcluded');

it('should log #facetSelect when an fExcluded parameter is added', () => {
const action = parametersChange({}, {fExcluded: {author: ['Cervantes']}});

expect(action.actionCause).toEqual(
facetExclude(ANY_FACET_ID, ANY_FACET_VALUE).actionCause
);
});

it('should log #facetSelect when an fExcluded parameter is modified & a value added', () => {
const action = parametersChange(
{fExcluded: {author: ['Cervantes']}},
{fExcluded: {author: ['Cervantes', 'Orwell']}}
);

expect(action.actionCause).toEqual(
facetExclude(ANY_FACET_ID, ANY_FACET_VALUE).actionCause
);
});
}

describe('parametersChange', () => {
it('should log #searchboxSubmit when #q parameter changes', () => {
const action = parametersChange({}, {q: 'test'});

expect(action.actionCause).toEqual(searchboxSubmit().actionCause);
});

it('should log #resultsSort when #sortCriteria parameter changes', () => {
const action = parametersChange({}, {sortCriteria: 'size ascending'});

expect(action.actionCause).toEqual(resultsSort().actionCause);
});

testFacetSelectLogging('f');

testFacetSelectLogging('af');

testFacetSelectLogging('cf');

testFacetExcludeLogging();

it('should log a generic #interfaceLoad when an unmanaged parameter', () => {
const action = parametersChange({}, {cq: 'hello'});

expect(action.actionCause).toEqual(interfaceChange().actionCause);
});
});

function testFacetSelectLogging(parameter: string) {
it(`should log #facetDeselect when an ${parameter} parameter with a single value is removed`, () => {
const action = parametersChange({[parameter]: {author: ['Cervantes']}}, {});

expect(action.actionCause).toEqual(
facetDeselect(ANY_FACET_ID, ANY_FACET_VALUE).actionCause
);
});

it(`should log #facetClearAll when an ${parameter} parameter with multiple values is removed`, () => {
const action = parametersChange(
{[parameter]: {author: ['Cervantes', 'Orwell']}},
{}
);

expect(action.actionCause).toEqual(facetClearAll(ANY_FACET_ID).actionCause);
});

it(`should log #facetDeselect when an ${parameter} parameter is modified & a value removed`, () => {
const action = parametersChange(
{[parameter]: {author: ['Cervantes', 'Orwell']}},
{[parameter]: {author: ['Cervantes']}}
);

expect(action.actionCause).toEqual(
facetDeselect(ANY_FACET_ID, ANY_FACET_VALUE).actionCause
);
});
}
Loading

0 comments on commit c249e63

Please sign in to comment.