Fix issue with Attendee not being string crashing tooltip

Signed-off-by: Mason Brothers <brothers.mason@gmail.com>
This commit is contained in:
Mason Brothers 2023-04-28 11:31:51 -06:00
parent 3977b5e305
commit ac300db723
2 changed files with 14 additions and 0 deletions

View File

@ -27,6 +27,8 @@
* @return {string} URI without a mailto prefix
*/
export function removeMailtoPrefix(uri) {
if (typeof uri !== 'string') return ''
if (uri.startsWith('mailto:')) {
return uri.slice(7)
}
@ -41,6 +43,8 @@ export function removeMailtoPrefix(uri) {
* @return {string} URI with a mailto prefix
*/
export function addMailtoPrefix(uri) {
if (typeof uri !== 'string') return 'mailto:'
if (uri.startsWith('mailto:')) {
return uri
}

View File

@ -33,12 +33,22 @@ describe('utils/attendee test suite', () => {
expect(removeMailtoPrefix(`mailto:${uri}`)).toEqual(uri)
})
it('should return blank strings when uris are not of type string', () => {
expect(removeMailtoPrefix(null)).toEqual('')
expect(removeMailtoPrefix(undefined)).toEqual('')
})
it('should add mailto prefixes to uris', () => {
const uri = 'principal@test.com'
const uriWithPrefix = `mailto:${uri}`
expect(addMailtoPrefix(uri)).toEqual(uriWithPrefix)
expect(addMailtoPrefix(uriWithPrefix)).toEqual(uriWithPrefix)
})
it('should add mailto prefixes to uris when they are not of type string', () => {
expect(addMailtoPrefix(null)).toEqual("mailto:")
expect(addMailtoPrefix(undefined)).toEqual("mailto:")
})
it('should extract a display name of an organizer', () => {
const commonName = 'My Name'