Skip to content

Commit

Permalink
fix(toggleRefinement): don't set off value in getWidgetRenderState (#…
Browse files Browse the repository at this point in the history
…4912)

This was added in the migration from render to getWidgetRenderState, but actually getWidgetSearchParameters already takes this in account, and i can't find any situations where "off" gets erased.

Added a test to make sure getWidgetAttribute works when "off" is given, but it's straightforward now
  • Loading branch information
Haroenv authored Sep 30, 2021
1 parent 019cd18 commit 69525bf
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 8 deletions.
8 changes: 0 additions & 8 deletions src/connectors/toggle-refinement/connectToggleRefinement.ts
Original file line number Diff line number Diff line change
Expand Up @@ -340,14 +340,6 @@ const connectToggleRefinement: ToggleRefinementConnector =
offData.reduce((acc, v) => acc + v.count, 0) ||
allFacetValues.reduce((total, { count }) => total + count, 0),
};
} else if (hasAnOffValue && !isRefined) {
if (off) {
off.forEach((v) =>
helper.addDisjunctiveFacetRefinement(attribute, v)
);
}

helper.setPage(helper.state.page!);
}

if (!sendEvent) {
Expand Down
15 changes: 15 additions & 0 deletions src/lib/utils/__tests__/getWidgetAttribute-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import {
hits,
panel,
refinementList,
toggleRefinement,
} from '../../../widgets';

describe('getWidgetAttribute', () => {
Expand Down Expand Up @@ -42,6 +43,20 @@ describe('getWidgetAttribute', () => {
).toBe('test1');
});

it('reads the attribute from a toggleRefinement', () => {
expect(
getWidgetAttribute(
toggleRefinement({
container: document.createElement('div'),
attribute: 'test',
on: 'yes',
off: 'no',
}),
createInitOptions()
)
).toBe('test');
});

it('reads the attribute from a panel', () => {
expect(
getWidgetAttribute(
Expand Down

0 comments on commit 69525bf

Please sign in to comment.