Skip to content

Commit

Permalink
Dispatch change instead of input event in onSubmit create test and ge…
Browse files Browse the repository at this point in the history
…t element by test id instead of id
  • Loading branch information
RandomTannenbaum committed Oct 22, 2024
1 parent 4479528 commit 1595411
Showing 1 changed file with 5 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -125,16 +125,6 @@ describe('ObjectiveDialogComponent', () => {
it.each([['DRAFT'], ['ONGOING']])(
'onSubmit create',
fakeAsync((state: string) => {
matDataMock = {
objectiveId: 99,
teamId: 1,
} as any as MatDialogDataInterface;

TestBed.overrideProvider(MAT_DIALOG_DATA, { useValue: matDataMock });
TestBed.compileComponents();
component = fixture.componentInstance;
fixture.detectChanges();

//Prepare data
let title: string = 'title';
let description: string = 'description';
Expand All @@ -157,17 +147,19 @@ describe('ObjectiveDialogComponent', () => {
descriptionInput.value = description;
loader.getHarness(MatCheckboxHarness).then((checkBox) => checkBox.check());
tick(200);
const quarterSelect: HTMLSelectElement = fixture.debugElement.query(By.css('#quarter')).nativeElement;
const quarterSelect: HTMLSelectElement = fixture.debugElement.query(
By.css('[data-testId="quarterSelect"]'),
).nativeElement;
quarterSelect.value = quarter.toString();
// Trigger update of form
fixture.detectChanges();
titleInput.dispatchEvent(new Event('input'));
descriptionInput.dispatchEvent(new Event('input'));
quarterSelect.dispatchEvent(new Event('input'));
quarterSelect.dispatchEvent(new Event('change'));

const rawFormValue = component.objectiveForm.getRawValue();
expect(rawFormValue.description).toBe(description);
expect(rawFormValue.quarter).toBe(quarter);
expect(rawFormValue.quarter).toBe(quarter.toString());
expect(rawFormValue.team).toBe(team);
expect(rawFormValue.title).toBe(title);
expect(rawFormValue.createKeyResults).toBe(createKeyresults);
Expand Down

0 comments on commit 1595411

Please sign in to comment.