-
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
Changes from 5 commits
60544c0
f26070b
c66cd3c
6f6de3e
81e0f47
3dab582
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
import * as TextUtils from './textUtils'; | ||
export { TextUtils }; |
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 was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,149 @@ | ||
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 handle ignore case-sensetive', () => { | ||
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}]); | ||
}); | ||
Comment on lines
+79
to
+83
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Consider adding a test for more than full string: There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 👍 |
||
}); | ||
|
||
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 handle ignore case-sensetive', () => { | ||
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} | ||
]); | ||
}); | ||
}); | ||
}); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
import * as TextUtils from './textUtils'; | ||
|
||
export {TextUtils}; |
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.