test: sanitizeSessionUsername

which is the core function of sanitizeDisplayNameOrToast in onboarding
pull/3056/head
William Grant 1 year ago
parent 238713e907
commit ba0a10960b

@ -43,13 +43,6 @@ describe('Onboarding', () => {
});
});
describe('sanitizeDisplayNameOrToast', () => {
// Arrange
// const name = sanitizeDisplayNameOrToast(_name, setDisplayNameError, dispatch);
// Act
// Assert
});
describe('signInByLinkingDevice', () => {
// Arrange
// TODO generated recoverypassword

@ -1,11 +1,11 @@
/* eslint-disable no-unused-expressions */
import chai from 'chai';
import ByteBuffer from 'bytebuffer';
import chai from 'chai';
import chaiAsPromised from 'chai-as-promised';
// Can't import type as StringUtils.Encoding
import { Encoding } from '../../../../session/utils/String';
import { StringUtils } from '../../../../session/utils';
import { Encoding } from '../../../../session/utils/String';
chai.use(chaiAsPromised as any);
@ -220,4 +220,49 @@ describe('String Utils', () => {
});
});
});
describe('sanitizeSessionUsername', () => {
it('should remove invalid characters', () => {
const invalidChars = ['\uFFD2', '\uFFD2\uFFD2', '\uFFD2\uFFD2\uFFD2'];
invalidChars.forEach(invalidChar => {
const validUsername = StringUtils.sanitizeSessionUsername(invalidChar);
expect(
validUsername,
'should return an empty string if there are no valid characters'
).to.equal('');
});
});
it('should not remove valid characters', () => {
const validChars = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j'];
validChars.forEach(validChar => {
const validUsername = StringUtils.sanitizeSessionUsername(validChar);
expect(validUsername).to.equal(validChar);
});
});
it('should remove invalid characters and keep valid characters', () => {
const input = 'a\uFFD2b\uFFD2c\uFFD2d\uFFD2e\uFFD2f\uFFD2g\uFFD2h\uFFD2i\uFFD2j';
const expected = 'abcdefghij';
const validUsername = StringUtils.sanitizeSessionUsername(input);
expect(validUsername).to.equal(expected);
});
it('should remove invalid characters and keep valid characters with spaces', () => {
const input = 'a\uFFD2 b\uFFD2 c\uFFD2 d\uFFD2 e\uFFD2 f\uFFD2 g\uFFD2 h\uFFD2 i\uFFD2 j';
const expected = 'a b c d e f g h i j';
const validUsername = StringUtils.sanitizeSessionUsername(input);
expect(validUsername).to.equal(expected);
});
it('should remove invalid characters and keep valid characters with spaces and special characters', () => {
const input =
'a\uFFD2 b\uFFD2 c\uFFD2 d\uFFD2 e\uFFD2 f\uFFD2 g\uFFD2 h\uFFD2 i\uFFD2 j\uFFD2 !@#$%^&*()_+';
const expected = 'a b c d e f g h i j !@#$%^&*()_+';
const validUsername = StringUtils.sanitizeSessionUsername(input);
expect(validUsername).to.equal(expected);
});
});
});

Loading…
Cancel
Save