diff --git a/lib/components/LoadingBar/loading-bar.spec.ts b/lib/components/LoadingBar/loading-bar.spec.ts
new file mode 100644
index 00000000..2c883462
--- /dev/null
+++ b/lib/components/LoadingBar/loading-bar.spec.ts
@@ -0,0 +1,58 @@
+'use strict';
+
+import {
+ Component
+} from '@angular/core';
+
+import {
+ ComponentFixture,
+ inject,
+ fakeAsync,
+ tick,
+ TestBed,
+} from '@angular/core/testing';
+
+import { getChildDebugElement } from '../../../tests/helpers';
+import { LoadingBar } from './loading-bar';
+
+describe('Redoc components', () => {
+ describe('Loading Bar', () => {
+ let component: LoadingBar;
+
+ it('should init component', () => {
+ let fixture = TestBed.createComponent(LoadingBar);
+ component = fixture.componentInstance;
+ fixture.detectChanges();
+ should.exist(component);
+ component.progress.should.be.equal(0);
+ component.display.should.be.equal('block');
+ });
+
+ it('should hide itself in 500ms if progress is 100', fakeAsync(() => {
+ TestBed.configureTestingModule({ declarations: [ TestAppComponent ] });
+ let fixture = TestBed.createComponent(TestAppComponent);
+ let parentComp = fixture.componentInstance;
+ component = getChildDebugElement(fixture.debugElement, 'loading-bar').componentInstance;
+ // need to pass update through parent component as ngOnChanges is run only for view changes
+ parentComp.progress = 50;
+ fixture.detectChanges();
+ parentComp.progress = 100;
+ fixture.detectChanges();
+
+ component.display.should.be.equal('block');
+ tick(500);
+ component.display.should.be.equal('none');
+ }));
+ });
+});
+
+
+/** Test component that contains an ApiInfo. */
+@Component({
+ selector: 'test-app',
+ template:
+ ``
+})
+class TestAppComponent {
+ progress = 0;
+}
diff --git a/lib/components/SideMenu/side-menu.spec.ts b/lib/components/SideMenu/side-menu.spec.ts
index 8f1bb3b5..8a253905 100644
--- a/lib/components/SideMenu/side-menu.spec.ts
+++ b/lib/components/SideMenu/side-menu.spec.ts
@@ -2,14 +2,14 @@
import { getChildDebugElement } from '../../../tests/helpers';
import { Component } from '@angular/core';
-import { OptionsService } from '../../services/index';
+import { OptionsService, MenuItem } from '../../services/index';
import {
inject,
async
} from '@angular/core/testing';
-import { TestBed } from '@angular/core/testing';
+import { TestBed, ComponentFixture } from '@angular/core/testing';
import { MethodsList, SideMenu } from '../index';
@@ -23,8 +23,8 @@ describe('Redoc components', () => {
});
describe('SideMenu Component', () => {
let builder;
- let component;
- let fixture;
+ let component: SideMenu;
+ let fixture: ComponentFixture;
let specMgr;
beforeEach(inject([SpecManager, OptionsService],
@@ -53,8 +53,34 @@ describe('Redoc components', () => {
});
it('should init component and component data', () => {
- expect(component).not.toBeNull();
- expect(component.data).not.toBeNull();
+ 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);
});
});
});
diff --git a/lib/services/clipboard.service.spec.ts b/lib/services/clipboard.service.spec.ts
new file mode 100644
index 00000000..acde50b2
--- /dev/null
+++ b/lib/services/clipboard.service.spec.ts
@@ -0,0 +1,56 @@
+'use strict';
+
+import { Clipboard } from './clipboard.service';
+
+describe('Clipboard Service', () => {
+ let el:Node;
+ let copiedText = null;
+
+ function createEl(html) {
+ let tmpDiv = document.createElement('div');
+ tmpDiv.innerHTML = html;
+ document.body.appendChild(tmpDiv);
+ return tmpDiv.lastChild;
+ }
+
+ beforeEach(() => {
+ spyOn(Clipboard, 'copySelected').and.callFake(() => {
+ copiedText = window.getSelection().toString();
+ return true;
+ });
+ });
+
+ afterEach(() => {
+ copiedText = null;
+ if (el && el.parentNode) el.parentNode.removeChild(el);
+ (Clipboard.copySelected).and.callThrough();
+ });
+
+ it('selectElement should select element text', () => {
+ el = createEl('Test
');
+ Clipboard.selectElement(el);
+ let selected = window.getSelection().toString();
+ selected.should.be.equal('Test');
+ });
+
+ it('deselect should clear selection', () => {
+ el = createEl('Test
');
+ Clipboard.selectElement(el);
+ let selected = window.getSelection().toString();
+ selected.should.be.equal('Test');
+ Clipboard.deselect();
+ window.getSelection().toString().should.be.equal('');
+ });
+
+ it('copyElement should copy and deselect', () => {
+ el = createEl('Test
');
+ Clipboard.copyElement(el);
+ copiedText.should.be.equal('Test');
+ window.getSelection().toString().should.be.equal('');
+ });
+
+ it('copyCustom should copy custom text', () => {
+ Clipboard.copyCustom('Custom text');
+ copiedText.should.be.equal('Custom text');
+ });
+});
diff --git a/lib/shared/components/StickySidebar/sticky-sidebar.spec.ts b/lib/shared/components/StickySidebar/sticky-sidebar.spec.ts
index af27fe99..80ba01cd 100644
--- a/lib/shared/components/StickySidebar/sticky-sidebar.spec.ts
+++ b/lib/shared/components/StickySidebar/sticky-sidebar.spec.ts
@@ -38,11 +38,11 @@ describe('Common components', () => {
expect(component.stickBottom).not.toHaveBeenCalled();
});
- it('should stick to the top on the next VM tick', (done) => {
+ it('should stick to the top on the next animation frame', (done) => {
spyOn(component, 'stick').and.callThrough();
spyOn(component, 'stickBottom').and.callThrough();
fixture.detectChanges();
- setTimeout(() => {
+ requestAnimationFrame(() => {
expect(component.stick).toHaveBeenCalled();
expect(component.stickBottom).toHaveBeenCalled();
done();
diff --git a/lib/utils/browser-adapter.ts b/lib/utils/browser-adapter.ts
index 5184f6a3..6cf835fa 100644
--- a/lib/utils/browser-adapter.ts
+++ b/lib/utils/browser-adapter.ts
@@ -14,16 +14,6 @@ export class BrowserDomAdapter {
return () => { el.removeEventListener(evt, listener, false); };
}
- static addClass(element: any /** TODO #9100 */, className: string) { element.classList.add(className); }
-
- static removeClass(element: any /** TODO #9100 */, className: string) {
- element.classList.remove(className);
- }
-
- static hasClass(element: any /** TODO #9100 */, className: string): boolean {
- return element.classList.contains(className);
- }
-
static attributeMap(element: any /** TODO #9100 */): Map {
var res = new Map();
var elAttrs = element.attributes;
@@ -59,15 +49,5 @@ export class BrowserDomAdapter {
return element.getAttribute(attribute);
}
- static setAttribute(element: any /** TODO #9100 */, name: string, value: string) {
- element.setAttribute(name, value);
- }
-
- static removeAttribute(element: any /** TODO #9100 */, attribute: string) {
- element.removeAttribute(attribute);
- }
-
- static getLocation(): Location { return window.location; }
-
static defaultDoc(): HTMLDocument { return document; }
}