Skip to content

Commit

Permalink
fix unit tests after testing if a lesson is used
Browse files Browse the repository at this point in the history
  • Loading branch information
Bali, Doron (db991h) authored and Roi ben haim (rb136m) committed Nov 17, 2018
1 parent e83ec50 commit e949db7
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 6 deletions.
12 changes: 9 additions & 3 deletions src/app/pages/lesson/lesson.component.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,11 @@ import { Lesson } from '../../models/lesson.model';
import { MatHeaderRow, MatRowDef, MatHeaderRowDef, MatSort, MatPaginator, MatDialog } from '@angular/material';

import { Observable } from 'rxjs-compat';
import { ClassService } from '../class/services/class.graphql.service';

describe('lesson component', () => {
let lessonServiceMock: Partial<LessonService>;
let classServiceMock: Partial<ClassService>;
let lessonTestData: Lesson[] = [];
let lessonDialogMock: Partial<MatDialog>;
let lessonDialogMockValue: boolean;
Expand All @@ -33,6 +35,9 @@ describe('lesson component', () => {
getAllLessons: jest.fn(),
delete: jest.fn(),
};
classServiceMock = {
getAllClasses: jest.fn().mockReturnValue(Observable.of([])),
};
lessonDialogMockValue = true;
lessonDialogMock = {
open: jest.fn().mockReturnValue({
Expand All @@ -45,6 +50,7 @@ describe('lesson component', () => {
providers: [
{ provide: LessonService, useValue: lessonServiceMock },
{ provide: MatDialog, useValue: lessonDialogMock },
{ provide: ClassService, useValue: classServiceMock },
],
schemas: [NO_ERRORS_SCHEMA],
});
Expand Down Expand Up @@ -87,7 +93,7 @@ describe('lesson component', () => {
});
const fixture = TestBed.createComponent(LessonComponent);
await fixture.componentInstance.ngOnInit(); // this triggers the subCleaner instantiator.
await fixture.componentInstance.deleteLesson('1');
await fixture.componentInstance.deleteLesson('1', 'anyTitle');
fixture.detectChanges();
await fixture.whenRenderingDone();
expect(lessonDialogMock.open).toHaveBeenCalled();
Expand All @@ -103,7 +109,7 @@ describe('lesson component', () => {
lessonDialogMockValue = true;
const fixture = TestBed.createComponent(LessonComponent);
await fixture.componentInstance.ngOnInit(); // this triggers the subCleaner instantiator.
await fixture.componentInstance.deleteLesson('1');
await fixture.componentInstance.deleteLesson('1', 'anyTitle');
fixture.detectChanges();
await fixture.whenRenderingDone();
expect(lessonServiceMock.delete).toHaveBeenCalledWith('1');
Expand All @@ -120,7 +126,7 @@ describe('lesson component', () => {

const fixture = TestBed.createComponent(LessonComponent);
await fixture.componentInstance.ngOnInit(); // this triggers the subCleaner instantiator.
await fixture.componentInstance.deleteLesson('1');
await fixture.componentInstance.deleteLesson('1', 'anyTitle');
fixture.detectChanges();
await fixture.whenRenderingDone();
expect(lessonServiceMock.delete).not.toHaveBeenCalled();
Expand Down
5 changes: 2 additions & 3 deletions src/app/pages/lesson/lesson.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import { first } from 'rxjs/operators';
import { DeleteLessonDialogComponent } from './dialogs/delete/delete-lesson.dialog';
import { Subscription } from 'rxjs';
import { ClassService } from '../class/services/class.graphql.service';
import { cleanSession } from 'selenium-webdriver/safari';
import { Class } from '../../models/class.model';

@Component({
Expand Down Expand Up @@ -51,7 +50,7 @@ export class LessonComponent implements OnInit {
.pipe(first())
.subscribe(async (result) => {
if (result === true) {
const sub = this.classService
const getAllClassesSub = this.classService
.getAllClasses()
.map((classes: Class[]) =>
classes.filter(
Expand All @@ -66,7 +65,7 @@ export class LessonComponent implements OnInit {
alert('cant delete - used');
}
});
this.subCollector.add(sub);
this.subCollector.add(getAllClassesSub);
}
}),
);
Expand Down

0 comments on commit e949db7

Please sign in to comment.