environment.component.spec.ts
2.45 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
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;
let defaultEnvironment = <any> {id: 1, name: 'Noosfero' };
beforeEach(inject((_$rootScope_: ng.IRootScopeService, _$q_: ng.IQService) => {
$rootScope = _$rootScope_;
$q = _$q_;
}));
beforeEach(() => {
$state = jasmine.createSpyObj("$state", ["transitionTo"]);
environmentServiceMock = jasmine.createSpyObj("environmentServiceMock", ["get", "getBoxes"]);
notificationMock = jasmine.createSpyObj("notificationMock", ["error"]);
let getBoxesResponse = $q.defer();
getBoxesResponse.resolve({ data: { boxes: [{ id: 2 }] } });
environmentServiceMock.getBoxes = jasmine.createSpy("getBoxes").and.returnValue(getBoxesResponse.promise);
});
it("get the default environment", done => {
let component: EnvironmentComponent = new EnvironmentComponent(environmentServiceMock, $state, notificationMock, defaultEnvironment);
$rootScope.$apply();
expect(component.environment).toEqual({ id: 1, name: 'Noosfero' });
done();
});
it("get the environment boxes", done => {
let component: EnvironmentComponent = new EnvironmentComponent(environmentServiceMock, $state, notificationMock, defaultEnvironment);
$rootScope.$apply();
expect(environmentServiceMock.getBoxes).toHaveBeenCalled();
expect(component.boxes).toEqual({ data: { boxes: [{ id: 2 }] } });
done();
});
it("display notification error when does not find boxes to the environment", done => {
let environmentResponse = $q.defer();
environmentResponse.reject();
environmentServiceMock.getBoxes = jasmine.createSpy('getBoxes').and.returnValue(environmentResponse.promise);
let component: EnvironmentComponent = new EnvironmentComponent(environmentServiceMock, $state, notificationMock, defaultEnvironment);
$rootScope.$apply();
expect(notificationMock.error).toHaveBeenCalled();
done();
});
});
});