image.component.spec.ts
3.08 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
/**
* @ngdoc overview
* @name components.noosfero.profile-image.ProfileImageSpec
* @description
* This file contains the tests for the {@link components.noosfero.profile-image.ProfileImage} component.
*/
import { ComponentTestHelper, createClass } from '../../../spec/component-test-helper';
import { TestComponentBuilder, ComponentFixture } from 'ng-forward/cjs/testing/test-component-builder';
import { Pipe, Input, provide, Component } from 'ng-forward';
import { PersonService } from "../../../lib/ng-noosfero-api/http/person.service";
import * as helpers from "../../../spec/helpers";
import { ProfileImageComponent } from "./image.component";
const htmlTemplate: string = '<noosfero-profile-image [editable]="true" [edit-class]="editable-class" [profile]="ctrl.profile"></noosfero-profile-image>';
describe("Components", () => {
describe("Profile Image Component", () => {
let helper: ComponentTestHelper<ProfileImageComponent>;
beforeEach(angular.mock.module("templates"));
beforeEach((done) => {
let scope = helpers.mocks.scopeWithEvents;
let personService = jasmine.createSpyObj("personService", ["upload"]);
let properties = { profile: { custom_footer: "footer" } };
let cls = createClass({
template: htmlTemplate,
directives: [ProfileImageComponent],
properties: properties,
providers: [
helpers.createProviderToValue("PersonService", personService),
helpers.createProviderToValue("$uibModal", helpers.mocks.$modal),
helpers.createProviderToValue("$scope", scope)
]
});
helper = new ComponentTestHelper<ProfileImageComponent>(cls, done);
});
it("set modal instance when select files modal", () => {
helper.component['$uibModal'].open = jasmine.createSpy("open");
helper.component.fileSelected("file", []);
expect(helper.component['$uibModal'].open).toHaveBeenCalled();
});
it("show community users image if profile is not Person", (done) => {
let profile = <noosfero.Profile>{ id: 1, identifier: "myprofile", type: "Community" };
helper.component.profile = profile;
helper.component.ngOnInit();
// Check the attribute
expect(helper.component.defaultIcon).toBe("fa-users", "The default icon should be community users");
// var elProfile = fixture.debugElement.componentViewChildren[0];
// expect(elProfile.query('div.profile-image-block').length).toEqual(1);
done();
});
it("show Person image if profile is Person", (done) => {
let profile = <noosfero.Profile>{ id: 1, identifier: "myprofile", type: "Person" };
helper.component.profile = profile;
helper.component.ngOnInit();
// Check the attribute
expect(helper.component.defaultIcon).toEqual("fa-user", "The default icon should be person user");
done();
});
});
});