-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' into fix/exui-2595
- Loading branch information
Showing
68 changed files
with
6,151 additions
and
2,410 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
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
64 changes: 64 additions & 0 deletions
64
...-ui-toolkit/src/lib/shared/components/case-editor/case-edit-utils/case-edit.utils.spec.ts
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,64 @@ | ||
import { CaseEditUtils, convertNonASCIICharacter } from "./case-edit.utils"; | ||
|
||
describe('CaseEditUtils', () => { | ||
const caseUtils: CaseEditUtils = new CaseEditUtils(); | ||
const LONG_ASCII_STRING = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz1234567890!@£$%^&*()-=[];\,./`<>?:"|{}_+'; | ||
const LONG_PRE_STRING: string = 'Examples of non-ASCII characters: éこ¥🌍'; | ||
const LONG_POST_STRING: string = 'Examples of non-ASCII characters: éこ¥��'; | ||
|
||
describe('editNonASCIICharacters', () => { | ||
|
||
it('should not edit undefined', () => { | ||
// Note: Should never happen | ||
const response = caseUtils.convertNonASCIICharacters(undefined); | ||
expect(response).toEqual(''); | ||
}); | ||
|
||
it('should not edit an empty string', () => { | ||
const mockString = ''; | ||
const response = caseUtils.convertNonASCIICharacters(mockString); | ||
expect(response).toEqual(mockString); | ||
}); | ||
|
||
it('should note edit ASCII characters', () => { | ||
// note: string includes £ (non-ASCII) which should not be edited | ||
const response = caseUtils.convertNonASCIICharacters(LONG_ASCII_STRING); | ||
expect(response).toEqual(LONG_ASCII_STRING); | ||
}); | ||
|
||
it('should not edit £ (non ASCII)', () => { | ||
const mockString = 'Cost: £2.50'; | ||
const response = caseUtils.convertNonASCIICharacters(mockString); | ||
expect(response).toEqual(mockString); | ||
}); | ||
|
||
it('should edit ASCII characters', () => { | ||
// Summarises with copied mock string | ||
const response = caseUtils.convertNonASCIICharacters(LONG_PRE_STRING); | ||
expect(response).toEqual(LONG_POST_STRING); | ||
|
||
// Goes deeper into what should be happening just in case | ||
const chineseCharacter = '漢'; | ||
const secondMockString = 'Examples of non-ASCII characters: ' + chineseCharacter; | ||
const editedSecondMockString = | ||
`Examples of non-ASCII characters: ${CaseEditUtils.PREFIX + chineseCharacter.charCodeAt(0) + CaseEditUtils.SUFFIX}`; | ||
const secondResponse = caseUtils.convertNonASCIICharacters(secondMockString); | ||
expect(secondResponse).toEqual(editedSecondMockString); | ||
}); | ||
}); | ||
|
||
describe('revertEditNonASCIICharacters', () => { | ||
|
||
it('should not revert strings without the prefix and/or suffix', () => { | ||
const mockString = 'Hello World!'; | ||
const response = caseUtils.convertHTMLEntities(mockString); | ||
expect(response).toEqual(mockString); | ||
}); | ||
|
||
it('should revert relevant strings', () => { | ||
const response = caseUtils.convertHTMLEntities(LONG_POST_STRING); | ||
expect(response).toEqual(LONG_PRE_STRING); | ||
}); | ||
}); | ||
|
||
}); |
38 changes: 38 additions & 0 deletions
38
...-case-ui-toolkit/src/lib/shared/components/case-editor/case-edit-utils/case-edit.utils.ts
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,38 @@ | ||
|
||
export function convertNonASCIICharacter(character: string): string { | ||
if (character === '£') { | ||
// pound sign will be frequently used and works for btoa despite being non-ASCII | ||
// note: this could be done for other characters provided they work for btoa() | ||
return character; | ||
} | ||
// Note: Will convert to HTML entity | ||
return CaseEditUtils.PREFIX + character.charCodeAt(0) + CaseEditUtils.SUFFIX; | ||
} | ||
|
||
export class CaseEditUtils { | ||
|
||
public static readonly PREFIX = '&#'; | ||
public static readonly SUFFIX = ';'; | ||
|
||
public convertNonASCIICharacters(rawString: string): string { | ||
return rawString ? rawString.replace(/[^\x20-\x7E]/g, function (c) { | ||
return convertNonASCIICharacter(c); | ||
}) : ''; | ||
} | ||
|
||
public convertHTMLEntities(editedString: string): string { | ||
const revertedCharacterList = editedString.split(CaseEditUtils.PREFIX); | ||
let rawString = revertedCharacterList[0]; | ||
for (let index = 1; index < revertedCharacterList.length; index++) { | ||
const currentSection = revertedCharacterList[index]; | ||
if (!currentSection.includes(CaseEditUtils.SUFFIX)) { | ||
return rawString.concat(currentSection); | ||
} else { | ||
const suffixSplitList = currentSection.split(CaseEditUtils.SUFFIX); | ||
const characterCode = Number(suffixSplitList[0]); | ||
rawString = rawString.concat(String.fromCharCode(characterCode), suffixSplitList[1]); | ||
} | ||
} | ||
return rawString; | ||
} | ||
} |
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
Oops, something went wrong.