From 4ba54410e15b9808ff0feae4062701eea0f1e2d0 Mon Sep 17 00:00:00 2001 From: Oliver Shi Date: Tue, 8 Jun 2021 13:40:36 -0400 Subject: [PATCH 1/4] bump version to 1.8.4 --- package-lock.json | 2 +- package.json | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/package-lock.json b/package-lock.json index 0acfceff5..c2ae50d6f 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,6 +1,6 @@ { "name": "@yext/answers-search-ui", - "version": "1.8.3", + "version": "1.8.4", "lockfileVersion": 1, "requires": true, "dependencies": { diff --git a/package.json b/package.json index 61fe7b737..5b071ae87 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@yext/answers-search-ui", - "version": "1.8.3", + "version": "1.8.4", "description": "Javascript Answers Programming Interface", "main": "dist/answers-umd.js", "repository": { From 868b706a13f0dec9dde97eaa5fa6643b92c1070f Mon Sep 17 00:00:00 2001 From: Oliver Shi Date: Wed, 9 Jun 2021 08:08:29 -0400 Subject: [PATCH 2/4] fix facets not being persisted when applied from the URL (#1429) When sending facets in a search request, there is logic that first checks whether FACET_FILTER_NODES exist. If none exist, we default to using whatever was persisted in the URL. The issue was that this logic was not being duplicated for persisting facets in the URL. If facets were applied from the URL on a search run on page load, for example, we would try to persist facets using the FACET_FILTER_NODE state on page load, which would be no filter nodes existing. Defaulting this to whatever is persisted in the URL fixes the issue. J=SLAP-1377 TEST=manual,auto saw that I can double refresh the page with facets applied from the url, and also that the back and forwards buttons work for facets added a additional refresh and forward nav actions to the facetsonload acceptance test to test double refreshing and forward naving with facets from the URL added a new facetsonload.html for this test, with the only difference being searchOnChange: true for facets (which is the default as well as more common config setting) --- src/core/core.js | 2 +- src/core/filters/filterregistry.js | 21 +- .../acceptancesuites/facetsonload.js | 17 +- .../fixtures/html/facetsonload.html | 193 ++++++++++++++++++ tests/acceptance/server.js | 1 + tests/core/filters/filterregistry.js | 33 ++- 6 files changed, 253 insertions(+), 14 deletions(-) create mode 100644 tests/acceptance/fixtures/html/facetsonload.html diff --git a/src/core/core.js b/src/core/core.js index 6b0651ce1..6e8e8a6bb 100644 --- a/src/core/core.js +++ b/src/core/core.js @@ -681,7 +681,7 @@ export default class Core { * Persists the current `facetFilters` state into the URL. */ _persistFacets () { - const persistedFacets = this.filterRegistry.createFacetsFromFilterNodes(); + const persistedFacets = this.filterRegistry.getFacets(); this.storage.setWithPersist(StorageKeys.PERSISTED_FACETS, persistedFacets); } diff --git a/src/core/filters/filterregistry.js b/src/core/filters/filterregistry.js index 7d0b769ec..b572425ed 100644 --- a/src/core/filters/filterregistry.js +++ b/src/core/filters/filterregistry.js @@ -172,9 +172,10 @@ export default class FilterRegistry { /** * Combines the active facet FilterNodes into a single Facet + * * @returns {Facet} */ - createFacetsFromFilterNodes () { + _createFacetsFromFilterNodes () { const getFilters = fn => fn.getChildren().length ? fn.getChildren().flatMap(getFilters) : fn.getFilter(); @@ -183,16 +184,24 @@ export default class FilterRegistry { } /** - * Gets the facet filters as an array of Filters to send to the answers-core. + * Returns the current Facets state. * - * @returns {Facet[]} from answers-core + * @returns {Facet} */ - getFacetsPayload () { + getFacets () { const hasFacetFilterNodes = this.storage.has(StorageKeys.FACET_FILTER_NODES); - const facets = hasFacetFilterNodes - ? this.createFacetsFromFilterNodes() + return hasFacetFilterNodes + ? this._createFacetsFromFilterNodes() : this.storage.get(StorageKeys.PERSISTED_FACETS) || {}; + } + /** + * Gets the facet filters as an array of Filters to send to the answers-core. + * + * @returns {Facet[]} from answers-core + */ + getFacetsPayload () { + const facets = this.getFacets(); const coreFacets = Object.entries(facets).map(([fieldId, filterArray]) => { return { fieldId: fieldId, diff --git a/tests/acceptance/acceptancesuites/facetsonload.js b/tests/acceptance/acceptancesuites/facetsonload.js index e64ff946b..d7b7f9718 100644 --- a/tests/acceptance/acceptancesuites/facetsonload.js +++ b/tests/acceptance/acceptancesuites/facetsonload.js @@ -1,13 +1,14 @@ import { setupServer, shutdownServer, - FACETS_PAGE + FACETS_ON_LOAD_PAGE } from '../server'; import FacetsPage from '../pageobjects/facetspage'; import { RequestLogger } from 'testcafe'; import { browserBackButton, browserRefreshPage, + browserForwardButton, registerIE11NoCacheHook } from '../utils'; import { getMostRecentQueryParamsFromLogger } from '../requestUtils'; @@ -15,7 +16,7 @@ import { getMostRecentQueryParamsFromLogger } from '../requestUtils'; fixture`Facets page` .before(setupServer) .after(shutdownServer) - .page`${FACETS_PAGE}`; + .page`${FACETS_ON_LOAD_PAGE}`; test(`Facets work with back/forward navigation and page refresh`, async t => { const logger = RequestLogger({ @@ -42,7 +43,6 @@ test(`Facets work with back/forward navigation and page refresh`, async t => { let options; options = await filterBox.getFilterOptions('Employee Department'); await options.toggleOption('Client Delivery'); - await filterBox.applyFilters(); currentFacets = await getFacetsFromRequest(); const state1 = { 'c_puppyPreference': [], @@ -55,7 +55,6 @@ test(`Facets work with back/forward navigation and page refresh`, async t => { options = await filterBox.getFilterOptions('Employee Department'); await options.toggleOption('Technology'); - await filterBox.applyFilters(); currentFacets = await getFacetsFromRequest(); const state2 = { 'c_employeeDepartment': [ @@ -68,7 +67,6 @@ test(`Facets work with back/forward navigation and page refresh`, async t => { options = await filterBox.getFilterOptions('Puppy Preference'); await options.toggleOption('Frodo'); - await filterBox.applyFilters(); currentFacets = await getFacetsFromRequest(); const state3 = { 'c_puppyPreference': [{ 'c_puppyPreference': { '$eq': 'Frodo' } }], @@ -87,6 +85,11 @@ test(`Facets work with back/forward navigation and page refresh`, async t => { await t.expect(currentFacets).eql(state3); logger.clear(); + await browserRefreshPage(); + currentFacets = await getFacetsFromRequest(); + await t.expect(currentFacets).eql(state3); + logger.clear(); + await browserBackButton(); currentFacets = await getFacetsFromRequest(); await t.expect(currentFacets).eql(state2); @@ -99,4 +102,8 @@ test(`Facets work with back/forward navigation and page refresh`, async t => { await browserBackButton(); currentFacets = await getFacetsFromRequest(); await t.expect(currentFacets).eql({}); + + await browserForwardButton(); + currentFacets = await getFacetsFromRequest(); + await t.expect(currentFacets).eql(state1); }); diff --git a/tests/acceptance/fixtures/html/facetsonload.html b/tests/acceptance/fixtures/html/facetsonload.html new file mode 100644 index 000000000..453aa0859 --- /dev/null +++ b/tests/acceptance/fixtures/html/facetsonload.html @@ -0,0 +1,193 @@ + + + + + + + + + + + + +
+
+ +
+
+
+
+
+
+
+
+
+
+
+
+
+ + + + + diff --git a/tests/acceptance/server.js b/tests/acceptance/server.js index e77f209d8..6e9f81183 100644 --- a/tests/acceptance/server.js +++ b/tests/acceptance/server.js @@ -24,5 +24,6 @@ export async function shutdownServer (ctx) { export const UNIVERSAL_PAGE = 'http://localhost:9999/tests/acceptance/fixtures/html/universal'; export const VERTICAL_PAGE = 'http://localhost:9999/tests/acceptance/fixtures/html/vertical'; export const FACETS_PAGE = 'http://localhost:9999/tests/acceptance/fixtures/html/facets'; +export const FACETS_ON_LOAD_PAGE = 'http://localhost:9999/tests/acceptance/fixtures/html/facetsonload'; export const FILTERBOX_PAGE = 'http://localhost:9999/tests/acceptance/fixtures/html/filterbox'; export const UNIVERSAL_INITIAL_SEARCH_PAGE = 'http://localhost:9999/tests/acceptance/fixtures/html/universalinitialsearch'; diff --git a/tests/core/filters/filterregistry.js b/tests/core/filters/filterregistry.js index e99c3e7ba..199721660 100644 --- a/tests/core/filters/filterregistry.js +++ b/tests/core/filters/filterregistry.js @@ -284,7 +284,7 @@ describe('FilterRegistry', () => { }); }); - it('createFacetsFromFilterNodes', () => { + it('_createFacetsFromFilterNodes', () => { registry.setFacetFilterNodes([ 'random_field', 'another_field' ], [node1, node2]); const expectedFacets = { 'another_field': [], @@ -292,7 +292,36 @@ describe('FilterRegistry', () => { 'c_2': [{ 'c_2': { '$eq': '2' } }], 'random_field': [] }; - expect(registry.createFacetsFromFilterNodes()).toEqual(expectedFacets); + expect(registry._createFacetsFromFilterNodes()).toEqual(expectedFacets); + }); + + it('getFacets defaults to the current state of PERSISTED_FACETS if no filter nodes exist', () => { + const persistedFacets = { + c_employeeDepartment: [ + { + c_employeeDepartment: { + $eq: 'International Dang Sales' + } + } + ] + }; + registry.storage.set(StorageKeys.PERSISTED_FACETS, persistedFacets); + expect(registry.getFacets()).toEqual(persistedFacets); + }); + + it('getFacets uses FACET_FILTER_NODES if they exist', () => { + registry.setFacetFilterNodes([ 'random_field', 'another_field' ], [node1, node2]); + const persistedFacets = { + c_employeeDepartment: [ + { + c_employeeDepartment: { + $eq: 'International Dang Sales' + } + } + ] + }; + registry.storage.set(StorageKeys.PERSISTED_FACETS, persistedFacets); + expect(registry.getFacets()).toEqual(registry._createFacetsFromFilterNodes()); }); it('transforms static filters with multiple matchers into combined filters', () => { From 713bd6a9b41282121071c40151b4411f8221b435 Mon Sep 17 00:00:00 2001 From: Tom Meyer Date: Wed, 9 Jun 2021 08:22:27 -0400 Subject: [PATCH 3/4] Update third party notices. --- THIRD-PARTY-NOTICES | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/THIRD-PARTY-NOTICES b/THIRD-PARTY-NOTICES index a3a4196d2..c3c3cbaa1 100644 --- a/THIRD-PARTY-NOTICES +++ b/THIRD-PARTY-NOTICES @@ -304,7 +304,7 @@ MIT License The following NPM packages may be included in this product: - - @yext/answers-core@1.2.0-alpha.0 + - @yext/answers-core@1.1.0 These packages each contain the following license and notice below: @@ -342,8 +342,8 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. The following NPM packages may be included in this product: - - @yext/answers-search-ui@1.8.3 - - @yext/answers-storage@1.1.0 + - @yext/answers-search-ui@1.8.4 + - @yext/answers-storage@1.0.0-beta.0 These packages each contain the following license and notice below: @@ -3872,7 +3872,7 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. The following NPM packages may be included in this product: - - handlebars@4.7.7 + - handlebars@4.7.6 These packages each contain the following license and notice below: @@ -8017,7 +8017,7 @@ PERFORMANCE OF THIS SOFTWARE. The following NPM packages may be included in this product: - - uglify-js@3.13.4 + - uglify-js@3.12.1 These packages each contain the following license and notice below: From a366b7f44557a27f025782b17f64af9ca6520cb9 Mon Sep 17 00:00:00 2001 From: Tom Meyer Date: Wed, 9 Jun 2021 08:33:08 -0400 Subject: [PATCH 4/4] Fix notices. --- THIRD-PARTY-NOTICES | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/THIRD-PARTY-NOTICES b/THIRD-PARTY-NOTICES index c3c3cbaa1..7e0a02daf 100644 --- a/THIRD-PARTY-NOTICES +++ b/THIRD-PARTY-NOTICES @@ -304,7 +304,7 @@ MIT License The following NPM packages may be included in this product: - - @yext/answers-core@1.1.0 + - @yext/answers-core@1.2.0-alpha.0 These packages each contain the following license and notice below: @@ -343,7 +343,7 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. The following NPM packages may be included in this product: - @yext/answers-search-ui@1.8.4 - - @yext/answers-storage@1.0.0-beta.0 + - @yext/answers-storage@1.1.0 These packages each contain the following license and notice below: @@ -3872,7 +3872,7 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. The following NPM packages may be included in this product: - - handlebars@4.7.6 + - handlebars@4.7.7 These packages each contain the following license and notice below: @@ -8017,7 +8017,7 @@ PERFORMANCE OF THIS SOFTWARE. The following NPM packages may be included in this product: - - uglify-js@3.12.1 + - uglify-js@3.13.4 These packages each contain the following license and notice below: