Skip to content

Commit

Permalink
Fix oppia#15413: ViewDestroyedError Frontend flake and other flakes a…
Browse files Browse the repository at this point in the history
…lso present. (oppia#16030)

* Fix ViewDestroyedError frontend flake

* Fix more FE flakes
  • Loading branch information
gp201 authored Sep 10, 2022
1 parent 40a1d9c commit 7751fb0
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import { ImageUploaderComponent } from 'components/forms/custom-forms-directives
import { WindowDimensionsService } from 'services/contextual/window-dimensions.service';
import { of } from 'rxjs';

describe('Upload Blog Post Thumbnail Modal Component', () => {
describe('Upload Blog Post Thumbnail Component', () => {
let fixture: ComponentFixture<UploadBlogPostThumbnailComponent>;
let componentInstance: UploadBlogPostThumbnailComponent;
let windowDimensionsService: WindowDimensionsService;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,8 +94,15 @@ export class UploadBlogPostThumbnailComponent implements OnInit {
this.uploadedImage = decodeURIComponent(
(e.target as FileReader).result as string);
}
this.changeDetectorRef.detectChanges();
this.initializeCropper();
try {
this.changeDetectorRef.detectChanges();
this.initializeCropper();
} catch (viewDestroyedError) {
// This try catch block handles the following error in FE tests:
// ViewDestroyedError:
// Attempt to use a destroyed view: detectChanges thrown.
// No further action is needed.
}
};
reader.readAsDataURL(file);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,11 @@ describe('Contributor dashboard page', () => {
fakeAsync(() => {
getTranslatableTopicNamesAsyncSpy.and.returnValue(
Promise.resolve([]));
// The `topicName` is set to undefined below since ngOnInit() does not
// initialize the variable as undefined. This means that if another
// frontend test is run before this test, the topicName will be set to
// the value of the previous test.
component.topicName = undefined;

component.ngOnInit();
tick();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ import { HttpClientTestingModule } from '@angular/common/http/testing';
import { ExplorationDataService } from '../services/exploration-data.service';
import { ExplorationBackendDict } from 'domain/exploration/ExplorationObjectFactory';
import { NumberAttemptsService } from 'pages/exploration-player-page/services/number-attempts.service';
import { RouterService } from '../services/router.service';


class MockNgbModalRef {
Expand Down Expand Up @@ -67,6 +68,7 @@ describe('Preview Tab Component', () => {
let explorationParamChangesService: ExplorationParamChangesService;
let explorationStatesService: ExplorationStatesService;
let graphDataService: GraphDataService;
let routerService: RouterService;
let stateEditorService: StateEditorService;
let stateObjectFactory: StateObjectFactory;
let paramChangeObjectFactory: ParamChangeObjectFactory;
Expand Down Expand Up @@ -129,6 +131,7 @@ describe('Preview Tab Component', () => {
fixture = TestBed.createComponent(PreviewTabComponent);
component = fixture.componentInstance;
numberAttemptsService = TestBed.inject(NumberAttemptsService);
routerService = TestBed.inject(RouterService);
paramChangeObjectFactory = TestBed.inject(ParamChangeObjectFactory);
stateObjectFactory = TestBed.inject(StateObjectFactory);
explorationEngineService = TestBed.inject(ExplorationEngineService);
Expand Down Expand Up @@ -236,6 +239,7 @@ describe('Preview Tab Component', () => {
fakeAsync(() => {
spyOn(explorationFeaturesService, 'areParametersEnabled')
.and.returnValue(false);
spyOn(routerService, 'navigateToMainTab');
component.allParams = {};

expect(component.showParameterSummary()).toBe(false);
Expand All @@ -255,6 +259,7 @@ describe('Preview Tab Component', () => {
flushMicrotasks();

expect(ngbModal.open).toHaveBeenCalled();
expect(routerService.navigateToMainTab).toHaveBeenCalled();
}));

it('should getManualParamChanges', fakeAsync(() => {
Expand Down

0 comments on commit 7751fb0

Please sign in to comment.