Commit 4dddf170 authored by Justin Ho's avatar Justin Ho

Fix search functionality in Jira issues list

A recent change (still unidentified) changed the way
FilteredSearchBar sends back its `filters` object in the
`onFilter` event.

In particular, the free text filter changed from a string value
to an object with the key `filtered-search-term`. This
caused an regression in the Jira issues list as we were lacking
specs around the free text search functionality.

This fix updates the code to follow the next object structure
and adds specs to make sure it doesn't break again.
parent 14d6ca06
...@@ -333,15 +333,19 @@ export default { ...@@ -333,15 +333,19 @@ export default {
this.fetchIssuables(); this.fetchIssuables();
}, },
handleFilter(filters) { handleFilter(filters) {
let search = null; const searchTokens = [];
filters.forEach((filter) => { filters.forEach((filter) => {
if (typeof filter === 'string') { if (filter.type === 'filtered-search-term') {
search = filter; if (filter.value.data) {
searchTokens.push(filter.value.data);
}
} }
}); });
this.filters.search = search; if (searchTokens.length) {
this.filters.search = searchTokens.join(' ');
}
this.page = 1; this.page = 1;
this.refetchIssuables(); this.refetchIssuables();
......
---
title: Fix search functionality in Jira issues list
merge_request: 54312
author:
type: fixed
...@@ -591,5 +591,75 @@ describe('Issuables list component', () => { ...@@ -591,5 +591,75 @@ describe('Issuables list component', () => {
expect(findFilteredSearchBar().props('initialFilterValue')).toEqual(['free text']); expect(findFilteredSearchBar().props('initialFilterValue')).toEqual(['free text']);
}); });
}); });
describe('on filter search', () => {
beforeEach(() => {
factory({ type: 'jira' });
window.history.pushState = jest.fn();
});
afterEach(() => {
window.history.pushState.mockRestore();
});
const emitOnFilter = (filter) => findFilteredSearchBar().vm.$emit('onFilter', filter);
describe('empty filter', () => {
const mockFilter = [];
it('updates URL with correct params', () => {
emitOnFilter(mockFilter);
expect(window.history.pushState).toHaveBeenCalledWith(
{},
'',
`${TEST_LOCATION}?state=opened`,
);
});
});
describe('filter with search term', () => {
const mockFilter = [
{
type: 'filtered-search-term',
value: { data: 'free' },
},
];
it('updates URL with correct params', () => {
emitOnFilter(mockFilter);
expect(window.history.pushState).toHaveBeenCalledWith(
{},
'',
`${TEST_LOCATION}?state=opened&search=free`,
);
});
});
describe('filter with multiple search terms', () => {
const mockFilter = [
{
type: 'filtered-search-term',
value: { data: 'free' },
},
{
type: 'filtered-search-term',
value: { data: 'text' },
},
];
it('updates URL with correct params', () => {
emitOnFilter(mockFilter);
expect(window.history.pushState).toHaveBeenCalledWith(
{},
'',
`${TEST_LOCATION}?state=opened&search=free+text`,
);
});
});
});
}); });
}); });
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment