<commit_before>import { by, element, ExpectedConditions, browser } from 'protractor';
import { BellowsLoginPage } from '../../../../bellows/pages/loginPage';
import { ProjectsPage } from '../../../../bellows/pages/projectsPage';
import { EditorPage } from '../../pages/editorPage';

const loginPage = new BellowsLoginPage();
const projectsPage = new ProjectsPage();
const editorPage = new EditorPage();
const constants = require('../../../../testConstants');
const CONDITION_TIMEOUT = 3000;

describe('Editor Comments', () => {

  it('setup: login, click on test project', () => {
    loginPage.loginAsManager();
    projectsPage.get();
    projectsPage.clickOnProject(constants.testProjectName);
  });

  it('browse page has correct word count', () => {
    // flaky assertion, also test/app/languageforge/lexicon/editor/e2e/editor-entry.spec.js:20
    expect<any>(editorPage.browse.entriesList.count()).toEqual(editorPage.browse.getEntryCount());
    expect<any>(editorPage.browse.getEntryCount()).toBe(3);
  });

  it('click on first word', () => {
    editorPage.browse.findEntryByLexeme(constants.testEntry1.lexeme.th.value).click();
  });

  it('switch to comments page, add one comment', () => {
    editorPage.edit.toCommentsLink.click();
    editorPage.comment.newComment.textarea.sendKeys('First comment on this word.');
    editorPage.comment.newComment.postBtn.click();
  });

  it('comments page: check that comment shows up', () => {
    var comment = editorPage.comment.getComment(0);
    expect<any>(comment.wholeComment.isPresent()).toBe(true);

    // Earlier tests modify the avatar and name of the manager user; don't check those
    //expect<any>(comment.avatar.getAttribute('src')).toContain(constants.avatar);
    //expect<any>(comment.author.getText()).toEqual(constants.managerName);
    expect<any>(comment.score.getText()).toEqual('0');
    expect<any>(comment.plusOne.isPresent()).toBe(true);
    expect<any>(comment.content.getText()).toEqual('First comment on this word.');
    expect<any>(comment.date.getText()).toMatch(/ago|in a few seconds/);

    // This comment should have no "regarding" section
    expect<any>(comment.regarding.fieldLabel.isDisplayed()).toBe(false);
  });

  it('comments page: add comment about a specific part of the entry', () => {
    editorPage.comment.newComment.textarea.clear();
    editorPage.comment.newComment.textarea.sendKeys('Second comment.');
    editorPage.comment.entry.getOneFieldAllInputSystems('Word').first().click();
    editorPage.comment.newComment.postBtn.click();
  });

  it('comments page: check that second comment shows up', () => {
    var comment = editorPage.comment.getComment(-1);
    expect<any>(comment.wholeComment.isPresent()).toBe(true);

    // Earlier tests modify the avatar and name of the manager user; don't check those
    //expect<any>(comment.avatar.getAttribute('src')).toContain(constants.avatar);
    //expect<any>(comment.author.getText()).toEqual(constants.managerName);

    expect<any>(comment.score.getText()).toEqual('0');
    expect<any>(comment.plusOne.isPresent()).toBe(true);
    expect<any>(comment.content.getText()).toEqual('Second comment.');
    expect<any>(comment.date.getText()).toMatch(/ago|in a few seconds/);

    // This comment should have a "regarding" section
    expect<any>(comment.regarding.fieldLabel.isDisplayed()).toBe(true);
    var word    = constants.testEntry1.lexeme.th.value;
    var definition = constants.testEntry1.senses[0].definition.en.value;
    expect<any>(comment.regarding.word.getText()).toEqual(word);
    expect<any>(comment.regarding.definition.getText()).toEqual(definition);
    expect<any>(comment.regarding.fieldLabel.getText()).toEqual('Word');
    expect<any>(comment.regarding.fieldWsid .getText()).toEqual('th');
    expect<any>(comment.regarding.fieldValue.getText()).toEqual(word);
  });

  it('comments page: click +1 button on first comment', () => {
    var comment = editorPage.comment.getComment(0);
    expect<any>(comment.plusOne.getAttribute('data-ng-click')).not.toBe(null); // Should be clickable
    comment.plusOne.click();
    expect<any>(comment.score.getText()).toEqual('1');
  });

  it('comments page: +1 button disabled after clicking', () => {
    var comment = editorPage.comment.getComment(0);
    expect<any>(comment.plusOne.getAttribute('data-ng-click')).toBe(null); // Should NOT be clickable
    comment.plusOne.click();
    expect<any>(comment.score.getText()).toEqual('1'); // Should not change from previous test
  });

  it('comments page: refresh returns to comment', () => {
    var comment = editorPage.comment.getComment(0);
    browser.refresh();
    browser.wait(ExpectedConditions.visibilityOf(comment.content), CONDITION_TIMEOUT);
    expect<any>(comment.content.getText()).toEqual('First comment on this word.');
  });

});<commit_msg>fix editor-comments.spec.ts per Nigel's work<commit_after>import { browser, by, element, ExpectedConditions } from 'protractor';
import { BellowsLoginPage } from '../../../../bellows/pages/loginPage';
import { ProjectsPage } from '../../../../bellows/pages/projectsPage';
import { EditorPage } from '../../pages/editorPage';

const loginPage = new BellowsLoginPage();
const projectsPage = new ProjectsPage();
const editorPage = new EditorPage();
// tslint:disable-next-line:no-var-requires
const constants = require('../../../../testConstants');
const CONDITION_TIMEOUT = 3000;

describe('Editor Comments', () => {

  it('setup: login, click on test project', () => {
    loginPage.loginAsManager();
    projectsPage.get();
    projectsPage.clickOnProject(constants.testProjectName);
  });

  it('browse page has correct word count', () => {
    // flaky assertion, also test/app/languageforge/lexicon/editor/e2e/editor-entry.spec.js:20
    expect<any>(editorPage.browse.entriesList.count()).toEqual(editorPage.browse.getEntryCount());
    expect<any>(editorPage.browse.getEntryCount()).toBe(3);
  });

  it('click on first word', () => {
    editorPage.browse.findEntryByLexeme(constants.testEntry1.lexeme.th.value).click();
  });

  it('click first comment bubble, type in a comment, add text to another part of the entry, ' +
    'submit comment to appear on original field', () => {
      editorPage.comment.bubbles.first.click();
      browser.sleep(1000);
      editorPage.comment.newComment.textarea.sendKeys('First comment on this word.');
      editorPage.edit.getMultiTextInputs('Definition').first().sendKeys('change value - ');
      browser.sleep(500);
      editorPage.comment.newComment.postBtn.click();
    });

  it('comments panel: check that comment shows up', () => {
    const comment = editorPage.comment.getComment(0);
    expect<any>(comment.contextGuid.getAttribute('textContent')).toEqual('lexeme.th');

    // Earlier tests modify the avatar and name of the manager user; don't check those
    expect<any>(comment.score.getText()).toEqual('0 Likes');
    expect<any>(comment.plusOne.isPresent()).toBe(true);
    expect<any>(comment.content.getText()).toEqual('First comment on this word.');
    expect<any>(comment.date.getText()).toMatch(/ago|in a few seconds/);
  });

  it('comments panel: add comment to another part of the entry', () => {
    const definitionField = editorPage.edit.getMultiTextInputs('Definition').first();
    definitionField.clear();
    definitionField.sendKeys(
      constants.testEntry1.senses[0].definition.en.value
    );
    editorPage.comment.bubbles.second.click();
    editorPage.comment.newComment.textarea.clear();
    editorPage.comment.newComment.textarea.sendKeys('Second comment.');
    editorPage.comment.newComment.postBtn.click();
  });

  it('comments panel: check that second comment shows up', () => {
    const comment = editorPage.comment.getComment(-1);
    expect<any>(comment.wholeComment.isPresent()).toBe(true);

    // Earlier tests modify the avatar and name of the manager user; don't check those
    expect<any>(comment.score.getText()).toEqual('0');
    expect<any>(comment.plusOne.isPresent()).toBe(true);
    expect<any>(comment.content.getText()).toEqual('Second comment.');
    expect<any>(comment.date.getText()).toMatch(/ago|in a few seconds/);
  });

  it('comments panel: check regarding value is hidden when the field value matches', () => {
    const comment = editorPage.comment.getComment(-1);

    // Make sure it is hidden
    expect<any>(comment.regarding.container.isDisplayed()).toBe(false);

    // Change the field value and then make sure it appears
    editorPage.edit.getMultiTextInputs('Definition').first().sendKeys('update - ');
    expect<any>(comment.regarding.container.isDisplayed()).toBe(true);

    // Make sure the regarding value matches what was originally there
    const word    = constants.testEntry1.senses[0].definition.en.value;
    expect<any>(comment.regarding.fieldValue.getText()).toEqual(word);

    // old stuff
    // This comment should have a "regarding" section
  });

  it('comments panel: click +1 button on first comment', () => {
    const comment = editorPage.comment.getComment(0);
    editorPage.comment.bubbles.first.click();

    // Should be clickable
    expect(comment.plusOneActive.getAttribute('data-ng-click')).not.toBe(null);
    comment.plusOneActive.click();
    expect<any>(comment.score.getText()).toEqual('1 Like');
    });

  it('comments panel: +1 button disabled after clicking', () => {
    const comment = editorPage.comment.getComment(0);
    expect<any>(comment.plusOneInactive.isDisplayed()).toBe(true);

    // Should NOT be clickable
    expect<any>(comment.plusOneInactive.getAttribute('data-ng-click')).toBe(null);
    expect<any>(comment.score.getText()).toEqual('1 Like'); // Should not change from previous test
  });

  it('comments panel: refresh returns to comment', () => {
    const comment = editorPage.comment.getComment(0);
    browser.refresh();
    browser.wait(ExpectedConditions.visibilityOf(editorPage.comment.bubbles.first),
      CONDITION_TIMEOUT);
    editorPage.comment.bubbles.first.click();
    browser.sleep(1000);
    expect<any>(comment.content.getText()).toEqual('First comment on this word.');
  });

  it('comments panel: close comments panel clicking on bubble', () => {
    editorPage.comment.bubbles.first.click();
    browser.sleep(1000);
    expect<any>(editorPage.commentDiv.getAttribute('class')).not.toContain('panel-visible');
  });

  it('comments panel: show all comments', () => {
    editorPage.edit.toCommentsLink.click();
    browser.sleep(1000);
    expect<any>(editorPage.commentDiv.getAttribute('class')).toContain('panel-visible');
  });

  it('comments panel: close all comments clicking on main comments button', () => {
    editorPage.edit.toCommentsLink.click();
    browser.sleep(1000);
    expect<any>(editorPage.commentDiv.getAttribute('class')).not.toContain('panel-visible');
  });
});
{'fraction_non_alphanumeric': 0.16399484061175604, 'fraction_numerical': 0.0065413672378846505, 'mean_word_length': 4.4031856645097065, 'pattern_counts': {'":': 0, '<': 54, '<?xml version=': 0, '>': 80, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, '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': '4332997', 'n_tokens_mistral': 3137, 'n_tokens_neox': 3106, 'n_words': 600}