<commit_before>import { async, ComponentFixture, TestBed } from '@angular/core/testing';
import { TennisGame3Component } from './tennis-game3.component';
import {expectedScores} from '../../test/testHelper';
import {FormsModule, ReactiveFormsModule} from '@angular/forms';

describe('TennisGame3Component', () => {
  let component: TennisGame3Component;
  let fixture: ComponentFixture<TennisGame3Component>;
  let element: any;

  beforeEach(async(() => {
    TestBed.configureTestingModule({
      imports: [FormsModule, ReactiveFormsModule],
      declarations: [ TennisGame3Component ]
    })
    .compileComponents();
  }));

  beforeEach(() => {
    fixture = TestBed.createComponent(TennisGame3Component);
    component = fixture.componentInstance;
    element = fixture.nativeElement;
    fixture.detectChanges();
  });

  it('should create', () => {
    expect(component).toBeTruthy();
  });

  expectedScores.forEach(([player1Score, player2Score, expectedScore]) => {
    it(`should score '${expectedScore}' when player 1 has '${player1Score}' and player 2 has '${player2Score}'`, () => {
      expect(component.overallScore).toBe('');

      setPlayerScores(player1Score, player2Score);
      selectElement('#get-score-button');

      expect(component.overallScore).toBe(expectedScore as string);
    });

    function setPlayerScores(newPlayer1Score: number | string, newPlayer2Score: number | string) {
      const tennisFormControls = component.tennisGameForm.controls;
      tennisFormControls.player1Score.setValue(newPlayer1Score);
      tennisFormControls.player2Score.setValue(newPlayer2Score);
    }

    function selectElement(selector: string) {
      const getScoreButton = element.querySelector(selector);
      getScoreButton.click();
    }
  });
});<commit_msg>t - improved test for tennis 3 by inputting data via element instead of the under the hood control<commit_after>import { async, ComponentFixture, TestBed } from '@angular/core/testing';
import {FormsModule, ReactiveFormsModule} from '@angular/forms';
import { TennisGame3Component } from './tennis-game3.component';
import {expectedScores} from '../../test/testHelper';

describe('TennisGame3Component', () => {
  let component: TennisGame3Component;
  let fixture: ComponentFixture<TennisGame3Component>;
  let element: any;

  beforeEach(async(() => {
    TestBed.configureTestingModule({
      imports: [FormsModule, ReactiveFormsModule],
      declarations: [ TennisGame3Component ]
    })
    .compileComponents();
  }));

  beforeEach(() => {
    fixture = TestBed.createComponent(TennisGame3Component);
    component = fixture.componentInstance;
    element = fixture.nativeElement;
    fixture.detectChanges();
  });

  it('should create', () => {
    expect(component).toBeTruthy();
  });

  expectedScores.forEach(([player1Score, player2Score, expectedScore]) => {
    it(`should score '${expectedScore}' when player 1 has '${player1Score}' and player 2 has '${player2Score}'`, () => {
      expect(component.overallScore).toBe('');

      setInputValue('#player-one-score', player1Score);
      setInputValue('#player-two-score', player2Score);
      selectElement('#get-score-button');

      expect(component.overallScore).toBe(expectedScore as string);
    });

    function setInputValue(inputSelector: string, newPlayer1Score: number | string) {
      const player1ScoreInput = element.querySelector(inputSelector);
      player1ScoreInput.value = newPlayer1Score;
      player1ScoreInput.dispatchEvent(new Event('input'));
    }

    function selectElement(selector: string) {
      const getScoreButton = element.querySelector(selector);
      getScoreButton.click();
    }
  });
});
{'fraction_non_alphanumeric': 0.13336947682298725, 'fraction_numerical': 0.011385199240986717, 'mean_word_length': 4.557228915662651, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 17, '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': '3106567', 'n_tokens_mistral': 1039, 'n_tokens_neox': 1022, 'n_words': 200}