<commit_before>/*
 *  Copyright 2014 TWO SIGMA OPEN SOURCE, LLC
 *
 *  Licensed under the Apache License, Version 2.0 (the "License");
 *  you may not use this file except in compliance with the License.
 *  You may obtain a copy of the License at
 *
 *         http://www.apache.org/licenses/LICENSE-2.0
 *
 *  Unless required by applicable law or agreed to in writing, software
 *  distributed under the License is distributed on an "AS IS" BASIS,
 *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *  See the License for the specific language governing permissions and
 *  limitations under the License.
 */

var _ = require('underscore');
var path = require('path');
var fs = require('fs');

var BeakerPageObject = function() {

  this.EC = protractor.ExpectedConditions;
  this.baseURL = 'http://127.0.0.1:8801/';
  this.mainmenu = element.all(by.repeater('m in getMenus()'));
  //jscs:disable
  this.submenu = element.all(by.repeater("item in getMenuItems() | filter:isHidden | orderBy:'sortorder'"))
  //jscs:enable
    .filter(function(e, i) { return e.isDisplayed(); });

  this.waitForInstantiationCells = function(screenshotName) {
    var self = this;
    var dialogIsPresent = this.EC.presenceOf($('.modal-dialog'));
    // First wait for the modal to show up when opening a URL
    browser.wait(dialogIsPresent, 10000).then(function(){
      // wait for the modal to close
      browser.wait(self.EC.not(dialogIsPresent), 100000).then(function(){
        return true;
      },
      function(error){
        beakerPO.createScreenshot(screenshotName);
        expect(error).toBe('Cells have been initialized');
      });
    });
  };

  this.openFile = function(path) {
    this.openMenuAtIndex(0);

    browser.sleep(1000); // mouseMove happens too fast and the menu doesnt display sometimes. Couldn't find a better solution.
    browser.actions().mouseMove(element(by.css('#open-menuitem'))).perform();

    element(by.css('a[title="Open a bkr notebook file"]')).click();
    browser.wait(function() {
      return element(by.css('input.form-control')).sendKeys(path)
        .then(function() {
          return true;
        })
        .thenCatch(function() {
          return false;
        });
    }, 100000);

    return element(by.css('.modal-submit')).click();
  };

  this.waitUntilGraphOutputPresent = function() {
    return browser.wait(function() {
      return element(by.css('bk-output-display[type="Plot"]')).isDisplayed()
      .then(function() {
        return true;
      })
      .thenCatch(function() {
        return false;
      });
    }, 100000);
  };

  this.openMenuAtIndex = function(index) {
    return this.mainmenu.get(index).element(by.css('.dropdown-toggle')).click();
  };

  this.toggleLanguageCellMenu = function(opts) {
    return element.all(by.css('.dropdown-toggle bk-language-logo'))
    .get(opts.cellIndex).click();
  };

  this.isLanguageCellMenuOpen = function() {
    return browser.executeScript('return $(".inputcellmenu:visible").length > 0');
  };

  this.toggleCellMenu = function(opts) {
    return element.all(by.css('.bkcell .toggle-menu .dropdown-promoted'))
    .get(opts.cellIndex)
    .click();
  };

  this.toggleAdvancedMode = function() {
    return element(by.css('.view-menu'))
    .click()
    .then(element(by.partialLinkText('Advanced Mode')).click);
  };

  this.setNormalEditMode = function() {
    var self = this;
    this.setEditMode();
    element(by.css('#normal-edit-mode-menuitem')).click().then(
        function(resolve){
          return true;
        },
        function(reject){
          console.log("normal-edit-mode-menuitem hasn't displayed");
          self.createScreenshot('errorSetEditMode');
          browser.actions().mouseMove(element(by.css('#edit-mode-menuitem'))).perform();
          element(by.css('#normal-edit-mode-menuitem')).click();
        }
    );
  };

  this.setEmacsEditMode = function() {
    this.setEditMode();
    element(by.css('#emacs-edit-mode-menuitem')).click();
  };

  this.setVimEditMode = function () {
    var self = this;
    this.setEditMode();
    element(by.css('#vim-edit-mode-menuitem')).click().then(
        function(resolve){
          return true;
        },
        function(reject){
          console.log("vim-edit-mode-menuitem hasn't displayed");
          self.createScreenshot('errorSetEditMode');
          browser.actions().mouseMove(element(by.css('#edit-mode-menuitem'))).perform();
          element(by.css('#vim-edit-mode-menuitem')).click();
        }
    );

  };

  this.setSublimeEditMode = function() {
    this.setEditMode().then(element(by.css('#sublime-edit-mode-menuitem')).click);
  };

  this.setEditMode = function() {
    element(by.css('.notebook-menu')).click();
    return browser.actions().mouseMove(element(by.css('#edit-mode-menuitem'))).perform();
  };

  this.isCellMenuOpen = function(opts) {
    return element.all(by.css('.bkcell .open.toggle-menu-items.bkr'))
    .get(opts.cellIndex)
    .isDisplayed()
    .then(function() {
      return true;
    })
    .thenCatch(function() {
      return false;
    });
  };

  this.createMarkdownCell = function(text) {
    return element(by.css('bk-new-cell-menu .dropdown-toggle'))
    .click()
    .then(function() {
      return element(by.css('.insert-text'));
    })
    .then(function(el) {
      return el.click();
    })
    .then(function() {
      return this.setCellInput(text);
    }.bind(this));
  }.bind(this);

  this.newEmptyNotebook = element(by.className('new-empty-notebook'));
<commit_msg>check tests<commit_after>/*
 *  Copyright 2014 TWO SIGMA OPEN SOURCE, LLC
 *
 *  Licensed under the Apache License, Version 2.0 (the "License");
 *  you may not use this file except in compliance with the License.
 *  You may obtain a copy of the License at
 *
 *         http://www.apache.org/licenses/LICENSE-2.0
 *
 *  Unless required by applicable law or agreed to in writing, software
 *  distributed under the License is distributed on an "AS IS" BASIS,
 *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *  See the License for the specific language governing permissions and
 *  limitations under the License.
 */

var _ = require('underscore');
var path = require('path');
var fs = require('fs');

var BeakerPageObject = function() {

  this.EC = protractor.ExpectedConditions;
  this.baseURL = 'http://127.0.0.1:8801/';
  this.mainmenu = element.all(by.repeater('m in getMenus()'));
  //jscs:disable
  this.submenu = element.all(by.repeater("item in getMenuItems() | filter:isHidden | orderBy:'sortorder'"))
  //jscs:enable
    .filter(function(e, i) { return e.isDisplayed(); });

  this.waitForInstantiationCells = function(screenshotName) {
    var self = this;
    var dialogIsPresent = this.EC.presenceOf($('.modal-dialog'));
    // First wait for the modal to show up when opening a URL
    browser.wait(dialogIsPresent, 10000).then(function(){
      // wait for the modal to close
      browser.wait(self.EC.not(dialogIsPresent), 100000).then(function(){
        return true;
      },
      function(error){
        beakerPO.createScreenshot(screenshotName);
        expect(error).toBe('Cells have been initialized');
      });
    });
  };

  this.openFile = function(path) {
    this.openMenuAtIndex(0);

    browser.sleep(1000); // mouseMove happens too fast and the menu doesnt display sometimes. Couldn't find a better solution.
    browser.actions().mouseMove(element(by.css('#open-menuitem'))).perform();

    element(by.css('a[title="Open a bkr notebook file"]')).click();
    browser.wait(function() {
      return element(by.css('input.form-control')).sendKeys(path)
        .then(function() {
          return true;
        })
        .thenCatch(function() {
          return false;
        });
    }, 100000);

    return element(by.css('.modal-submit')).click();
  };

  this.waitUntilGraphOutputPresent = function() {
    return browser.wait(function() {
      return element(by.css('bk-output-display[type="Plot"]')).isDisplayed()
      .then(function() {
        return true;
      })
      .thenCatch(function() {
        return false;
      });
    }, 100000);
  };

  this.openMenuAtIndex = function(index) {
    return this.mainmenu.get(index).element(by.css('.dropdown-toggle')).click();
  };

  this.toggleLanguageCellMenu = function(opts) {
    return element.all(by.css('.dropdown-toggle bk-language-logo'))
    .get(opts.cellIndex).click();
  };

  this.isLanguageCellMenuOpen = function() {
    return browser.executeScript('return $(".inputcellmenu:visible").length > 0');
  };

  this.toggleCellMenu = function(opts) {
    return element.all(by.css('.bkcell .toggle-menu .dropdown-promoted'))
    .get(opts.cellIndex)
    .click();
  };

  this.toggleAdvancedMode = function() {
    return element(by.css('.view-menu'))
    .click()
    .then(element(by.partialLinkText('Advanced Mode')).click);
  };

  this.setNormalEditMode = function() {
    var self = this;
    this.setEditMode();
    $('#normal-edit-mode-menuitem').click().then(
        function(resolve){
          return true;
        },
        function(reject){
          console.log("normal-edit-mode-menuitem hasn't displayed");
          self.createScreenshot('errorSetEditMode');
          browser.actions().mouseMove(element(by.css('#edit-mode-menuitem'))).perform();
          $('#normal-edit-mode-menuitem').click();
        }
    );
  };

  this.setEmacsEditMode = function() {
    this.setEditMode();
    element(by.css('#emacs-edit-mode-menuitem')).click();
  };

  this.setVimEditMode = function () {
    var self = this;
    this.setEditMode();
    $('#vim-edit-mode-menuitem').click().then(
        function(resolve){
          return true;
        },
        function(reject){
          console.log("vim-edit-mode-menuitem hasn't displayed");
          self.createScreenshot('errorSetEditMode');
          browser.actions().mouseMove(element(by.css('#edit-mode-menuitem'))).perform();
          $('#vim-edit-mode-menuitem').click();
        }
    );

  };

  this.setSublimeEditMode = function() {
    this.setEditMode().then(element(by.css('#sublime-edit-mode-menuitem')).click);
  };

  this.setEditMode = function() {
    $('.notebook-menu').click();
    return browser.actions().mouseMove($('#edit-mode-menuitem')).perform();
  };

  this.isCellMenuOpen = function(opts) {
    return element.all(by.css('.bkcell .open.toggle-menu-items.bkr'))
    .get(opts.cellIndex)
    .isDisplayed()
    .then(function() {
      return true;
    })
    .thenCatch(function() {
      return false;
    });
  };

  this.createMarkdownCell = function(text) {
    return element(by.css('bk-new-cell-menu .dropdown-toggle'))
    .click()
    .then(function() {
      return element(by.css('.insert-text'));
    })
    .then(function(el) {
      return el.click();
    })
    .then(function() {
      return this.setCellInput(text);
    }.bind(this));
  }.bind(this);

  this.newEmptyNotebook = element(by.className('new-empty-notebook'));

{'fraction_non_alphanumeric': 0.1613780598368087, 'fraction_numerical': 0.008522212148685404, 'mean_word_length': 3.0795118343195265, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 2, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5414011', 'n_tokens_mistral': 3496, 'n_tokens_neox': 3383, 'n_words': 629}