<commit_before>import {async} from '@angular/core/testing';
import {TennisGame1Component} from './tennis-game1.component';
import {TennisComponentTester, tennisPlayerNumbers} from '../../test/tennisTester';
import {
  blockDisplay,
  boldFontWeight, darkGrayColor, expectedVerticalSpacingBetweenScores,
  flex, lightGrayColor,
  slightlyRoundedBottomCorners,
  spaceBetween,
  tennisBallOpticYellowColor, tennisCardMaxWidth, tennisCourtGreenColor,
  twentyPixels, whiteColor,
  zeroPixels
} from '../../test/expectedStyles';
import {
  getScoreButton,
  tennisGameCardContents,
  overallScore,
  overallScoreLabel,
  overallScoreSection,
  player1ScoreInput,
  player2ScoreInput,
  tennisGameCard,
  tennisGameCardTitle,
  tennisGameCardSubtitle, player1ScoreLabel, player2ScoreLabel, errorLabelForPlayer
} from '../../test/selectors';
import {
  expectedTennisScores,
  expectedText,
  invalidScores,
  scoreErrorMessage,
  threeSecondsOfWaitingBeforeGivingInputValidationFeedback,
  winningScores
} from '../../test/expectedResults';
import {ManagerOfZanzibar} from './ZanzibarManager';
import {smartSpyOn} from '../../test/smartSpy';
import {maxScore, minScore, numberType} from '../../test/expectedElementAttributes';

describe('Tennis Game 1', () => {
  let tennisTester: TennisComponentTester;

  beforeEach(async(async () => {
    tennisTester = new TennisComponentTester();
    await tennisTester.beforeEach([TennisGame1Component]);
  }));

  describe('Scoring', () => {

    it('should have correct initial value before any scores are entered', () => {
      tennisTester.verifyLabelText(overallScore, '');
      tennisTester.verifyInputValue(player1ScoreInput, '0');
      tennisTester.verifyInputValue(player2ScoreInput, '0');
    });

    expectedTennisScores.forEach(({player1Score, player2Score, expectedScore, expectedErrors}) => {
      it(`should score '${expectedScore}' when player 1 has '${player1Score}' and player 2 has '${player2Score}'`, () => {
        tennisTester.verifyButtonIsEnabled(getScoreButton);

        tennisTester.enterPlayersScores(player1Score, player2Score);
        tennisTester.selectElement(getScoreButton);

        tennisTester.verifyInputValidation(expectedErrors);
        tennisTester.verifyLabelText(overallScore, expectedScore);
      });
    });

    describe('Score Input', () => {
      let player1ScoreInputElement;
      let player2ScoreInputElement;

      beforeEach(() => {
        player1ScoreInputElement = tennisTester.getElement(player1ScoreInput);
        player2ScoreInputElement = tennisTester.getElement(player2ScoreInput);
      });

      it('should only allow numbers', () => {
        expect(player1ScoreInputElement.attributes.type).toBe(numberType);
        expect(player2ScoreInputElement.attributes.type).toBe(numberType);
      });

      it('should prevent large numbers via the incrementer button', () => {
        expect(player1ScoreInputElement.attributes.max).toBe(maxScore);
        expect(player2ScoreInputElement.attributes.max).toBe(maxScore);
      });

      it('should prevent negative numbers via the decrementer button', () => {
        expect(player1ScoreInputElement.attributes.min).toBe(minScore);
        expect(player2ScoreInputElement.attributes.min).toBe(minScore);
      });

      // todo: way to get rid of setTimeout?
      // todo: set all tennis tester functions to explicit public vs. private
      // todo: apply this to other tennis games spec files
      it('should show validation feedback after user starts entering data for more than 3 seconds', (done) => {
        tennisTester.verifyScoreInputsHaveBeenTouched(false);
        tennisTester.verifyNoScoreInputErrorMessages();

        tennisTester.setInputValue(player1ScoreInput, -3);
        tennisTester.setInputValue(player2ScoreInput, -1);
        tennisTester.selectElement(getScoreButton);

        setTimeout(() => {
          tennisTester.verifyAllScoreInputsHaveAnErrorMessage();
          tennisTester.verifyScoreInputsHaveBeenTouched(true);
          expect(tennisTester.debounceDueTimesSent[0]).toBe(threeSecondsOfWaitingBeforeGivingInputValidationFeedback);
          expect(tennisTester.debounceDueTimesSent[1]).toBe(threeSecondsOfWaitingBeforeGivingInputValidationFeedback);
          expect(tennisTester.debounceDueTimesSent.length).toBe(tennisPlayerNumbers.length);
          done();
          }, 0);
      });
    });
  });

  describe('Card', () => {<commit_msg>t - replace smelly setTimeout with whenRenderingDone<commit_after>import {async} from '@angular/core/testing';
import {TennisGame1Component} from './tennis-game1.component';
import {TennisComponentTester, tennisPlayerNumbers} from '../../test/tennisTester';
import {
  blockDisplay,
  boldFontWeight, darkGrayColor, expectedVerticalSpacingBetweenScores,
  flex, lightGrayColor,
  slightlyRoundedBottomCorners,
  spaceBetween,
  tennisBallOpticYellowColor, tennisCardMaxWidth, tennisCourtGreenColor,
  twentyPixels, whiteColor,
  zeroPixels
} from '../../test/expectedStyles';
import {
  getScoreButton,
  tennisGameCardContents,
  overallScore,
  overallScoreLabel,
  overallScoreSection,
  player1ScoreInput,
  player2ScoreInput,
  tennisGameCard,
  tennisGameCardTitle,
  tennisGameCardSubtitle, player1ScoreLabel, player2ScoreLabel, errorLabelForPlayer
} from '../../test/selectors';
import {
  expectedTennisScores,
  expectedText,
  invalidScores,
  scoreErrorMessage,
  threeSecondsOfWaitingBeforeGivingInputValidationFeedback,
  winningScores
} from '../../test/expectedResults';
import {ManagerOfZanzibar} from './ZanzibarManager';
import {smartSpyOn} from '../../test/smartSpy';
import {maxScore, minScore, numberType} from '../../test/expectedElementAttributes';

describe('Tennis Game 1', () => {
  let tennisTester: TennisComponentTester;

  beforeEach(async(async () => {
    tennisTester = new TennisComponentTester();
    await tennisTester.beforeEach([TennisGame1Component]);
  }));

  describe('Scoring', () => {

    it('should have correct initial value before any scores are entered', () => {
      tennisTester.verifyLabelText(overallScore, '');
      tennisTester.verifyInputValue(player1ScoreInput, '0');
      tennisTester.verifyInputValue(player2ScoreInput, '0');
    });

    expectedTennisScores.forEach(({player1Score, player2Score, expectedScore, expectedErrors}) => {
      it(`should score '${expectedScore}' when player 1 has '${player1Score}' and player 2 has '${player2Score}'`, () => {
        tennisTester.verifyButtonIsEnabled(getScoreButton);

        tennisTester.enterPlayersScores(player1Score, player2Score);
        tennisTester.selectElement(getScoreButton);

        tennisTester.verifyInputValidation(expectedErrors);
        tennisTester.verifyLabelText(overallScore, expectedScore);
      });
    });

    describe('Score Input', () => {
      let player1ScoreInputElement;
      let player2ScoreInputElement;

      beforeEach(() => {
        player1ScoreInputElement = tennisTester.getElement(player1ScoreInput);
        player2ScoreInputElement = tennisTester.getElement(player2ScoreInput);
      });

      it('should only allow numbers', () => {
        expect(player1ScoreInputElement.attributes.type).toBe(numberType);
        expect(player2ScoreInputElement.attributes.type).toBe(numberType);
      });

      it('should prevent large numbers via the incrementer button', () => {
        expect(player1ScoreInputElement.attributes.max).toBe(maxScore);
        expect(player2ScoreInputElement.attributes.max).toBe(maxScore);
      });

      it('should prevent negative numbers via the decrementer button', () => {
        expect(player1ScoreInputElement.attributes.min).toBe(minScore);
        expect(player2ScoreInputElement.attributes.min).toBe(minScore);
      });

      // todo: apply this to other tennis games spec files
      it('should show validation feedback after user starts entering data for more than 3 seconds', (done) => {
        tennisTester.verifyScoreInputsHaveBeenTouched(false);
        tennisTester.verifyNoScoreInputErrorMessages();

        tennisTester.setInputValue(player1ScoreInput, -3);
        tennisTester.setInputValue(player2ScoreInput, -1);
        tennisTester.selectElement(getScoreButton);

        tennisTester.fixture.whenRenderingDone().then(() => {
          tennisTester.verifyAllScoreInputsHaveAnErrorMessage();
          tennisTester.verifyScoreInputsHaveBeenTouched(true);
          expect(tennisTester.debounceDueTimesSent[0]).toBe(threeSecondsOfWaitingBeforeGivingInputValidationFeedback);
          expect(tennisTester.debounceDueTimesSent[1]).toBe(threeSecondsOfWaitingBeforeGivingInputValidationFeedback);
          expect(tennisTester.debounceDueTimesSent.length).toBe(tennisPlayerNumbers.length);
          done();
        });
      });
    });
  });

  describe('Card', () => {
{'fraction_non_alphanumeric': 0.11155152887882219, 'fraction_numerical': 0.008946772366930917, 'mean_word_length': 4.401223241590214, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 31, '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': '1460399', 'n_tokens_mistral': 2467, 'n_tokens_neox': 2458, 'n_words': 418}