Skip to content

Commit

Permalink
TEMP: Attempt to fix flaky tests
Browse files Browse the repository at this point in the history
  • Loading branch information
ybnd committed Mar 10, 2022
1 parent a24ec06 commit 38d46af
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 13 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import { ChangeDetectionStrategy, Injector, NO_ERRORS_SCHEMA } from '@angular/core';
import { ComponentFixture, TestBed, waitForAsync } from '@angular/core/testing';
import {
ComponentFixture, discardPeriodicTasks, fakeAsync, flush, flushMicrotasks, TestBed, tick, waitForAsync,
} from '@angular/core/testing';
import { FormBuilder, FormGroup, ReactiveFormsModule } from '@angular/forms';
import { By } from '@angular/platform-browser';

Expand Down Expand Up @@ -121,7 +123,9 @@ describe('ClaimedTaskActionsRejectComponent', () => {
beforeEach(() => {
spyOn(component.processCompleted, 'emit');
spyOn(component, 'startActionExecution').and.returnValue(of(null));
});

it('should start the action execution', fakeAsync(() => {
expectedBody = {
[component.option]: 'true',
reason: null
Expand All @@ -135,12 +139,14 @@ describe('ClaimedTaskActionsRejectComponent', () => {

const form = ((document as any).querySelector('form'));
form.dispatchEvent(new Event('ngSubmit'));
fixture.detectChanges();
});

it('should start the action execution', () => {
fixture.detectChanges();
tick();
flush();
flushMicrotasks();
discardPeriodicTasks();
expect(component.startActionExecution).toHaveBeenCalled();
});
}));

});

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import { ChangeDetectorRef, Component, CUSTOM_ELEMENTS_SCHEMA, SimpleChange } from '@angular/core';
import { ComponentFixture, inject, TestBed, waitForAsync } from '@angular/core/testing';
import {
ComponentFixture, discardPeriodicTasks, fakeAsync, flush, flushMicrotasks, inject, TestBed, tick, waitForAsync,
} from '@angular/core/testing';
import { By } from '@angular/platform-browser';

import { TestScheduler } from 'rxjs/testing';
Expand Down Expand Up @@ -182,24 +184,25 @@ describe('SubmissionFormFooterComponent Component', () => {
expect(submissionServiceStub.dispatchDeposit).toHaveBeenCalledWith(submissionId);
});

it('should call dispatchDiscard on discard confirmation', (done) => {
it('should call dispatchDiscard on discard confirmation', fakeAsync(() => {
comp.showDepositAndDiscard = observableOf(true);
fixture.detectChanges();
const modalBtn = fixture.debugElement.query(By.css('.btn-danger'));

modalBtn.nativeElement.click();
fixture.detectChanges();


const confirmBtn: any = ((document as any).querySelector('.btn-danger:nth-child(2)'));
confirmBtn.click();

fixture.detectChanges();

fixture.whenStable().then(() => {
expect(submissionServiceStub.dispatchDiscard).toHaveBeenCalledWith(submissionId);
done();
});
});
tick();
flush();
flushMicrotasks();
discardPeriodicTasks();
expect(submissionServiceStub.dispatchDiscard).toHaveBeenCalledWith(submissionId);
}));

it('should not have deposit button disabled when submission is not valid', () => {
comp.showDepositAndDiscard = observableOf(true);
Expand Down

0 comments on commit 38d46af

Please sign in to comment.