profile-view.component.spec.ts 1.76 KB
import {ComponentFixture} from 'ng-forward/cjs/testing/test-component-builder';
import {Profile} from "./../../models/interfaces";
import * as helpers from "../../../spec/helpers";
import {Component} from 'ng-forward'

import {ProfileView} from './profile-view.component';

import {INgForwardJQuery} from '../../../../node_modules/ng-forward/cjs/util/jqlite-extensions.d';

let htmlTemplate = '<profile-view [profile]="ctrl.profile"></profile-view>'
describe('Profile View Component', () => {
    beforeEach(angular.mock.module('templates'))
    @Component({
        selector: 'test-profile-view-container',
        directives: [ProfileView],
        providers: helpers.provideFilters('translateFilter'),
        template: htmlTemplate
    })
    class ProfileViewContainer {
        profile: any = {
            id: 1,
            identifier: 'scarlet',
            type: 'Profile',
            name: 'Scarlet',
            created_at: '2016-03-11'
        }
    }

    it('render main content profile view', (done: Function) => {
        helpers.createComponentFromClass(ProfileViewContainer).then((fixture) => {
            expect(fixture.debugElement.query('div.profile-view').length).toEqual(1);

            done();
        })
            .catch((e) => {
                fail(e.message);
                done();
            });

    });

    it('render profile data', (done: Function) => {
        helpers.createComponentFromClass(ProfileViewContainer).then((fixture) => {
            let nameTag: INgForwardJQuery = fixture.debugElement.query('header > h2');
            let container: ProfileViewContainer = fixture.componentInstance;


            expect(nameTag.length).toEqual(1);
            expect(nameTag.text()).toEqual(container.profile.name);

            done();
        })
    });
});