Loading e2e/app.e2e-spec.ts +15 −11 Original line number Diff line number Diff line Loading @@ -8,35 +8,37 @@ describe('ng2-mentions App', function() { page = new Ng2MentionsPage(); }) it('two mentions text field', () => { let elements = it('test mentions text field', () => { page.navigateTo(); expect(page.getHeadingText()).toEqual('Angular 2 Mentions'); let el = element(by.css('input')); testTwoMentions(el); testMentions(el); }); it('two mentions text area', () => { it('test mentions text area', () => { page.navigateTo(); expect(page.getHeadingText()).toEqual('Angular 2 Mentions'); let el = element.all(by.css('textarea')).first(); testTwoMentions(el); testMentions(el); }); it('two mentions div', () => { it('test mentions div', () => { page.navigateTo(); expect(page.getHeadingText()).toEqual('Angular 2 Mentions'); let el = element.all(by.css('div')).first(); testTwoMentions(el); testMentions(el); }); it('two mentions iframe', () => { it('test mentions iframe', () => { page.navigateTo(); expect(page.getHeadingText()).toEqual('Angular 2 Mentions'); let el = element.all(by.id('tmce_ifr')); testTwoMentions(el); testMentions(el); }); function testTwoMentions(el){ function testMentions(el){ el.getTagName().then(function(tagName){ let menu = element(by.css('.dropdown-menu')); el.click(); Loading @@ -48,8 +50,10 @@ describe('ng2-mentions App', function() { expect(menu.isDisplayed()).toBe(true); expect(getValue(el, tagName)).toEqual('Hello @'); // select menion el.sendKeys(protractor.Key.ARROW_DOWN, protractor.Key.ENTER); // select mention using arrow keys and pressing enter //el.sendKeys(protractor.Key.ARROW_DOWN, protractor.Key.ENTER); // select mention by clicking mouse on second item in menu element(by.css('.dropdown-menu li:nth-child(2) a')).click(); browser.sleep(500); expect(menu.isDisplayed()).toBe(false); expect(getValue(el, tagName)).toEqual('Hello @Aaron '); Loading src/mention/mention.ts +6 −4 Original line number Diff line number Diff line Loading @@ -51,12 +51,14 @@ export class Mention { } stopEvent(event) { if (!event.wasClick) { event.preventDefault(); event.stopPropagation(); event.stopImmediatePropagation(); } } keyHandler(event, nativeElement=this._element.nativeElement, wasClick=false) { keyHandler(event, nativeElement=this._element.nativeElement) { let val = getValue(nativeElement); let pos = getCaretPosition(nativeElement, this.iframe); let charPressed = event.key; Loading @@ -74,7 +76,7 @@ export class Mention { charPressed = String.fromCharCode(event.which || event.keyCode); } } if (event.keyCode==13 && wasClick && pos<this.startPos) { if (event.keyCode==13 && event.wasClick && pos<this.startPos) { // put caret back in position prior to contenteditable menu click pos = this.startNode.length; setCaretPosition(this.startNode, pos, this.iframe); Loading Loading @@ -157,8 +159,8 @@ export class Mention { this.searchList.position(nativeElement, this.iframe); containerRef.instance['itemClick'].subscribe(ev => { nativeElement.focus(); let fakeKeydown = new KeyboardEvent('keydown', <KeyboardEventInit>{"keyCode":KEY_ENTER}); this.keyHandler(fakeKeydown, nativeElement, true); let fakeKeydown = {"keyCode":KEY_ENTER,"wasClick":true}; this.keyHandler(fakeKeydown, nativeElement); }); }); } Loading Loading
e2e/app.e2e-spec.ts +15 −11 Original line number Diff line number Diff line Loading @@ -8,35 +8,37 @@ describe('ng2-mentions App', function() { page = new Ng2MentionsPage(); }) it('two mentions text field', () => { let elements = it('test mentions text field', () => { page.navigateTo(); expect(page.getHeadingText()).toEqual('Angular 2 Mentions'); let el = element(by.css('input')); testTwoMentions(el); testMentions(el); }); it('two mentions text area', () => { it('test mentions text area', () => { page.navigateTo(); expect(page.getHeadingText()).toEqual('Angular 2 Mentions'); let el = element.all(by.css('textarea')).first(); testTwoMentions(el); testMentions(el); }); it('two mentions div', () => { it('test mentions div', () => { page.navigateTo(); expect(page.getHeadingText()).toEqual('Angular 2 Mentions'); let el = element.all(by.css('div')).first(); testTwoMentions(el); testMentions(el); }); it('two mentions iframe', () => { it('test mentions iframe', () => { page.navigateTo(); expect(page.getHeadingText()).toEqual('Angular 2 Mentions'); let el = element.all(by.id('tmce_ifr')); testTwoMentions(el); testMentions(el); }); function testTwoMentions(el){ function testMentions(el){ el.getTagName().then(function(tagName){ let menu = element(by.css('.dropdown-menu')); el.click(); Loading @@ -48,8 +50,10 @@ describe('ng2-mentions App', function() { expect(menu.isDisplayed()).toBe(true); expect(getValue(el, tagName)).toEqual('Hello @'); // select menion el.sendKeys(protractor.Key.ARROW_DOWN, protractor.Key.ENTER); // select mention using arrow keys and pressing enter //el.sendKeys(protractor.Key.ARROW_DOWN, protractor.Key.ENTER); // select mention by clicking mouse on second item in menu element(by.css('.dropdown-menu li:nth-child(2) a')).click(); browser.sleep(500); expect(menu.isDisplayed()).toBe(false); expect(getValue(el, tagName)).toEqual('Hello @Aaron '); Loading
src/mention/mention.ts +6 −4 Original line number Diff line number Diff line Loading @@ -51,12 +51,14 @@ export class Mention { } stopEvent(event) { if (!event.wasClick) { event.preventDefault(); event.stopPropagation(); event.stopImmediatePropagation(); } } keyHandler(event, nativeElement=this._element.nativeElement, wasClick=false) { keyHandler(event, nativeElement=this._element.nativeElement) { let val = getValue(nativeElement); let pos = getCaretPosition(nativeElement, this.iframe); let charPressed = event.key; Loading @@ -74,7 +76,7 @@ export class Mention { charPressed = String.fromCharCode(event.which || event.keyCode); } } if (event.keyCode==13 && wasClick && pos<this.startPos) { if (event.keyCode==13 && event.wasClick && pos<this.startPos) { // put caret back in position prior to contenteditable menu click pos = this.startNode.length; setCaretPosition(this.startNode, pos, this.iframe); Loading Loading @@ -157,8 +159,8 @@ export class Mention { this.searchList.position(nativeElement, this.iframe); containerRef.instance['itemClick'].subscribe(ev => { nativeElement.focus(); let fakeKeydown = new KeyboardEvent('keydown', <KeyboardEventInit>{"keyCode":KEY_ENTER}); this.keyHandler(fakeKeydown, nativeElement, true); let fakeKeydown = {"keyCode":KEY_ENTER,"wasClick":true}; this.keyHandler(fakeKeydown, nativeElement); }); }); } Loading