Skip to content

Commit

Permalink
chore(getConfiguration): burn it to the ground 🔥 (#4083)
Browse files Browse the repository at this point in the history
* chore: remove enhanceConfiguration

* chore: remove getConfiguration from types

* chore: remove getConfiguration from widgets

* test(autocomplete): replace getConfiguration tests

* chore: remove enhanceConfiguration test

* test(refinementlist): replace getConfiguration tests

* test(pagination): replace getConfiguration test

* test(searchbox): replace getConfiguration tests

* test(configure): replace getConfiguration in tests

* test(ratingMenu): update usage of getConfiguration

* test(breadcrumb): move getConfiguration tests

* test(hitsPerPage): migrate getConfiguration tests

* test(infinitehits): remove duplicate getConfiguration tests

* test(stats): remove useless (common) test

* chore: update comment

* test(toggleRefinement): swap getConfiguration usages

* test(refinementlist): migrate getConfiguration tests

* test(clear): remove useless assertion

* test(current): remove useless assertion

* test(menu): update calls

* test(pagination): !fixup

* test(hierarchical-menu): remove redundant tests

* test(sortBy): remove redundant tests

* test(hits): remove redundant tests

* test: remove redundant tests

* test(range): update getConfiguration tests (with caveats)

* !fixup linting

* chore(test): remove commented code

* chore: fix message

Co-Authored-By: Yannick Croissant <yannick.croissant@gmail.com>

* fix(range): apply min/max to getWidgetSearchParameters (#4088)

* fix(connectRange): apply min/max

* fix(connectRange): throw an error when max is lower than min

* test(hpp): cleaner test without snapshots
  • Loading branch information
Haroenv authored and samouss committed Sep 17, 2019
1 parent 64ee334 commit b4d02d1
Show file tree
Hide file tree
Showing 56 changed files with 794 additions and 2,206 deletions.
106 changes: 49 additions & 57 deletions src/connectors/autocomplete/__tests__/connectAutocomplete-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,6 @@ search.addWidgets([
init: expect.any(Function),
render: expect.any(Function),
dispose: expect.any(Function),
getConfiguration: expect.any(Function),
})
);
});
Expand Down Expand Up @@ -312,61 +311,6 @@ search.addWidgets([
expect(rendering.indices[0].results.hits).toEqual(hits);
});

describe('getConfiguration', () => {
it('takes the existing `query` from the `SearchParameters`', () => {
const render = jest.fn();
const makeWidget = connectAutocomplete(render);
const widget = makeWidget({});

const nextConfiguation = widget.getConfiguration!(
new SearchParameters({
query: 'First query',
})
);

expect(nextConfiguation.query).toBe('First query');
});

it('adds a `query` to the `SearchParameters`', () => {
const render = jest.fn();
const makeWidget = connectAutocomplete(render);
const widget = makeWidget({});

const nextConfiguation = widget.getConfiguration!(new SearchParameters());

expect(nextConfiguation.query).toBe('');
});

it('adds the TAG_PLACEHOLDER to the `SearchParameters`', () => {
const render = jest.fn();
const makeWidget = connectAutocomplete(render);
const widget = makeWidget({});

const nextConfiguation = widget.getConfiguration!(new SearchParameters());

expect(nextConfiguation.highlightPreTag).toBe(
TAG_PLACEHOLDER.highlightPreTag
);

expect(nextConfiguation.highlightPostTag).toBe(
TAG_PLACEHOLDER.highlightPostTag
);
});

it('does not add the TAG_PLACEHOLDER to the `SearchParameters` with `escapeHTML` disabled', () => {
const render = jest.fn();
const makeWidget = connectAutocomplete(render);
const widget = makeWidget({
escapeHTML: false,
});

const nextConfiguation = widget.getConfiguration!(new SearchParameters());

expect(nextConfiguation.highlightPreTag).toBeUndefined();
expect(nextConfiguation.highlightPostTag).toBeUndefined();
});
});

describe('dispose', () => {
it('calls the unmount function', () => {
const searchClient = createSearchClient();
Expand Down Expand Up @@ -501,7 +445,7 @@ search.addWidgets([
});
});

test('should give back the same instance if the value is alreay in the uiState', () => {
test('should give back the same instance if the value is already in the uiState', () => {
const [widget, helper, refine] = getInitializedWidget();
refine('query');
const uiStateBefore = widget.getWidgetState(
Expand Down Expand Up @@ -565,5 +509,53 @@ search.addWidgets([
})
);
});

test('does not add highlight tags if escapeHTML is false', () => {
const [widget, helper] = getInitializedWidget({
escapeHTML: false,
});

expect(helper.state).toEqual(
new SearchParameters({
index: '',
})
);

const actual = widget.getWidgetSearchParameters(helper.state, {
uiState: {},
});

expect(actual).toEqual(
new SearchParameters({
index: '',
query: '',
})
);
});

test('overrides query from search parameters', () => {
const [widget, helper] = getInitializedWidget();

helper.setQuery('Zeppelin manufacturer');

expect(helper.state).toEqual(
new SearchParameters({
index: '',
query: 'Zeppelin manufacturer',
})
);

const actual = widget.getWidgetSearchParameters(helper.state, {
uiState: {},
});

expect(actual).toEqual(
new SearchParameters({
index: '',
query: '',
...TAG_PLACEHOLDER,
})
);
});
});
});
15 changes: 0 additions & 15 deletions src/connectors/autocomplete/connectAutocomplete.ts
Original file line number Diff line number Diff line change
Expand Up @@ -101,21 +101,6 @@ search.addWidgets([
return {
$$type: 'ais.autocomplete',

getConfiguration(previousParameters) {
const parameters = {
query: previousParameters.query || '',
};

if (!escapeHTML) {
return previousParameters.setQueryParameters(parameters);
}

return previousParameters.setQueryParameters({
...parameters,
...TAG_PLACEHOLDER,
});
},

init({ instantSearchInstance, helper }) {
connectorState.refine = (query: string) => {
helper.setQuery(query).search();
Expand Down
Loading

0 comments on commit b4d02d1

Please sign in to comment.