environment.component.spec.ts
2.61 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
import {quickCreateComponent} from "../../spec/helpers";
import {EnvironmentComponent} from "./environment.component";
describe("Components", () => {
describe("Environment Component", () => {
let $rootScope: ng.IRootScopeService;
let $q: ng.IQService;
let environmentServiceMock: any;
let notificationMock: any;
let $state: any;
beforeEach(inject((_$rootScope_: ng.IRootScopeService, _$q_: ng.IQService) => {
$rootScope = _$rootScope_;
$q = _$q_;
}));
beforeEach(() => {
$state = jasmine.createSpyObj("$state", ["transitionTo"]);
environmentServiceMock = jasmine.createSpyObj("environmentServiceMock", ["getByIdentifier", "getBoxes"]);
notificationMock = jasmine.createSpyObj("notificationMock", ["error"]);
let environmentResponse = $q.defer();
environmentResponse.resolve({ id: 1 });
let getBoxesResponse = $q.defer();
getBoxesResponse.resolve({ data: { boxes: [{ id: 2 }] } });
environmentServiceMock.getByIdentifier = jasmine.createSpy('getByIdentifier').and.returnValue(environmentResponse.promise);
environmentServiceMock.getBoxes = jasmine.createSpy("getBoxes").and.returnValue(getBoxesResponse.promise);
});
it("get the default environment", done => {
let component: EnvironmentComponent = new EnvironmentComponent(environmentServiceMock, $state, notificationMock);
$rootScope.$apply();
expect(component.environment).toEqual({ id: 1 });
done();
});
it("get the environment boxes", done => {
let component: EnvironmentComponent = new EnvironmentComponent(environmentServiceMock, $state, notificationMock);
$rootScope.$apply();
expect(environmentServiceMock.getBoxes).toHaveBeenCalled();
expect(component.boxes).toEqual({ data: { boxes: [{ id: 2 }] } });
done();
});
it("display notification error when the environment wasn't found", done => {
let environmentResponse = $q.defer();
environmentResponse.reject();
environmentServiceMock.getByIdentifier = jasmine.createSpy('getByIdentifier').and.returnValue(environmentResponse.promise);
let component: EnvironmentComponent = new EnvironmentComponent(environmentServiceMock, $state, notificationMock);
$rootScope.$apply();
expect(notificationMock.error).toHaveBeenCalled();
expect(component.environment).toBeUndefined();
done();
});
});
});