Commits

Rezart Vata authored ed6cb04de44
[CST-4875] Fix unit testing
No tags

src/app/info/feedback/feedback-form/feedback-form.component.spec.ts

Modified
7 7 import { By } from '@angular/platform-browser';
8 8 import { RouteService } from '../../../core/services/route.service';
9 9 import { routeServiceStub } from '../../../shared/testing/route-service.stub';
10 10 import { FormBuilder } from '@angular/forms';
11 11 import { NotificationsService } from '../../../shared/notifications/notifications.service';
12 12 import { NotificationsServiceStub } from '../../../shared/testing/notifications-service.stub';
13 13 import { AuthService } from '../../../core/auth/auth.service';
14 14 import { AuthServiceStub } from '../../../shared/testing/auth-service.stub';
15 15 import { of } from 'rxjs';
16 16 import { Feedback } from '../../../core/feedback/models/feedback.model';
17 +import { Router } from '@angular/router';
18 +import { RouterMock } from '../../../shared/mocks/router.mock';
17 19
18 20
19 21 describe('FeedbackFormComponent', () => {
20 22 let component: FeedbackFormComponent;
21 23 let fixture: ComponentFixture<FeedbackFormComponent>;
22 24 let de: DebugElement;
23 25 const notificationService = new NotificationsServiceStub();
24 26 const feedbackDataServiceStub = jasmine.createSpyObj('feedbackDataService', {
25 27 create: of(new Feedback())
26 28 });
27 29 const authService: AuthServiceStub = Object.assign(new AuthServiceStub(), {
28 30 getAuthenticatedUserFromStore: () => {
29 31 return of(EPersonMock);
30 32 }
31 33 });
34 + const routerStub = new RouterMock();
32 35
33 36 beforeEach(waitForAsync(() => {
34 37 TestBed.configureTestingModule({
35 38 imports: [TranslateModule.forRoot()],
36 39 declarations: [FeedbackFormComponent],
37 40 providers: [
38 41 { provide: RouteService, useValue: routeServiceStub },
39 42 { provide: FormBuilder, useValue: new FormBuilder() },
40 43 { provide: NotificationsService, useValue: notificationService },
41 44 { provide: FeedbackDataService, useValue: feedbackDataServiceStub },
42 45 { provide: AuthService, useValue: authService },
46 + { provide: Router, useValue: routerStub },
43 47 ],
44 48 schemas: [NO_ERRORS_SCHEMA]
45 49 }).compileComponents();
46 50 }));
47 51
48 52 beforeEach(() => {
49 53 fixture = TestBed.createComponent(FeedbackFormComponent);
50 54 component = fixture.componentInstance;
51 55 de = fixture.debugElement;
52 56 fixture.detectChanges();
53 57 });
54 58
55 59 it('should create', () => {
56 60 expect(component).toBeTruthy();
57 61 });
58 62
59 63 it('should have page value', () => {
60 - expect(de.query(By.css('input[name=page]')).nativeElement.value).toEqual('/home');
64 + expect(component.feedbackForm.controls.page.value).toEqual('/home');
61 65 });
62 66
63 67 it('should have email if ePerson', () => {
64 68 expect(component.feedbackForm.controls.email.value).toEqual('test@test.com');
65 69 });
66 70
67 71 it('should have disabled button', () => {
68 72 expect(de.query(By.css('button')).nativeElement.disabled).toBeTrue();
69 73 });
70 74

Everything looks good. We'll let you know here if there's anything you should know about.

Add shortcut