-
Notifications
You must be signed in to change notification settings - Fork 2.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #53453 from software-mansion-labs/kicu/53036-email…
…-autocomplete Make autocomplete accountIDs work when pasting user emails
- Loading branch information
Showing
4 changed files
with
122 additions
and
41 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
/* eslint-disable @typescript-eslint/naming-convention */ | ||
// we need "dirty" object key names in these tests | ||
import {getQueryWithUpdatedValues} from '@src/libs/SearchQueryUtils'; | ||
|
||
const personalDetailsFakeData = { | ||
'[email protected]': { | ||
accountID: 12345, | ||
}, | ||
'[email protected]': { | ||
accountID: 78901, | ||
}, | ||
} as Record<string, {accountID: number}>; | ||
|
||
jest.mock('@libs/PersonalDetailsUtils', () => { | ||
return { | ||
getPersonalDetailByEmail(email: string) { | ||
return personalDetailsFakeData[email]; | ||
}, | ||
}; | ||
}); | ||
|
||
// The default query is generated by default values from parser, which are defined in grammar. | ||
// We don't want to test or mock the grammar and the parser, so we're simply defining this string directly here. | ||
const defaultQuery = `type:expense status:all sortBy:date sortOrder:desc`; | ||
|
||
describe('getQueryWithUpdatedValues', () => { | ||
test('returns default query for empty value', () => { | ||
const userQuery = ''; | ||
|
||
const result = getQueryWithUpdatedValues(userQuery); | ||
|
||
expect(result).toEqual(defaultQuery); | ||
}); | ||
|
||
test('returns query with updated amounts', () => { | ||
const userQuery = 'foo test amount:20000'; | ||
|
||
const result = getQueryWithUpdatedValues(userQuery); | ||
|
||
expect(result).toEqual(`${defaultQuery} amount:2000000 foo test`); | ||
}); | ||
|
||
test('returns query with user emails substituted', () => { | ||
const userQuery = 'from:[email protected] hello'; | ||
|
||
const result = getQueryWithUpdatedValues(userQuery); | ||
|
||
expect(result).toEqual(`${defaultQuery} from:12345 hello`); | ||
}); | ||
|
||
test('returns query with user emails substituted and preserves user ids', () => { | ||
const userQuery = 'from:[email protected] to:112233'; | ||
|
||
const result = getQueryWithUpdatedValues(userQuery); | ||
|
||
expect(result).toEqual(`${defaultQuery} from:12345 to:112233`); | ||
}); | ||
|
||
test('returns query with all of the fields correctly substituted', () => { | ||
const userQuery = 'from:9876,87654 to:[email protected] hello amount:150 test'; | ||
|
||
const result = getQueryWithUpdatedValues(userQuery); | ||
|
||
expect(result).toEqual(`${defaultQuery} from:9876,87654 to:78901 amount:15000 hello test`); | ||
}); | ||
}); |