redoc/lib/shared/components/Zippy/zippy.spec.ts

112 lines
3.0 KiB
TypeScript
Raw Permalink Normal View History

2015-12-19 15:16:29 +03:00
'use strict';
2016-06-12 20:44:34 +03:00
import { getChildDebugElement, mouseclick } from '../../../../tests/helpers';
2015-12-19 15:16:29 +03:00
2016-05-06 00:48:41 +03:00
import { Component } from '@angular/core';
2015-12-19 15:16:29 +03:00
import {
inject,
2016-09-02 23:18:31 +03:00
TestBed
2016-05-09 22:55:16 +03:00
} from '@angular/core/testing';
2015-12-19 15:16:29 +03:00
2016-06-12 20:44:34 +03:00
import { Zippy } from '../index';
2015-12-19 15:16:29 +03:00
2015-12-19 20:36:28 +03:00
describe('Common components', () => {
2016-09-02 23:18:31 +03:00
beforeEach(() => {
TestBed.configureTestingModule({ declarations: [ TestApp ] });
});
2015-12-19 20:36:28 +03:00
describe('Zippy Component', () => {
let builder;
2017-01-28 16:57:22 +03:00
let component: Zippy;
2015-12-19 20:36:28 +03:00
let nativeElement;
let fixture;
2016-12-02 13:10:12 +03:00
beforeEach(() => {
2016-09-02 23:18:31 +03:00
fixture = TestBed.createComponent(TestApp);
2016-07-01 15:53:16 +03:00
let debugEl = getChildDebugElement(fixture.debugElement, 'zippy');
component = debugEl.componentInstance;
nativeElement = debugEl.nativeElement;
2016-12-02 13:10:12 +03:00
});
2015-12-19 20:36:28 +03:00
it('should init component', () => {
expect(component).not.toBeNull();
});
it('should init component defaults', () => {
2016-06-13 20:54:24 +03:00
component.empty.should.be.false();
2017-01-28 16:57:22 +03:00
component.open.should.be.false();
2015-12-19 20:36:28 +03:00
component.type.should.be.equal('general');
});
it('should init properties from dom params', () => {
fixture.detectChanges();
2017-01-28 16:57:22 +03:00
component.open.should.be.true();
2016-06-13 20:54:24 +03:00
component.empty.should.be.true();
2015-12-19 20:36:28 +03:00
component.title.should.be.equal('Zippy');
component.type.should.be.equal('test');
});
it('project inner content', () => {
fixture.detectChanges();
let contentEl = nativeElement.querySelector('.zippy-content');
2016-06-12 20:44:34 +03:00
expect(contentEl.innerText).toMatch('test');
2015-12-19 20:36:28 +03:00
});
2016-06-13 20:54:24 +03:00
it('should open and close zippy', (done) => {
2015-12-19 20:36:28 +03:00
fixture.detectChanges();
component.empty = false;
2017-01-28 16:57:22 +03:00
component.open = true;
2015-12-19 20:36:28 +03:00
fixture.detectChanges();
let testComponent = fixture.debugElement.componentInstance;
let titleEl = nativeElement.querySelector('.zippy-title');
mouseclick(titleEl);
fixture.detectChanges();
2017-01-28 16:57:22 +03:00
component.open.should.be.false();
2016-06-13 20:54:24 +03:00
testComponent.opened.should.be.false();
2015-12-19 20:36:28 +03:00
mouseclick(titleEl);
fixture.detectChanges();
2016-06-13 20:54:24 +03:00
setTimeout(() => {
2017-01-28 16:57:22 +03:00
component.open.should.be.true();
2016-06-13 20:54:24 +03:00
testComponent.opened.should.be.true();
testComponent.clickCount.should.be.equal(2);
done();
});
2015-12-19 20:36:28 +03:00
});
it('should disable empty zippy', () => {
fixture.detectChanges();
component.empty = true;
fixture.detectChanges();
let testComponent = fixture.debugElement.componentInstance;
let titleEl = nativeElement.querySelector('.zippy-title');
mouseclick(titleEl);
fixture.detectChanges();
testComponent.clickCount.should.be.equal(0);
});
2015-12-19 15:16:29 +03:00
});
});
/** Test component that contains an ApiInfo. */
@Component({
selector: 'test-app',
2015-12-19 15:16:29 +03:00
template:
2017-01-28 16:57:22 +03:00
`<zippy title="Zippy" type="test" [open]="true" [empty]="true" (openChange)="open($event)">test</zippy>`
2015-12-19 15:16:29 +03:00
})
class TestApp {
2016-06-12 20:44:34 +03:00
opened: boolean;
clickCount: number;
2015-12-19 15:16:29 +03:00
constructor() {
this.opened = false;
2017-01-28 16:57:22 +03:00
this.clickCount = -1; // initial change detection
2015-12-19 15:16:29 +03:00
}
2017-01-28 16:57:22 +03:00
open(val) {
this.opened = val;
2015-12-19 15:16:29 +03:00
this.clickCount++;
}
}