Skip to content

Commit

Permalink
Merge 1388dee into 4d7c0cb
Browse files Browse the repository at this point in the history
  • Loading branch information
yen-tt committed Jun 17, 2021
2 parents 4d7c0cb + 1388dee commit 329d0bd
Show file tree
Hide file tree
Showing 6 changed files with 40 additions and 6 deletions.
6 changes: 3 additions & 3 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
],
"dependencies": {
"@mapbox/mapbox-gl-language": "^0.10.1",
"@yext/answers-core": "^1.2.0-alpha.0",
"@yext/answers-core": "^1.3.0-alpha.0",
"@yext/answers-storage": "^1.1.0",
"@yext/rtf-converter": "^1.5.0",
"cross-fetch": "^3.0.6",
Expand Down
5 changes: 5 additions & 0 deletions src/core/core.js
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,7 @@ export default class Core {
if (!verticalResults || verticalResults.searchState !== SearchStates.SEARCH_LOADING) {
this.storage.set(StorageKeys.VERTICAL_RESULTS, VerticalResults.searchLoading());
}
this.storage.set(StorageKeys.DIRECT_ANSWER, {});
this.storage.set(StorageKeys.SPELL_CHECK, {});
this.storage.set(StorageKeys.LOCATION_BIAS, LocationBias.searchLoading());
}
Expand Down Expand Up @@ -258,8 +259,12 @@ export default class Core {
const mergedResults = this.storage.get(StorageKeys.VERTICAL_RESULTS)
.append(data[StorageKeys.VERTICAL_RESULTS]);
this.storage.set(StorageKeys.VERTICAL_RESULTS, mergedResults);
if(data[StorageKeys.DIRECT_ANSWER].answer) {
this.storage.set(StorageKeys.DIRECT_ANSWER, data[StorageKeys.DIRECT_ANSWER]);
}
} else {
this.storage.set(StorageKeys.VERTICAL_RESULTS, data[StorageKeys.VERTICAL_RESULTS]);
this.storage.set(StorageKeys.DIRECT_ANSWER, data[StorageKeys.DIRECT_ANSWER]);
}

if (data[StorageKeys.DYNAMIC_FILTERS]) {
Expand Down
1 change: 1 addition & 0 deletions src/core/search/searchdatatransformer.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ export default class SearchDataTransformer {
return {
[StorageKeys.QUERY_ID]: response.queryId,
[StorageKeys.NAVIGATION]: new Navigation(), // Vertical doesn't respond with ordering, so use empty nav.
[StorageKeys.DIRECT_ANSWER]: DirectAnswer.fromCore(response.directAnswer, formatters),
[StorageKeys.VERTICAL_RESULTS]: VerticalResults.fromCore(
response.verticalResults, {}, formatters, resultsContext, verticalKey),
[StorageKeys.DYNAMIC_FILTERS]: DynamicFilters.fromCore(response.facets, resultsContext),
Expand Down
4 changes: 2 additions & 2 deletions src/ui/components/results/directanswercomponent.js
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ export default class DirectAnswerComponent extends Component {
verticalKey: relatedItem.verticalConfigId,
directAnswer: true,
fieldName: this.getState('answer').fieldApiName,
searcher: 'UNIVERSAL',
searcher: this._config.isUniversal ? 'UNIVERSAL' : 'VERTICAL',
entityId: relatedItem.data.id,
url: event.target.href
};
Expand Down Expand Up @@ -215,7 +215,7 @@ export default class DirectAnswerComponent extends Component {
}
return JSON.stringify({
verticalConfigId: data.relatedItem.verticalConfigId,
searcher: 'UNIVERSAL',
searcher: this._config.isUniversal ? 'UNIVERSAL' : 'VERTICAL',
entityId: data.relatedItem.data.id,
ctaLabel: this._viewDetailsText.toUpperCase().replace(' ', '_')
});
Expand Down
28 changes: 28 additions & 0 deletions tests/core/search/searchdatatransformer.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import ResponseWithResults from '../../fixtures/responseWithResults.json';
import ResponseWithoutResults from '../../fixtures/responseWithNoResults.json';
import ResultsContext from '../../../src/core/storage/resultscontext';
import AlternativeVerticals from '../../../src/core/models/alternativeverticals';
import DirectAnswer from '../../../src/core/models/directanswer';

describe('tranform vertical search response', () => {
let response;
Expand All @@ -22,10 +23,13 @@ describe('tranform vertical search response', () => {
it('transforms vertical response correctly with results', () => {
const data = response;
const result = SearchDataTransformer.transformVertical(data);
const formatters = {};

expect(result).toEqual(
{
[StorageKeys.QUERY_ID]: data.queryId,
[StorageKeys.NAVIGATION]: new Navigation(), // Vertical doesn't respond with ordering, so use empty nav.
[StorageKeys.DIRECT_ANSWER]: DirectAnswer.fromCore(response.directAnswer, formatters),
[StorageKeys.VERTICAL_RESULTS]: VerticalResults.fromCore(data.verticalResults, {}, {}, ResultsContext.NORMAL),
[StorageKeys.DYNAMIC_FILTERS]: DynamicFilters.fromCore(data.facets, ResultsContext.NORMAL),
[StorageKeys.SPELL_CHECK]: SpellCheck.fromCore(data.spellCheck),
Expand All @@ -39,10 +43,13 @@ describe('tranform vertical search response', () => {
const data = responseWithNoResults;
const result = SearchDataTransformer.transformVertical(data);
const convertedResponse = SearchDataTransformer._reshapeForNoResults(data);
const formatters = {};

expect(result).toEqual(
{
[StorageKeys.QUERY_ID]: convertedResponse.queryId,
[StorageKeys.NAVIGATION]: new Navigation(), // Vertical doesn't respond with ordering, so use empty nav.
[StorageKeys.DIRECT_ANSWER]: DirectAnswer.fromCore(response.directAnswer, formatters),
[StorageKeys.VERTICAL_RESULTS]: VerticalResults.fromCore(
convertedResponse.verticalResults, {}, {}, ResultsContext.NO_RESULTS),
[StorageKeys.DYNAMIC_FILTERS]: DynamicFilters.fromCore(convertedResponse.facets, ResultsContext.NO_RESULTS),
Expand Down Expand Up @@ -100,6 +107,23 @@ describe('forming no results response', () => {
}
]
},
directAnswer: {
type: 'FEATURED_SNIPPET',
relatedResult: {
rawData: {},
source: 'KNOWLEDGE_MANAGER'
},
verticalKey: 'help_articles',
snippet: {
value: 'Lorem ipsum dolor sit amet.\n consectetur adipiscing elit.',
matchedSubstrings: [
{
offset: 0,
length: 10
}
]
}
},
appliedQueryFilters: []
};
});
Expand All @@ -116,6 +140,7 @@ describe('forming no results response', () => {
results: [],
resultsCount: 0,
allResultsForVertical: [],
directAnswer: {},
appliedQueryFilters: []
};
const convertedResponse = SearchDataTransformer._reshapeForNoResults(responseEmptyResults);
Expand All @@ -125,6 +150,7 @@ describe('forming no results response', () => {
facets: undefined,
resultsCount: 0,
allResultsForVertical: [],
directAnswer: {},
appliedQueryFilters: []
});
});
Expand All @@ -133,6 +159,7 @@ describe('forming no results response', () => {
const responseEmptyResults = {
results: [],
resultsCount: 0,
directAnswer: {},
appliedQueryFilters: []
};
const convertedResponse = SearchDataTransformer._reshapeForNoResults(responseEmptyResults);
Expand All @@ -141,6 +168,7 @@ describe('forming no results response', () => {
results: [],
facets: undefined,
resultsCount: 0,
directAnswer: {},
appliedQueryFilters: []
});
});
Expand Down

0 comments on commit 329d0bd

Please sign in to comment.