-
Notifications
You must be signed in to change notification settings - Fork 734
Feat/text highlight refactor #1669
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
60544c0
Add tests for array highlightString and small fixes
M-i-k-e-l f26070b
Move text highlight to utils
M-i-k-e-l c66cd3c
Minor refactor
M-i-k-e-l 6f6de3e
Handle full string
M-i-k-e-l 81e0f47
Prettify
M-i-k-e-l 3dab582
Review and another bug fix
M-i-k-e-l File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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,2 @@ | ||
import * as TextUtils from './textUtils'; | ||
export { TextUtils }; |
This file contains hidden or 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,13 @@ | ||
declare function getPartsByHighlight(targetString: string | undefined, highlightString: string | string[]): { | ||
string: string; | ||
shouldHighlight: boolean; | ||
}[]; | ||
declare function getTextPartsByHighlight(targetString?: string, highlightString?: string): { | ||
string: string; | ||
shouldHighlight: boolean; | ||
}[]; | ||
declare function getArrayPartsByHighlight(targetString?: string, highlightString?: string[]): { | ||
string: string; | ||
shouldHighlight: boolean; | ||
}[]; | ||
export { getPartsByHighlight, getTextPartsByHighlight, getArrayPartsByHighlight }; |
This file contains hidden or 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 was deleted.
Oops, something went wrong.
This file contains hidden or 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 hidden or 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,164 @@ | ||
import {getTextPartsByHighlight, getArrayPartsByHighlight} from '../textUtils'; | ||
|
||
describe('Text', () => { | ||
describe('getTextPartsByHighlight', () => { | ||
it('should return the whole string as a single part when highlight string is undefined', () => { | ||
const result = getTextPartsByHighlight('Playground Screen', undefined); | ||
expect(result).toEqual([{string: 'Playground Screen', shouldHighlight: false}]); | ||
}); | ||
it('should return the whole string as a single part when highlight string is empty', () => { | ||
const result = getTextPartsByHighlight('Playground Screen', ''); | ||
expect(result).toEqual([{string: 'Playground Screen', shouldHighlight: false}]); | ||
}); | ||
it('should return the whole string as a single part when highlight string dont match', () => { | ||
const result = getTextPartsByHighlight('Playground Screen', 'aaa'); | ||
expect(result).toEqual([{string: 'Playground Screen', shouldHighlight: false}]); | ||
}); | ||
it('should break text to parts according to highlight string', () => { | ||
const result = getTextPartsByHighlight('Playground Screen', 'Scr'); | ||
expect(result).toEqual([ | ||
{string: 'Playground ', shouldHighlight: false}, | ||
{string: 'Scr', shouldHighlight: true}, | ||
{string: 'een', shouldHighlight: false} | ||
]); | ||
}); | ||
|
||
it('should handle case when highlight repeats more than once', () => { | ||
const result = getTextPartsByHighlight('Dancing in the Dark', 'Da'); | ||
expect(result).toEqual([ | ||
{string: 'Da', shouldHighlight: true}, | ||
{string: 'ncing in the ', shouldHighlight: false}, | ||
{string: 'Da', shouldHighlight: true}, | ||
{string: 'rk', shouldHighlight: false} | ||
]); | ||
}); | ||
|
||
it('should be case-insensitive', () => { | ||
const result = getTextPartsByHighlight('Dancing in the Dark', 'da'); | ||
expect(result).toEqual([ | ||
{string: 'Da', shouldHighlight: true}, | ||
{string: 'ncing in the ', shouldHighlight: false}, | ||
{string: 'Da', shouldHighlight: true}, | ||
{string: 'rk', shouldHighlight: false} | ||
]); | ||
}); | ||
|
||
it('Should handle special characters @', () => { | ||
const result = getTextPartsByHighlight('@ancing in the @ark', '@a'); | ||
expect(result).toEqual([ | ||
{string: '@a', shouldHighlight: true}, | ||
{string: 'ncing in the ', shouldHighlight: false}, | ||
{string: '@a', shouldHighlight: true}, | ||
{string: 'rk', shouldHighlight: false} | ||
]); | ||
}); | ||
|
||
it('Should handle special characters !', () => { | ||
const result = getTextPartsByHighlight('!ancing in the !ark', '!a'); | ||
expect(result).toEqual([ | ||
{string: '!a', shouldHighlight: true}, | ||
{string: 'ncing in the ', shouldHighlight: false}, | ||
{string: '!a', shouldHighlight: true}, | ||
{string: 'rk', shouldHighlight: false} | ||
]); | ||
}); | ||
|
||
it('Should handle special characters starts with @', () => { | ||
const result = getTextPartsByHighlight('[email protected]', '@wix'); | ||
expect(result).toEqual([ | ||
{string: 'uilib', shouldHighlight: false}, | ||
{string: '@wix', shouldHighlight: true}, | ||
{string: '.com', shouldHighlight: false} | ||
]); | ||
}); | ||
|
||
it('Should handle empty string.', () => { | ||
const result = getTextPartsByHighlight('@ancing in the @ark', ''); | ||
expect(result).toEqual([{string: '@ancing in the @ark', shouldHighlight: false}]); | ||
}); | ||
|
||
it('Should handle full string.', () => { | ||
const result = getTextPartsByHighlight('Dancing in the Dark', 'Dancing in the Dark'); | ||
expect(result).toEqual([{string: 'Dancing in the Dark', shouldHighlight: true}]); | ||
}); | ||
|
||
it('Should handle longer string.', () => { | ||
const result = getTextPartsByHighlight('Dancing in the Dark', 'Dancing in the Darker'); | ||
expect(result).toEqual([{string: 'Dancing in the Dark', shouldHighlight: false}]); | ||
}); | ||
}); | ||
|
||
describe('getArrayPartsByHighlight', () => { | ||
it('should return the whole string as a single part when highlight array is empty', () => { | ||
const result = getArrayPartsByHighlight('Playground Screen', []); | ||
expect(result).toEqual([{string: 'Playground Screen', shouldHighlight: false}]); | ||
}); | ||
it('should return the whole string as a single part when highlight string is empty', () => { | ||
const result = getArrayPartsByHighlight('Playground Screen', ['']); | ||
expect(result).toEqual([{string: 'Playground Screen', shouldHighlight: false}]); | ||
}); | ||
it('should return the whole string as a single part when highlight string dont match', () => { | ||
const result = getArrayPartsByHighlight('Playground Screen', ['aaa']); | ||
expect(result).toEqual([{string: 'Playground Screen', shouldHighlight: false}]); | ||
}); | ||
it('should break text to parts according to highlight string', () => { | ||
const result = getArrayPartsByHighlight('Playground Screen', ['Scr']); | ||
expect(result).toEqual([ | ||
{string: 'Playground ', shouldHighlight: false}, | ||
{string: 'Scr', shouldHighlight: true}, | ||
{string: 'een', shouldHighlight: false} | ||
]); | ||
}); | ||
|
||
it('highlight repeats more than once should color the first match', () => { | ||
const result = getArrayPartsByHighlight('Dancing in the Dark', ['Da']); | ||
expect(result).toEqual([ | ||
{string: 'Da', shouldHighlight: true}, | ||
{string: 'ncing in the Dark', shouldHighlight: false} | ||
]); | ||
}); | ||
|
||
it('should be case-insensitive', () => { | ||
const result = getArrayPartsByHighlight('Dancing in the Dark', ['da']); | ||
expect(result).toEqual([ | ||
{string: 'Da', shouldHighlight: true}, | ||
{string: 'ncing in the Dark', shouldHighlight: false} | ||
]); | ||
}); | ||
|
||
it('Should handle special characters @', () => { | ||
const result = getArrayPartsByHighlight('@ancing in the @ark', ['@a']); | ||
expect(result).toEqual([ | ||
{string: '@a', shouldHighlight: true}, | ||
{string: 'ncing in the @ark', shouldHighlight: false} | ||
]); | ||
}); | ||
|
||
it('Should handle special characters !', () => { | ||
const result = getArrayPartsByHighlight('!ancing in the !ark', ['!a']); | ||
expect(result).toEqual([ | ||
{string: '!a', shouldHighlight: true}, | ||
{string: 'ncing in the !ark', shouldHighlight: false} | ||
]); | ||
}); | ||
|
||
it('Should handle special characters starts with @', () => { | ||
const result = getArrayPartsByHighlight('[email protected]', ['@wix']); | ||
expect(result).toEqual([ | ||
{string: 'uilib', shouldHighlight: false}, | ||
{string: '@wix', shouldHighlight: true}, | ||
{string: '.com', shouldHighlight: false} | ||
]); | ||
}); | ||
|
||
it('Should handle full string.', () => { | ||
const result = getArrayPartsByHighlight('Dancing in the Dark', ['Dancing in the Dark']); | ||
expect(result).toEqual([{string: 'Dancing in the Dark', shouldHighlight: true}]); | ||
}); | ||
|
||
it('Should handle longer string.', () => { | ||
const result = getArrayPartsByHighlight('Dancing in the Dark', ['Dancing in the Darker']); | ||
expect(result).toEqual([{string: 'Dancing in the Dark', shouldHighlight: false}]); | ||
}); | ||
}); | ||
}); |
This file contains hidden or 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,3 @@ | ||
import * as TextUtils from './textUtils'; | ||
|
||
export {TextUtils}; |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Consider adding a test for more than full string:
getTextPartsByHighlight('Dancing in the Dark', 'Dancing in the Darkk');
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think this is very important in the current logic, adding in case it ever changes 👍
Also noticed we don't have these tests for the array --> found another bug.