Commit 807e1a43 authored by dmacfarlane's avatar dmacfarlane
Browse files

Cleanup e2e tests

parent 4eaa76cf
Loading
Loading
Loading
Loading
+15 −35
Original line number Original line Diff line number Diff line
import { browser, element, by, protractor } from 'protractor';
import { element, by, protractor } from 'protractor';


import { AngularMentionsPage } from './app.po';
import { AngularMentionsPage } from './app.po';


describe('angular-mentions App', function() {
describe('angular-mentions app', function() {
  var EC = protractor.ExpectedConditions;
  let page: AngularMentionsPage;
  let page: AngularMentionsPage;


  beforeEach(() => {
  beforeEach(() => {
    page = new AngularMentionsPage();
    page = new AngularMentionsPage();
  })
  })


  let elements = 

  it('test mentions text field', () => {
  it('test mentions text field', () => {
    page.navigateTo();
    page.navigateTo();
    expect(page.getHeadingText()).toEqual('Angular Mentions');
    expect(page.getHeadingText()).toEqual('Angular Mentions');
@@ -50,7 +47,7 @@ describe('angular-mentions App', function() {
    el.getTagName().then(function(tagName){
    el.getTagName().then(function(tagName){
      let menu = element(by.css('.dropdown-menu'));
      let menu = element(by.css('.dropdown-menu'));
      el.click();
      el.click();
      expect(getValue(el, tagName)).toEqual('');
      expect(page.getValue(el, tagName)).toEqual('');


      // test for git issue #59
      // test for git issue #59
      el.sendKeys('@');
      el.sendKeys('@');
@@ -60,12 +57,12 @@ describe('angular-mentions App', function() {
      el.sendKeys('xa');
      el.sendKeys('xa');
      expect(menu.isDisplayed()).toBe(false);
      expect(menu.isDisplayed()).toBe(false);
      el.sendKeys(protractor.Key.BACK_SPACE, protractor.Key.BACK_SPACE);
      el.sendKeys(protractor.Key.BACK_SPACE, protractor.Key.BACK_SPACE);
      expect(getValue(el, tagName)).toEqual('');
      expect(page.getValue(el, tagName)).toEqual('');


      // popup menu
      // popup menu
      el.sendKeys('Hello @');
      el.sendKeys('Hello @');
      expect(menu.isDisplayed()).toBe(true);
      expect(menu.isDisplayed()).toBe(true);
      expect(getValue(el, tagName)).toEqual('Hello @');
      expect(page.getValue(el, tagName)).toEqual('Hello @');
            
            
      // select mention using arrow keys and pressing enter
      // select mention using arrow keys and pressing enter
      // el.sendKeys(protractor.Key.ARROW_DOWN, protractor.Key.ENTER);
      // el.sendKeys(protractor.Key.ARROW_DOWN, protractor.Key.ENTER);
@@ -73,65 +70,48 @@ describe('angular-mentions App', function() {
      // select mention by clicking mouse on second item in menu
      // select mention by clicking mouse on second item in menu
      element(by.css('.dropdown-menu li:nth-child(2) a')).click();
      element(by.css('.dropdown-menu li:nth-child(2) a')).click();
      expect(menu.isDisplayed()).toBe(false);
      expect(menu.isDisplayed()).toBe(false);
      expect(getValue(el, tagName)).toEqual('Hello @Aaron');
      expect(page.getValue(el, tagName)).toEqual('Hello @Aaron');
      
      
      // select another mention
      // select another mention
      el.sendKeys(' and @gav', protractor.Key.ENTER);
      el.sendKeys(' and @gav', protractor.Key.ENTER);
      expect(menu.isDisplayed()).toBe(false);
      expect(menu.isDisplayed()).toBe(false);
      expect(getValue(el, tagName)).toEqual('Hello @Aaron and @Gavin');
      expect(page.getValue(el, tagName)).toEqual('Hello @Aaron and @Gavin');
      
      
      // start another mention (with no values)
      // start another mention (with no values)
      el.sendKeys(' and @u');
      el.sendKeys(' and @u');
      expect(menu.isDisplayed()).toBe(false);
      expect(menu.isDisplayed()).toBe(false);
      expect(getValue(el, tagName)).toEqual('Hello @Aaron and @Gavin and @u');
      expect(page.getValue(el, tagName)).toEqual('Hello @Aaron and @Gavin and @u');
      
      
      // remove the mention
      // remove the mention
      el.sendKeys(protractor.Key.BACK_SPACE, protractor.Key.BACK_SPACE);
      el.sendKeys(protractor.Key.BACK_SPACE, protractor.Key.BACK_SPACE);
      expect(getValue(el, tagName)).toEqual('Hello @Aaron and @Gavin and ');
      expect(page.getValue(el, tagName)).toEqual('Hello @Aaron and @Gavin and ');


      // start another mention
      // start another mention
      el.sendKeys('@');
      el.sendKeys('@');
      expect(menu.isDisplayed()).toBe(true);
      expect(menu.isDisplayed()).toBe(true);
      expect(getValue(el, tagName)).toEqual('Hello @Aaron and @Gavin and @');
      expect(page.getValue(el, tagName)).toEqual('Hello @Aaron and @Gavin and @');


      // continue the mention
      // continue the mention
      el.sendKeys('e');
      el.sendKeys('e');
      expect(menu.isDisplayed()).toBe(true);
      expect(menu.isDisplayed()).toBe(true);
      expect(getValue(el, tagName)).toEqual('Hello @Aaron and @Gavin and @e');
      expect(page.getValue(el, tagName)).toEqual('Hello @Aaron and @Gavin and @e');
      
      
      // but press escape instead
      // but press escape instead
      el.sendKeys(protractor.Key.ESCAPE);
      el.sendKeys(protractor.Key.ESCAPE);
      expect(menu.isDisplayed()).toBe(false);
      expect(menu.isDisplayed()).toBe(false);
      expect(getValue(el, tagName)).toEqual('Hello @Aaron and @Gavin and @e');
      expect(page.getValue(el, tagName)).toEqual('Hello @Aaron and @Gavin and @e');
      
      
      // remove the escaped entry
      // remove the escaped entry
      el.sendKeys('!!', protractor.Key.ARROW_LEFT, protractor.Key.ARROW_LEFT);
      el.sendKeys('!!', protractor.Key.ARROW_LEFT, protractor.Key.ARROW_LEFT);
      el.sendKeys(protractor.Key.BACK_SPACE, protractor.Key.BACK_SPACE);
      el.sendKeys(protractor.Key.BACK_SPACE, protractor.Key.BACK_SPACE);
      expect(getValue(el, tagName)).toEqual('Hello @Aaron and @Gavin and !!');
      expect(page.getValue(el, tagName)).toEqual('Hello @Aaron and @Gavin and !!');


      // and insert another mention
      // and insert another mention
      el.sendKeys('@HE', protractor.Key.ENTER);
      el.sendKeys('@HE', protractor.Key.ENTER);
      expect(menu.isDisplayed()).toBe(false);
      expect(menu.isDisplayed()).toBe(false);
      expect(getValue(el, tagName)).toEqual('Hello @Aaron and @Gavin and @Henry!!');
      expect(page.getValue(el, tagName)).toEqual('Hello @Aaron and @Gavin and @Henry!!');
    });  
    });  
  }
  }
  
  
  function getValue(el, tagName) {

    if (tagName=="input" || tagName=="textarea") {    
      return el.getAttribute('value');
    }
    else if (tagName.length>0 && tagName[0]=='iframe') {
      let iframe = browser.findElement(by.tagName("iframe"));
      return browser.switchTo().frame(iframe).then( () => {
        let el = browser.driver.findElement(by.id('tinymce'));
        let text = el.getText();
        return browser.switchTo().defaultContent().then(()=>{
          return browser.waitForAngular().then(()=>{return text});
        });
      });              
    }
    else {
      return el.getText();
    }    
  }
});
});
+19 −0
Original line number Original line Diff line number Diff line
@@ -8,4 +8,23 @@ export class AngularMentionsPage {
  getHeadingText() {
  getHeadingText() {
    return element(by.css('app-root h1')).getText();
    return element(by.css('app-root h1')).getText();
  }
  }

  getValue(el, tagName) {
    if (tagName=="input" || tagName=="textarea") {    
      return el.getAttribute('value');
    }
    else if (tagName.length>0 && tagName[0]=='iframe') {
      let iframe = browser.findElement(by.tagName("iframe"));
      return browser.switchTo().frame(iframe).then( () => {
        let el = browser.driver.findElement(by.id('tinymce'));
        let text = el.getText();
        return browser.switchTo().defaultContent().then(()=>{
          return browser.waitForAngular().then(()=>{return text});
        });
      });              
    }
    else {
      return el.getText();
    }    
  }  
}
}