Commit 1333ce211c17f4e205005f4175bd4ccc82ebac4d

Authored by Victor Costa
2 parents 2655bbbc 22070a63

Merge branch 'ngforward' of softwarepublico.gov.br:noosfero-themes/angular-theme into ngforward

src/app/components/noosfero-boxes/boxes.component.spec.ts 0 → 100644
... ... @@ -0,0 +1,67 @@
  1 +import {Component} from 'ng-forward';
  2 +
  3 +import {Box, Profile} from "../../models/interfaces";
  4 +import {Boxes} from './boxes.component';
  5 +
  6 +import {
  7 + createComponentFromClass,
  8 + quickCreateComponent,
  9 + provideEmptyObjects,
  10 + createProviderToValue,
  11 + getAngularServiceFactory,
  12 + provideFilters
  13 +} from "../../../spec/helpers";
  14 +
  15 +// this htmlTemplate will be re-used between the container components in this spec file
  16 +const htmlTemplate: string = '<noosfero-boxes [boxes]="ctrl.boxes" [owner]="ctrl.profile"></noosfero-blog>';
  17 +
  18 +
  19 +describe("Boxes Component", () => {
  20 +
  21 + beforeEach(() => {
  22 + angular.mock.module("templates")
  23 + })
  24 +
  25 + @Component({
  26 + selector: 'test-container-component',
  27 + template: htmlTemplate,
  28 + directives: [Boxes],
  29 + providers: []
  30 + })
  31 + class BoxesContainerComponent {
  32 + boxes: Box[] = [
  33 + { id: 1, position: 1 },
  34 + { id: 2, position: 2 }
  35 + ];
  36 +
  37 + owner: Profile = {
  38 + id: 1,
  39 + identifier: 'profile-name',
  40 + type: 'Person'
  41 + };
  42 + }
  43 +
  44 + it("renders boxes into a container", (done: Function) => {
  45 + createComponentFromClass(BoxesContainerComponent).then((fixture) => {
  46 +
  47 + var boxesHtml = fixture.debugElement;
  48 + expect(boxesHtml.query('div.col-md-7').length).toEqual(1);
  49 + expect(boxesHtml.query('div.col-md-2-5').length).toEqual(1);
  50 +
  51 + done();
  52 + });
  53 + });
  54 +
  55 + it("check the boxes order", (done: Function) => {
  56 + createComponentFromClass(BoxesContainerComponent).then((fixture) => {
  57 +
  58 + let boxesComponent: Boxes = fixture.debugElement.componentViewChildren[0].componentInstance;
  59 + let boxesContainer: BoxesContainerComponent = fixture.componentInstance;
  60 +
  61 + expect(boxesComponent.boxesOrder(boxesContainer.boxes[0])).toEqual(1);
  62 + expect(boxesComponent.boxesOrder(boxesContainer.boxes[1])).toEqual(0);
  63 +
  64 + done();
  65 + });
  66 + });
  67 +});
... ...
src/app/components/noosfero-boxes/boxes.component.ts
1   -import { Input, Inject, Component } from 'ng-forward';
2   -import {Box} from "./../../models/interfaces";
  1 +import {Input, Inject, Component} from 'ng-forward';
  2 +import {Box, Profile} from "./../../models/interfaces";
  3 +
3 4 @Component({
4 5 selector: "noosfero-boxes",
5 6 templateUrl: "app/components/noosfero-boxes/boxes.html"
6 7 })
7 8 export class Boxes {
8 9  
9   - @Input() boxes: any;
10   - @Input() owner: any;
  10 + @Input() boxes: Box[];
  11 + @Input() owner: Profile;
11 12  
12 13 boxesOrder(box: Box) {
13 14 if (box.position === 2) return 0;
... ...