Skip to content

Commit

Permalink
✅ autosuggest, use id in recent searches for retrieving entity type, …
Browse files Browse the repository at this point in the history
…fix tests
  • Loading branch information
faival committed Jun 25, 2018
1 parent 03729e4 commit fbad6ad
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 14 deletions.
6 changes: 4 additions & 2 deletions src/components/autoSuggest/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,7 @@ class AutoSuggest extends React.Component {
.filter(result => typeof result === 'object')
.map((result, idx) => {
let type = searchEntities.addresses;
if (result.searchTerm.match(regex.transactionId)) {
if (result.id.match(regex.transactionId)) {
type = searchEntities.transactions;
}
return {
Expand All @@ -278,7 +278,9 @@ class AutoSuggest extends React.Component {

return (
<div className={styles.wrapper}>
<input placeholder={placeholderValue}
<input
value={placeholderValue}
onChange={() => {}}
className={`${styles.placeholder} autosuggest-placeholder`}
type='text'
name='autosuggest-placeholder' />
Expand Down
5 changes: 4 additions & 1 deletion src/components/autoSuggest/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,10 @@ describe('AutoSuggest', () => {
});

it('should show recent searches when focusing on input and no search value has been entered yet', () => {
localStorageStub.withArgs('searches', []).returns(['111L', '111']);
localStorageStub.withArgs('searches', []).returns([
{ id: '111L', searchTerm: 'pepe' },
{ id: '111', searchTerm: '' },
]);
wrapper.setProps({
results: {
delegates: [],
Expand Down
21 changes: 10 additions & 11 deletions src/components/search/keyAction.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,23 +12,22 @@ describe('Search KeyAction', () => {

it('saves the last 3 searches without duplicates', () => {
const testValues = [
'811299173602533L',
'947273526752682L',
'',
'382923358293526L ',
'947273526752682L',
{ id: '811299173602533L', searchTerm: '811299173602533L' },
{ id: '947273526752682L', searchTerm: '947273526752682L' },
{ id: '', searchTerm: '' },
{ id: '382923358293526L ', searchTerm: '382923358293526L ' },
{ id: '947273526752682L ', searchTerm: '947273526752682L' },
];

const expectedOutcome = [
'947273526752682L',
'382923358293526L',
'811299173602533L',
{ id: '947273526752682L ', searchTerm: '947273526752682L' },
{ id: '382923358293526L ', searchTerm: '382923358293526L' },
{ id: '811299173602533L', searchTerm: '811299173602533L' },
];

testValues.forEach((value) => {
saveSearch(value);
testValues.forEach((searchObj) => {
saveSearch(searchObj.searchTerm, searchObj.id);
});

expect(localJSONStorage.get('searches')).to.eql(expectedOutcome);
});
});

0 comments on commit fbad6ad

Please sign in to comment.