<commit_before>/**
 * Horizontal-pager in-browser unit tests.
 *
 * Copyright (c) 2017 <NAME> (@localnerve), LocalNerve LLC
 * Copyrights licensed under the BSD License. See the accompanying LICENSE file for terms.
 */
/* global window, document, before, describe, it */
/* eslint-disable no-console, prefer-arrow-callback, func-names, no-underscore-dangle */

describe('Animation Tests', function () {
  const targetClass = 'page-item';
  const mainFrameId = '#demo-main';
  const twoFrameId = '#demo-two';
  const txComplete = 'translateX(0';

  /**
   * Make sure the moveResult has required properties.
   *
   * @param {Object} result - A moveResult object as documented/expected.
   */
  function verifyMoveResult (result) {
    if (!result) {
      throw new Error('moveResult was unexpectedly null');
    }
    if (!('currTargetIndex' in result)) {
      throw new Error('moveResult missing currTargetIndex property');
    }
    if (!('prevTargetIndex' in result)) {
      throw new Error('moveResult missing prevTargetIndex property');
    }
    if (!('distance' in result)) {
      throw new Error('moveResult missing distance property');
    }
  }

  /**
   * Verify the moveResult is as expected.
   *
   * @param {Object} doc - The contentDocument for the frame under test.
   * @param {Number} expectedPrev - The number expected for prevTargetIndex.
   * @param {Number} expectedCurr - The number expected for currTargetIndex.
   * @param {Object} result - The moveResult object from horizontalPager.
   */
  function verifyResult (doc, expectedPrev, expectedCurr, result) {
    verifyMoveResult(result);

    const pages = doc.querySelectorAll(`.${targetClass}`);

    const currTransform = pages[result.currTargetIndex].style.transform;
    const notCurrent = [...Array(pages.length).keys()];
    notCurrent.splice(result.currTargetIndex, 1);

    // The current completed tranform should be a form of translateX(0)
    currTransform.should.contain(txComplete);

    // All the others should not be that.
    notCurrent.forEach((pageIndex) => {
      const pageTransform = pages[pageIndex].style.transform;
      pageTransform.should.not.contain(txComplete);
    });

    // Make sure the result indexes agree with the expected situation.
    expectedCurr.should.equal(result.currTargetIndex);
    expectedPrev.should.equal(result.prevTargetIndex);
  }

  /**
   * Get horizontalPager and bound verifyResult bound to a particular iframe
   * hosted demo.
   *
   * @param {String} demoId - The id of the desired frame hosting a demo page.
   * @returns {Promise} Resolves to object with `horizontalPager` and `verify`.
   */
  function getDemoSubjects (demoId) {
    const demo = document.querySelector(demoId);
    const verify = verifyResult.bind(this, demo.contentDocument);
    const getMethods = {
      [mainFrameId]: window.__testUtils.getHorizontalPagerMain,
      [twoFrameId]: window.__testUtils.getHorizontalPagerTwo
    };

    return getMethods[demoId]()
    .then(horizontalPager => ({
      horizontalPager,
      verify
    }));
  }

  describe('main demo tests', function () {
    let horizontalPager;
    let verify;

    before('main demo tests', function () {
      return getDemoSubjects(mainFrameId).then((subjects) => {
        horizontalPager = subjects.horizontalPager;
        verify = subjects.verify;<commit_msg>readability adjustment<commit_after>/**
 * Horizontal-pager in-browser unit tests.
 *
 * Copyright (c) 2017 <NAME> (@localnerve), LocalNerve LLC
 * Copyrights licensed under the BSD License. See the accompanying LICENSE file for terms.
 */
/* global window, document, before, describe, it */
/* eslint-disable no-console, prefer-arrow-callback, func-names, no-underscore-dangle */

describe('Animation Tests', function () {
  const targetClass = 'page-item';
  const mainFrameId = '#demo-main';
  const twoFrameId = '#demo-two';
  const txComplete = 'translateX(0';

  /**
   * Make sure the moveResult has required properties.
   *
   * @param {Object} result - A moveResult object as documented/expected.
   */
  function verifyMoveResult (result) {
    if (!result) {
      throw new Error('moveResult was unexpectedly null');
    }
    if (!('currTargetIndex' in result)) {
      throw new Error('moveResult missing currTargetIndex property');
    }
    if (!('prevTargetIndex' in result)) {
      throw new Error('moveResult missing prevTargetIndex property');
    }
    if (!('distance' in result)) {
      throw new Error('moveResult missing distance property');
    }
  }

  /**
   * Verify the moveResult is as expected.
   *
   * @param {Object} doc - The contentDocument for the frame under test.
   * @param {Number} expectedPrev - The number expected for prevTargetIndex.
   * @param {Number} expectedCurr - The number expected for currTargetIndex.
   * @param {Object} result - The moveResult object from horizontalPager.
   */
  function verifyResult (doc, expectedPrev, expectedCurr, result) {
    verifyMoveResult(result);

    const pages = doc.querySelectorAll(`.${targetClass}`);

    const currTransform = pages[result.currTargetIndex].style.transform;
    const notCurrent = [...Array(pages.length).keys()];
    notCurrent.splice(result.currTargetIndex, 1);

    // The current completed tranform should be a form of translateX(0)
    currTransform.should.contain(txComplete);

    // All the others should not be that.
    notCurrent.forEach((pageIndex) => {
      const pageTransform = pages[pageIndex].style.transform;
      pageTransform.should.not.contain(txComplete);
    });

    // Make sure the result indexes agree with the expected situation.
    expectedCurr.should.equal(result.currTargetIndex);
    expectedPrev.should.equal(result.prevTargetIndex);
  }

  /**
   * Get horizontalPager and bound verifyResult bound to a particular iframe
   * hosted demo.
   *
   * @param {String} demoId - The id of the desired frame hosting a demo page.
   * @returns {Promise} Resolves to object with `horizontalPager` and `verify`.
   */
  function getDemoSubjects (demoId) {
    const demo = document.querySelector(demoId);
    const verify = verifyResult.bind(this, demo.contentDocument);
    const getMethods = {
      [mainFrameId]: window.__testUtils.getHorizontalPagerMain,
      [twoFrameId]: window.__testUtils.getHorizontalPagerTwo
    };

    return getMethods[demoId]().then(horizontalPager => ({
      horizontalPager,
      verify
    }));
  }

  describe('main demo tests', function () {
    let horizontalPager;
    let verify;

    before('main demo tests', function () {
      return getDemoSubjects(mainFrameId).then((subjects) => {
        horizontalPager = subjects.horizontalPager;
        verify = subjects.verify;
{'fraction_non_alphanumeric': 0.11197141155449672, 'fraction_numerical': 0.002084574151280524, 'mean_word_length': 3.5232323232323233, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 11, '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': '6642611', 'n_tokens_mistral': 1881, 'n_tokens_neox': 1846, 'n_words': 545}