From 7bbc8411c2c34dd4efbde7e5b3f7effa7e3fd83b Mon Sep 17 00:00:00 2001 From: Hardik Choudhary Date: Sun, 29 Oct 2023 23:40:21 +0530 Subject: [PATCH 1/9] input of '[' and other special characters fixed --- src/libs/convertToLTRForComposer/index.ts | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/libs/convertToLTRForComposer/index.ts b/src/libs/convertToLTRForComposer/index.ts index 37015a755869..c11f90054083 100644 --- a/src/libs/convertToLTRForComposer/index.ts +++ b/src/libs/convertToLTRForComposer/index.ts @@ -1,4 +1,4 @@ -import CONST from '@src/CONST'; +import CONST from '../../CONST'; import ConvertToLTRForComposer from './types'; function hasRTLCharacters(text: string): boolean { @@ -9,10 +9,11 @@ function hasRTLCharacters(text: string): boolean { // Converts a given text to ensure it starts with the LTR (Left-to-Right) marker. const convertToLTRForComposer: ConvertToLTRForComposer = (text) => { - // Ensure that the text starts with RTL characters if not we return the same text to avoid concatination with special character at the start which leads to unexpected behaviour for Emoji/Mention suggestions. + // Ensure that the text starts with RTL characters if not we return the same text to avoid concatination with special + // character at the start which leads to unexpected behaviour for Emoji/Mention suggestions. if (!hasRTLCharacters(text)) { // If text is empty string return empty string to avoid an empty draft due to special character. - if (text === '' || CONST.UNICODE.LTR.match(text)) { + if (text === '' || text.startsWith(CONST.UNICODE.LTR)) { return ''; } return text; From c1453334504f0aa68bb2f2035138f6a4220defa1 Mon Sep 17 00:00:00 2001 From: Hardik Choudhary Date: Mon, 30 Oct 2023 00:24:28 +0530 Subject: [PATCH 2/9] lint error fixed --- src/libs/convertToLTRForComposer/index.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/libs/convertToLTRForComposer/index.ts b/src/libs/convertToLTRForComposer/index.ts index c11f90054083..a985a5640d1a 100644 --- a/src/libs/convertToLTRForComposer/index.ts +++ b/src/libs/convertToLTRForComposer/index.ts @@ -1,4 +1,4 @@ -import CONST from '../../CONST'; +import CONST from '@src/CONST'; import ConvertToLTRForComposer from './types'; function hasRTLCharacters(text: string): boolean { From c4cc9715d484dfadd69e66142f9b24cd239e79b1 Mon Sep 17 00:00:00 2001 From: Hardik Choudhary Date: Mon, 30 Oct 2023 00:48:13 +0530 Subject: [PATCH 3/9] suggested changes applied --- src/libs/convertToLTRForComposer/index.ts | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/src/libs/convertToLTRForComposer/index.ts b/src/libs/convertToLTRForComposer/index.ts index a985a5640d1a..dd6ee50d862e 100644 --- a/src/libs/convertToLTRForComposer/index.ts +++ b/src/libs/convertToLTRForComposer/index.ts @@ -13,10 +13,7 @@ const convertToLTRForComposer: ConvertToLTRForComposer = (text) => { // character at the start which leads to unexpected behaviour for Emoji/Mention suggestions. if (!hasRTLCharacters(text)) { // If text is empty string return empty string to avoid an empty draft due to special character. - if (text === '' || text.startsWith(CONST.UNICODE.LTR)) { - return ''; - } - return text; + return text.replace(CONST.UNICODE.LTR, ''); } // Check if the text contains only spaces. If it does, we do not concatenate it with CONST.UNICODE.LTR, From 7054c5110906ca732d2b0ece401b27063a14db1a Mon Sep 17 00:00:00 2001 From: Hardik Choudhary Date: Mon, 30 Oct 2023 20:13:32 +0530 Subject: [PATCH 4/9] test for convertToLTRForComposer added --- tests/unit/ConvertToLTRForComposerTest.js | 60 +++++++++++++++++++++++ 1 file changed, 60 insertions(+) create mode 100644 tests/unit/ConvertToLTRForComposerTest.js diff --git a/tests/unit/ConvertToLTRForComposerTest.js b/tests/unit/ConvertToLTRForComposerTest.js new file mode 100644 index 000000000000..9179e8e5a479 --- /dev/null +++ b/tests/unit/ConvertToLTRForComposerTest.js @@ -0,0 +1,60 @@ +import convertToLTRForComposer from '@libs/convertToLTRForComposer'; +import CONST from '@src/CONST'; +import {platform} from 'os'; + +describe('convertToLTRForComposer', () => { + test('Input without RTL characters remains unchanged', () => { + // Test when input contains no RTL characters + const inputText = 'Hello, world!'; + const result = convertToLTRForComposer(inputText); + expect(result).toBe(inputText); + }); + + test('Input with RTL characters is prefixed with LTR marker', () => { + // Test when input contains RTL characters + const inputText = 'مثال'; + const result = convertToLTRForComposer(inputText); + if (platform === 'android') { + expect(result).toBe(inputText); + } else { + expect(result).toBe(`${CONST.UNICODE.LTR}${inputText}`); + } + }); + + test('Input with only space remains unchanged', () => { + // Test when input contains only spaces + const inputText = ' '; + const result = convertToLTRForComposer(inputText); + expect(result).toBe(inputText); + }); + + test('Input with existing LTR marker remains unchanged', () => { + // Test when input already starts with the LTR marker + const inputText = `${CONST.UNICODE.LTR}مثال`; + const result = convertToLTRForComposer(inputText); + expect(result).toBe(inputText); + }); + + test('Input starting with native emojis remains unchanged', () => { + // Test when input starts with the native emojis + const inputText = '🧶'; + const result = convertToLTRForComposer(inputText); + expect(result).toBe(inputText); + }); + + test('Input is empty', () => { + // Test when input is empty to check for draft comments + const inputText = ''; + const result = convertToLTRForComposer(inputText); + expect(result.length).toBe(0); + }); + + test('input with special characters remains unchanged', () => { + // Test when input contains special characters + const specialCharacters = ['!', '@', '#', '$', '%', '^', '&', '*', '(', ')', '_', '+', '-', '=', '{', '}', '[', ']', '"', ':', ';', '<', '>', '?', '`', '~']; + specialCharacters.forEach((character) => { + const result = convertToLTRForComposer(character); + expect(result).toBe(character); + }); + }); +}); From a2c202561db88128aef0a22b655cd0d623de4742 Mon Sep 17 00:00:00 2001 From: Hardik Choudhary Date: Mon, 30 Oct 2023 20:31:25 +0530 Subject: [PATCH 5/9] test case added --- tests/unit/ConvertToLTRForComposerTest.js | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/tests/unit/ConvertToLTRForComposerTest.js b/tests/unit/ConvertToLTRForComposerTest.js index 9179e8e5a479..d0a923f9663e 100644 --- a/tests/unit/ConvertToLTRForComposerTest.js +++ b/tests/unit/ConvertToLTRForComposerTest.js @@ -21,6 +21,17 @@ describe('convertToLTRForComposer', () => { } }); + test('Input with mixed RTL and LTR characters is prefixed with LTR marker', () => { + // Test when input contains mix of RTL and LTR characters + const inputText = 'مثال test '; + const result = convertToLTRForComposer(inputText); + if (platform === 'android') { + expect(result).toBe(inputText); + } else { + expect(result).toBe(`${CONST.UNICODE.LTR}${inputText}`); + } + }); + test('Input with only space remains unchanged', () => { // Test when input contains only spaces const inputText = ' '; From c449904dc4ecee4442f3dad9c0a0dc942d7e03c4 Mon Sep 17 00:00:00 2001 From: Hardik Choudhary Date: Mon, 30 Oct 2023 21:11:25 +0530 Subject: [PATCH 6/9] lint fixed --- tests/unit/ConvertToLTRForComposerTest.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/unit/ConvertToLTRForComposerTest.js b/tests/unit/ConvertToLTRForComposerTest.js index d0a923f9663e..e978ef33b0e6 100644 --- a/tests/unit/ConvertToLTRForComposerTest.js +++ b/tests/unit/ConvertToLTRForComposerTest.js @@ -1,5 +1,5 @@ -import convertToLTRForComposer from '@libs/convertToLTRForComposer'; -import CONST from '@src/CONST'; +import convertToLTRForComposer from '../../src/libs/convertToLTRForComposer'; +import CONST from '../../src/CONST'; import {platform} from 'os'; describe('convertToLTRForComposer', () => { From 9bd0b5f8f758eaf006b72976ac21beb387e34ef4 Mon Sep 17 00:00:00 2001 From: Hardik Choudhary Date: Mon, 30 Oct 2023 21:16:06 +0530 Subject: [PATCH 7/9] lint fixed --- tests/unit/ConvertToLTRForComposerTest.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/unit/ConvertToLTRForComposerTest.js b/tests/unit/ConvertToLTRForComposerTest.js index e978ef33b0e6..238c8d135eb6 100644 --- a/tests/unit/ConvertToLTRForComposerTest.js +++ b/tests/unit/ConvertToLTRForComposerTest.js @@ -1,6 +1,6 @@ +import {platform} from 'os'; import convertToLTRForComposer from '../../src/libs/convertToLTRForComposer'; import CONST from '../../src/CONST'; -import {platform} from 'os'; describe('convertToLTRForComposer', () => { test('Input without RTL characters remains unchanged', () => { From f6eede0ede133927ead734bdc2bb5a3689164d2f Mon Sep 17 00:00:00 2001 From: Hardik Choudhary Date: Mon, 30 Oct 2023 21:47:55 +0530 Subject: [PATCH 8/9] OS check removed --- tests/unit/ConvertToLTRForComposerTest.js | 13 ++----------- 1 file changed, 2 insertions(+), 11 deletions(-) diff --git a/tests/unit/ConvertToLTRForComposerTest.js b/tests/unit/ConvertToLTRForComposerTest.js index 238c8d135eb6..3cf08b910925 100644 --- a/tests/unit/ConvertToLTRForComposerTest.js +++ b/tests/unit/ConvertToLTRForComposerTest.js @@ -1,4 +1,3 @@ -import {platform} from 'os'; import convertToLTRForComposer from '../../src/libs/convertToLTRForComposer'; import CONST from '../../src/CONST'; @@ -14,22 +13,14 @@ describe('convertToLTRForComposer', () => { // Test when input contains RTL characters const inputText = 'مثال'; const result = convertToLTRForComposer(inputText); - if (platform === 'android') { - expect(result).toBe(inputText); - } else { - expect(result).toBe(`${CONST.UNICODE.LTR}${inputText}`); - } + expect(result).toBe(`${CONST.UNICODE.LTR}${inputText}`); }); test('Input with mixed RTL and LTR characters is prefixed with LTR marker', () => { // Test when input contains mix of RTL and LTR characters const inputText = 'مثال test '; const result = convertToLTRForComposer(inputText); - if (platform === 'android') { - expect(result).toBe(inputText); - } else { - expect(result).toBe(`${CONST.UNICODE.LTR}${inputText}`); - } + expect(result).toBe(`${CONST.UNICODE.LTR}${inputText}`); }); test('Input with only space remains unchanged', () => { From d28b633bd616a76e2cd5c2f2ca2da8d7e7b106ae Mon Sep 17 00:00:00 2001 From: Hardik Choudhary Date: Mon, 30 Oct 2023 21:58:04 +0530 Subject: [PATCH 9/9] lint fixed --- tests/unit/ConvertToLTRForComposerTest.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/unit/ConvertToLTRForComposerTest.js b/tests/unit/ConvertToLTRForComposerTest.js index 3cf08b910925..86246a9f1302 100644 --- a/tests/unit/ConvertToLTRForComposerTest.js +++ b/tests/unit/ConvertToLTRForComposerTest.js @@ -1,5 +1,5 @@ -import convertToLTRForComposer from '../../src/libs/convertToLTRForComposer'; -import CONST from '../../src/CONST'; +import convertToLTRForComposer from '@libs/convertToLTRForComposer'; +import CONST from '@src/CONST'; describe('convertToLTRForComposer', () => { test('Input without RTL characters remains unchanged', () => {