This repository was archived by the owner on Nov 20, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathuser-edit-location.component.spec.ts
More file actions
96 lines (74 loc) · 2.97 KB
/
user-edit-location.component.spec.ts
File metadata and controls
96 lines (74 loc) · 2.97 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
import { async, fakeAsync, tick, ComponentFixture, TestBed } from '@angular/core/testing';
import { Component, Input, Output, EventEmitter } from '@angular/core';
import { By } from '@angular/platform-browser';
import { ActivatedRoute } from '@angular/router';
import { Observable } from 'rxjs/Observable';
import { ModelService } from 'app/model.service';
import { NotificationsService } from 'app/notifications/notifications.service';
import { User } from 'app/shared/types';
import { UserEditLocationComponent } from './user-edit-location.component';
@Component({ selector: 'app-select-location', template: '' })
class SelectLocationStubComponent {
@Input() location;
@Input() disabled;
// tslint:disable-next-line:no-output-on-prefix
@Output() submit = new EventEmitter<[number, number]>();
}
class ActivatedRouteStub {
parent = {
data: Observable.of({ user: { username: 'test' } })
};
}
class ModelStubService {
async updateUser(username, fields) {
return { username, preciseLocation: fields.location } as User;
}
}
describe('UserEditLocationComponent', () => {
let component: UserEditLocationComponent;
let fixture: ComponentFixture<UserEditLocationComponent>;
let spyNotificationsInfo: jasmine.Spy;
beforeEach(async(() => {
TestBed.configureTestingModule({
declarations: [
UserEditLocationComponent,
SelectLocationStubComponent
],
providers: [
{ provide: ActivatedRoute, useClass: ActivatedRouteStub },
{ provide: ModelService, useClass: ModelStubService },
NotificationsService
]
})
.compileComponents();
}));
beforeEach(() => {
fixture = TestBed.createComponent(UserEditLocationComponent);
component = fixture.componentInstance;
// spy on the NotificationsService.info()
const notificationsService = fixture.debugElement.injector.get(NotificationsService);
spyNotificationsInfo = spyOn(notificationsService, 'info');
fixture.detectChanges();
});
it('should create', () => {
expect(component).toBeTruthy();
});
it('should notify about success after a successful update', fakeAsync(() => {
// emit the location-update event
const selectLocation = fixture.debugElement.query(By.css('app-select-location'));
selectLocation.componentInstance.submit.emit([7, 9]);
// wait for model.updateUser to resolve
tick();
expect(spyNotificationsInfo.calls.count()).toEqual(1);
expect(spyNotificationsInfo.calls.first().args[0]).toEqual('Your location was saved.');
}));
it('should notify about success after a successful removal', fakeAsync(() => {
// emit the location-update event
const selectLocation = fixture.debugElement.query(By.css('app-select-location'));
selectLocation.componentInstance.submit.emit(null);
// wait for model.updateUser to resolve
tick();
expect(spyNotificationsInfo.calls.count()).toEqual(1);
expect(spyNotificationsInfo.calls.first().args[0]).toEqual('Your location was removed.');
}));
});