2015-12-19 16:31:34 +03:00
|
|
|
'use strict';
|
|
|
|
|
2016-06-12 20:44:34 +03:00
|
|
|
import { getChildDebugElement, getChildDebugElementAll } from '../../../../tests/helpers';
|
2016-06-15 21:48:04 +03:00
|
|
|
import { Component } from '@angular/core';
|
2015-12-19 16:31:34 +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';
|
|
|
|
|
2016-06-12 20:44:34 +03:00
|
|
|
import {Tabs, Tab} from '../index';
|
2015-12-19 16:31:34 +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('Tabs Component', () => {
|
|
|
|
let builder;
|
|
|
|
let component;
|
|
|
|
let childDebugEls;
|
2016-02-03 17:47:20 +03:00
|
|
|
let debugEl;
|
2015-12-19 20:36:28 +03:00
|
|
|
let fixture;
|
2016-02-03 17:47:20 +03:00
|
|
|
let hostComponent;
|
2015-12-19 16:31:34 +03:00
|
|
|
|
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
|
|
|
hostComponent = fixture.debugElement.componentInstance;
|
|
|
|
debugEl = getChildDebugElement(fixture.debugElement, 'tabs');
|
|
|
|
childDebugEls = getChildDebugElementAll(debugEl, 'tab');
|
|
|
|
component = debugEl.componentInstance;
|
2016-12-02 13:10:12 +03:00
|
|
|
});
|
2015-12-19 16:31:34 +03:00
|
|
|
|
2015-12-19 20:36:28 +03:00
|
|
|
it('should init component', () => {
|
|
|
|
expect(component).not.toBeNull();
|
|
|
|
});
|
2015-12-19 16:31:34 +03:00
|
|
|
|
2015-12-19 20:36:28 +03:00
|
|
|
it('should handle inner tabs', () => {
|
|
|
|
component.tabs.should.have.lengthOf(2);
|
|
|
|
childDebugEls.should.have.lengthOf(2);
|
|
|
|
});
|
2015-12-19 16:31:34 +03:00
|
|
|
|
2015-12-19 20:36:28 +03:00
|
|
|
it('should activate first tab by default', () => {
|
|
|
|
let tabs = childDebugEls.map(debugEl => debugEl.componentInstance);
|
|
|
|
let [tab1, tab2] = tabs;
|
2015-12-19 16:31:34 +03:00
|
|
|
|
2016-01-24 22:27:15 +03:00
|
|
|
tab1.active.should.be.true();
|
|
|
|
tab2.active.should.be.false();
|
2015-12-19 20:36:28 +03:00
|
|
|
});
|
2015-12-19 16:31:34 +03:00
|
|
|
|
2015-12-19 20:36:28 +03:00
|
|
|
it('should change active tab on click', () => {
|
|
|
|
fixture.detectChanges();
|
2016-02-03 17:47:20 +03:00
|
|
|
//let headerEls = nativeElement.querySelectorAll('li');
|
2015-12-19 20:36:28 +03:00
|
|
|
let tabs = childDebugEls.map(debugEl => debugEl.componentInstance);
|
|
|
|
let [tab1, tab2] = tabs;
|
2015-12-19 16:31:34 +03:00
|
|
|
|
2016-02-03 17:47:20 +03:00
|
|
|
let tabsInst = debugEl.componentInstance;
|
|
|
|
tabsInst.selectTab(tab2);
|
|
|
|
tab1.active.should.be.false();
|
|
|
|
tab2.active.should.be.true();
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should change tab by title and not emit Event', (done) => {
|
|
|
|
fixture.detectChanges();
|
|
|
|
let tabs = childDebugEls.map(debugEl => debugEl.componentInstance);
|
|
|
|
let [tab1, tab2] = tabs;
|
|
|
|
let tab2Title = 'Tab2';
|
|
|
|
|
|
|
|
let tabsInst = debugEl.componentInstance;
|
|
|
|
tabsInst.selectyByTitle(tab2Title);
|
|
|
|
tab1.active.should.be.false();
|
|
|
|
tab2.active.should.be.true();
|
|
|
|
|
|
|
|
setTimeout(() => {
|
|
|
|
hostComponent.eventLog.should.be.deepEqual([]);
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
it('should emit event on tab Change', (done) => {
|
|
|
|
fixture.detectChanges();
|
|
|
|
let tabs = childDebugEls.map(debugEl => debugEl.componentInstance);
|
|
|
|
let tab2 = tabs[1];
|
|
|
|
let tabsInst = debugEl.componentInstance;
|
|
|
|
tabsInst.selectTab(tab2, true);
|
|
|
|
|
|
|
|
setTimeout(() => {
|
|
|
|
hostComponent.eventLog.should.be.deepEqual(['Tab2']);
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should emit event on tab change by Title with notify true', (done) => {
|
|
|
|
fixture.detectChanges();
|
|
|
|
let tab2Title = 'Tab2';
|
|
|
|
|
|
|
|
let tabsInst = debugEl.componentInstance;
|
|
|
|
tabsInst.selectyByTitle(tab2Title, true);
|
|
|
|
|
|
|
|
setTimeout(() => {
|
|
|
|
hostComponent.eventLog.should.be.deepEqual(['Tab2']);
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should not emit event on tab change with notify false', (done) => {
|
|
|
|
fixture.detectChanges();
|
|
|
|
let tabs = childDebugEls.map(debugEl => debugEl.componentInstance);
|
|
|
|
let tab2 = tabs[1];
|
|
|
|
let tabsInst = debugEl.componentInstance;
|
|
|
|
tabsInst.selectTab(tab2, false);
|
|
|
|
|
|
|
|
setTimeout(() => {
|
|
|
|
hostComponent.eventLog.should.be.deepEqual([]);
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should leave current tab active if selectyByTitle non existing title', () => {
|
|
|
|
fixture.detectChanges();
|
|
|
|
let tabs = childDebugEls.map(debugEl => debugEl.componentInstance);
|
|
|
|
let [tab1, tab2] = tabs;
|
|
|
|
|
|
|
|
let tabsInst = debugEl.componentInstance;
|
|
|
|
tabsInst.selectyByTitle('badTitle');
|
|
|
|
tab1.active.should.be.true();
|
|
|
|
tab2.active.should.be.false();
|
2015-12-19 20:36:28 +03:00
|
|
|
});
|
2015-12-19 16:31:34 +03:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
/** Test component that contains an ApiInfo. */
|
2016-03-27 18:25:46 +03:00
|
|
|
@Component({
|
|
|
|
selector: 'test-app',
|
2015-12-19 16:31:34 +03:00
|
|
|
template:
|
2016-02-03 17:47:20 +03:00
|
|
|
`<tabs (change)="onEvent($event)">
|
2015-12-19 16:31:34 +03:00
|
|
|
<tab tabTitle="Tab1" tabStatus="test">Test</tab>
|
|
|
|
<tab tabTitle="Tab2" tabStatus="test">Test</tab>
|
|
|
|
</tabs>`
|
|
|
|
})
|
|
|
|
class TestApp {
|
2016-06-12 20:44:34 +03:00
|
|
|
eventLog: any;
|
2016-02-03 17:47:20 +03:00
|
|
|
constructor() {
|
|
|
|
this.eventLog = [];
|
|
|
|
}
|
|
|
|
onEvent(event) {
|
|
|
|
this.eventLog.push(event);
|
|
|
|
}
|
2015-12-19 16:31:34 +03:00
|
|
|
}
|