add test for Lookup clearing QS params

This commit is contained in:
Keith Grant 2019-09-12 15:48:17 -07:00
parent 26e320582a
commit e854b179e4
2 changed files with 30 additions and 1 deletions

View File

@ -186,7 +186,7 @@ class Lookup extends React.Component {
const { history } = this.props;
const parts = history.location.search.replace(/^\?/, '').split('&');
const ns = this.qsConfig.namespace;
const otherParts = parts.filter(param => !param.startsWith(`${ns}.`))
const otherParts = parts.filter(param => !param.startsWith(`${ns}.`));
history.push(`${history.location.pathname}?${otherParts.join('&')}`);
}

View File

@ -359,4 +359,33 @@ describe('<Lookup />', () => {
expect(getItems).toHaveBeenCalledTimes(2);
done();
});
test('should clear its query params when closed', async () => {
mockData = [{ name: 'foo', id: 1, isChecked: false }];
const history = createMemoryHistory({
initialEntries: ['/organizations/add?inventory.name=foo&bar=baz'],
});
wrapper = mountWithContexts(
<_Lookup
multiple
name="foo"
lookupHeader="Foo Bar"
onLookupSave={() => {}}
value={mockData}
columns={mockColumns}
sortedColumnKey="name"
getItems={() => {}}
location={{ history }}
history={history}
qsNamespace="inventory"
i18n={{ _: val => val.toString() }}
/>
);
wrapper
.find('InputGroup Button')
.at(0)
.invoke('onClick')();
wrapper.find('Modal').invoke('onClose')();
expect(history.location.search).toEqual('?bar=baz');
});
});