diff --git a/api/js/etemplate/Et2Select/Tag/Et2EmailTag.ts b/api/js/etemplate/Et2Select/Tag/Et2EmailTag.ts index 83c8a65016..d44b35c6e4 100644 --- a/api/js/etemplate/Et2Select/Tag/Et2EmailTag.ts +++ b/api/js/etemplate/Et2Select/Tag/Et2EmailTag.ts @@ -302,7 +302,7 @@ export class Et2EmailTag extends Et2Tag split.email = parts[1].substring(0, parts[1].length - 1).trim(); split.name = parts[0].trim(); // remove quotes - if((split.name[0] === '"' || split.name[0] === "'") && split.name[0] === split.name.substr(-1)) + while((split.name[0] === '"' || split.name[0] === "'") && split.name[0] === split.name.substr(-1)) { split.name = split.name.substring(1, split.name.length - 1); } diff --git a/api/js/etemplate/Et2Select/test/Et2EmailTag.test.ts b/api/js/etemplate/Et2Select/test/Et2EmailTag.test.ts index 5ff738ed5e..ee6b526b45 100644 --- a/api/js/etemplate/Et2Select/test/Et2EmailTag.test.ts +++ b/api/js/etemplate/Et2Select/test/Et2EmailTag.test.ts @@ -71,7 +71,6 @@ describe('Et2EmailTag', () => assert.equal(extra['presets[email]'], 'test@example.com'); } }; - debugger; component.shadowRoot.querySelector("et2-button-icon").dispatchEvent(new MouseEvent('click')); }); @@ -98,3 +97,81 @@ describe('Et2EmailTag', () => await component.handleContactMouseDown(new MouseEvent('click')); }); }); + +/** + * Check a bunch of email addresses for correct formatting according to emailDisplay + */ +describe("Email formatting", function() +{ + const runs = [ + // @formatter:off + + // FULL + {emailDisplay: "full", email: "test@example.com", expected: "test@example.com"}, + {emailDisplay: "full", email: "\"Mr. Test Guy\" ", expected: "Mr. Test Guy "}, + + // No around email + {emailDisplay: "full", email: "\"Mr Test Guy\" test@example.com", expected: "\"Mr Test Guy\" test@example.com"}, + + // Multiple quotes + {emailDisplay: "full", email: "\"'EGroupware GmbH | Birgit Becker'\" ", expected: "EGroupware GmbH | Birgit Becker "}, + + // EMAIL + {emailDisplay: "email", email: "test@example.com", expected: "test@example.com"}, + {emailDisplay: "email", email: "\"Mr. Test Guy\" ", expected: "test@example.com"}, + + // No around email + {emailDisplay: "email", email: "\"Mr Test Guy\" test@example.com", expected: "\"Mr Test Guy\" test@example.com"}, + + // Multiple quotes + {emailDisplay: "email", email: "\"'EGroupware GmbH | Birgit Becker'\" ", expected: "bb@egroupware.org"}, + + // NAME + {emailDisplay: "name", email: "test@example.com", expected: "test@example.com"}, + {emailDisplay: "name", email: "\"Mr. Test Guy\" ", expected: "Mr. Test Guy"}, + + // No around email + {emailDisplay: "name", email: "\"Mr Test Guy\" test@example.com", expected: "\"Mr Test Guy\" test@example.com"}, + + // Multiple quotes + {emailDisplay: "name", email: "\"'EGroupware GmbH | Birgit Becker'\" ", expected: "EGroupware GmbH | Birgit Becker"}, + + + // DOMAIN + {emailDisplay: "domain", email: "test@example.com", expected: "test@example.com"}, + {emailDisplay: "domain", email: "\"Mr. Test Guy\" ", expected: "Mr. Test Guy (example.com)"}, + + // No around email + {emailDisplay: "domain", email: "\"Mr Test Guy\" test@example.com", expected: "\"Mr Test Guy\" test@example.com"}, + + // Multiple quotes + {emailDisplay: "domain", email: "\"'EGroupware GmbH | Birgit Becker'\" ", expected: "EGroupware GmbH | Birgit Becker (egroupware.org)"}, + + // @formatter:on + ]; + + // Create component for testing + let getComponent = async(display, value) => + { + let component = await fixture(html` + `); + // Stub egw() + // @ts-ignore + sinon.stub(component, "egw").returns(window.egw); + await component.updateComplete; + + // Asserting this instanceOf forces class loading + assert.instanceOf(component, Et2EmailTag); + return component; + } + + runs.forEach(function(run) + { + it(run.emailDisplay + ": " + run.email, async() => + { + const component = await getComponent(run.emailDisplay, run.email); + const actual = component.shadowRoot.querySelector("[part='content']")?.innerText ?? "*missing*"; + assert.equal(actual, run.expected); + }); + }); +});