From 05e262d5ee7065440bce04c5d475c17f2bea6bb2 Mon Sep 17 00:00:00 2001 From: nathan Date: Mon, 1 May 2023 15:27:17 -0600 Subject: [PATCH] Some tests for Et2EmailTag --- .../Et2Select/test/Et2EmailTag.test.ts | 84 +++++++++++++++++++ 1 file changed, 84 insertions(+) create mode 100644 api/js/etemplate/Et2Select/test/Et2EmailTag.test.ts diff --git a/api/js/etemplate/Et2Select/test/Et2EmailTag.test.ts b/api/js/etemplate/Et2Select/test/Et2EmailTag.test.ts new file mode 100644 index 0000000000..3d9ec68de7 --- /dev/null +++ b/api/js/etemplate/Et2Select/test/Et2EmailTag.test.ts @@ -0,0 +1,84 @@ +/** + * EGroupware eTemplate2 - Email Tag WebComponent tests + * + * @license http://opensource.org/licenses/gpl-license.php GPL - GNU General Public License + * @package api + * @link https://www.egroupware.org + * @author Nathan Gray + */ + +import {assert, fixture, html} from '@open-wc/testing'; +import {Et2EmailTag} from "../Tag/Et2EmailTag"; + +describe('Et2EmailTag', () => +{ + let component : Et2EmailTag; + + beforeEach(async() => + { + component = await fixture(html` + `); + await component.updateComplete; + }); + + it('should be defined', () => + { + assert.isDefined(component); + }); + + it('should have a value property', () => + { + assert.equal(component.value, 'test@example.com'); + }); + + it('should have a contactPlus property', () => + { + assert.isTrue(component.contactPlus); + }); + + it('should have an onlyEmail property', () => + { + assert.isFalse(component.onlyEmail); + }); + + it('should have a fullEmail property', () => + { + assert.isFalse(component.fullEmail); + }); + + it('should open addressbook with email preset on (+) click', () => + { + component.egw = () => ({ + open: (url, app, mode, extra) => + { + assert.equal(url, ''); + assert.equal(app, 'addressbook'); + assert.equal(mode, 'add'); + assert.equal(extra['presets[email]'], 'test@example.com'); + } + }); + component.handleClick(new MouseEvent('click')); + }); + + it('should open addressbook CRM on avatar click', async() => + { + // Fake data to test against + const contact = { + id: '123', + n_fn: 'Test User', + photo: 'test.jpg' + }; + component.value = 'test@example.com'; + component.checkContact = async(email) => contact; + component.egw = () => ({ + open: (id, app, mode, extra) => + { + assert.equal(id, contact.id); + assert.equal(app, 'addressbook'); + assert.equal(mode, 'view'); + assert.deepEqual(extra, {title: contact.n_fn, icon: contact.photo}); + } + }); + await component.handleContactClick(new MouseEvent('click')); + }); +});