Skip to content

Commit

Permalink
test for convertToLTRForComposer added
Browse files Browse the repository at this point in the history
  • Loading branch information
HardikChoudhary24 committed Oct 30, 2023
1 parent fbc466b commit 7054c51
Showing 1 changed file with 60 additions and 0 deletions.
60 changes: 60 additions & 0 deletions tests/unit/ConvertToLTRForComposerTest.js
Original file line number Diff line number Diff line change
@@ -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);
});
});
});

0 comments on commit 7054c51

Please sign in to comment.