2015-12-21 22:39:40 +03:00
|
|
|
'use strict';
|
|
|
|
|
2016-06-12 20:44:34 +03:00
|
|
|
import { getChildDebugElement } from '../../../tests/helpers';
|
2016-07-01 16:30:45 +03:00
|
|
|
import { Component } from '@angular/core';
|
2017-01-07 19:05:08 +03:00
|
|
|
import { OptionsService, MenuItem } from '../../services/index';
|
2015-12-21 22:39:40 +03:00
|
|
|
|
|
|
|
import {
|
2016-04-30 00:45:53 +03:00
|
|
|
inject,
|
2016-07-01 15:53:16 +03:00
|
|
|
async
|
2016-05-06 00:48:41 +03:00
|
|
|
} from '@angular/core/testing';
|
|
|
|
|
2017-01-07 19:05:08 +03:00
|
|
|
import { TestBed, ComponentFixture } from '@angular/core/testing';
|
2015-12-21 22:39:40 +03:00
|
|
|
|
2016-06-12 20:44:34 +03:00
|
|
|
import { MethodsList, SideMenu } from '../index';
|
2016-05-09 22:55:16 +03:00
|
|
|
|
2016-10-23 20:18:42 +03:00
|
|
|
import { SpecManager } from '../../utils/spec-manager';
|
2015-12-21 22:39:40 +03:00
|
|
|
|
2016-06-12 20:44:34 +03:00
|
|
|
let testOptions;
|
2016-05-09 22:55:16 +03:00
|
|
|
|
2015-12-21 22:39:40 +03:00
|
|
|
describe('Redoc components', () => {
|
2016-09-02 23:18:31 +03:00
|
|
|
beforeEach(() => {
|
2016-11-24 16:29:29 +03:00
|
|
|
TestBed.configureTestingModule({ declarations: [ TestAppComponent, MethodsList ] });
|
2016-09-02 23:18:31 +03:00
|
|
|
});
|
2015-12-21 22:39:40 +03:00
|
|
|
describe('SideMenu Component', () => {
|
|
|
|
let builder;
|
2017-01-07 19:05:08 +03:00
|
|
|
let component: SideMenu;
|
|
|
|
let fixture: ComponentFixture<TestAppComponent>;
|
2016-11-24 16:29:29 +03:00
|
|
|
let specMgr;
|
2016-07-01 15:53:16 +03:00
|
|
|
|
2016-11-24 16:29:29 +03:00
|
|
|
beforeEach(inject([SpecManager, OptionsService],
|
|
|
|
(_specMgr, opts) => {
|
2016-09-02 23:18:31 +03:00
|
|
|
|
2016-06-12 20:44:34 +03:00
|
|
|
testOptions = opts;
|
|
|
|
testOptions.options = {
|
|
|
|
scrollYOffset: () => 0,
|
2016-07-21 13:35:27 +03:00
|
|
|
$scrollParent: window
|
2016-06-12 20:44:34 +03:00
|
|
|
};
|
2016-11-24 16:29:29 +03:00
|
|
|
specMgr = _specMgr;
|
|
|
|
}));
|
|
|
|
|
|
|
|
beforeEach(done => {
|
|
|
|
specMgr.load('/tests/schemas/extended-petstore.yml').then(done, done.fail);
|
|
|
|
});
|
2015-12-21 22:39:40 +03:00
|
|
|
|
2016-07-01 15:53:16 +03:00
|
|
|
beforeEach(() => {
|
2016-09-02 23:18:31 +03:00
|
|
|
fixture = TestBed.createComponent(TestAppComponent);
|
2016-07-01 15:53:16 +03:00
|
|
|
component = getChildDebugElement(fixture.debugElement, 'side-menu').componentInstance;
|
|
|
|
fixture.detectChanges();
|
2015-12-21 22:39:40 +03:00
|
|
|
});
|
|
|
|
|
2016-05-09 22:55:16 +03:00
|
|
|
afterEach(() => {
|
|
|
|
if (fixture) fixture.destroy();
|
|
|
|
});
|
2015-12-22 18:02:03 +03:00
|
|
|
|
2016-11-24 19:21:49 +03:00
|
|
|
it('should init component and component data', () => {
|
2017-01-07 19:05:08 +03:00
|
|
|
should.exist(component);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should clear active item and cat captions on change to null', () => {
|
|
|
|
component.activeCatCaption = 'test';
|
|
|
|
component.activeItemCaption = 'test';
|
|
|
|
component.changed(null);
|
|
|
|
component.activeCatCaption.should.be.equal('');
|
|
|
|
component.activeItemCaption.should.be.equal('');
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should set active item and cat captions on change event', () => {
|
|
|
|
let parentItem: MenuItem = {
|
|
|
|
id: 'id',
|
|
|
|
name: 'Item'
|
|
|
|
};
|
|
|
|
component.changed(parentItem);
|
|
|
|
component.activeCatCaption.should.be.equal(parentItem.name);
|
|
|
|
component.activeItemCaption.should.be.equal('');
|
|
|
|
|
|
|
|
let childItem: MenuItem = {
|
|
|
|
id: 'id2',
|
|
|
|
name: 'Child',
|
|
|
|
parent: parentItem
|
|
|
|
};
|
|
|
|
component.changed(childItem);
|
|
|
|
component.activeCatCaption.should.be.equal(parentItem.name);
|
|
|
|
component.activeItemCaption.should.be.equal(childItem.name);
|
2015-12-21 22:39:40 +03:00
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
/** Test component that contains an ApiInfo. */
|
2016-03-27 18:25:46 +03:00
|
|
|
@Component({
|
|
|
|
selector: 'test-app',
|
2015-12-21 22:39:40 +03:00
|
|
|
template:
|
|
|
|
`<side-menu></side-menu>
|
|
|
|
<methods-list></methods-list>`
|
|
|
|
})
|
2016-06-13 20:54:24 +03:00
|
|
|
class TestAppComponent {
|
2015-12-21 22:39:40 +03:00
|
|
|
}
|