mirror of
https://github.com/Redocly/redoc.git
synced 2024-11-22 16:46:34 +03:00
Add a few tests + remove unused code
This commit is contained in:
parent
12c3e31f64
commit
899c2b8398
58
lib/components/LoadingBar/loading-bar.spec.ts
Normal file
58
lib/components/LoadingBar/loading-bar.spec.ts
Normal file
|
@ -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:
|
||||
`<loading-bar [progress]="progress"></loading-bar>`
|
||||
})
|
||||
class TestAppComponent {
|
||||
progress = 0;
|
||||
}
|
|
@ -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<TestAppComponent>;
|
||||
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);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
|
56
lib/services/clipboard.service.spec.ts
Normal file
56
lib/services/clipboard.service.spec.ts
Normal file
|
@ -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);
|
||||
(<jasmine.Spy>Clipboard.copySelected).and.callThrough();
|
||||
});
|
||||
|
||||
it('selectElement should select element text', () => {
|
||||
el = createEl('<div>Test</div>');
|
||||
Clipboard.selectElement(el);
|
||||
let selected = window.getSelection().toString();
|
||||
selected.should.be.equal('Test');
|
||||
});
|
||||
|
||||
it('deselect should clear selection', () => {
|
||||
el = createEl('<div>Test</div>');
|
||||
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('<div>Test</div>');
|
||||
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');
|
||||
});
|
||||
});
|
|
@ -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();
|
||||
|
|
|
@ -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<string, string> {
|
||||
var res = new Map<string, string>();
|
||||
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; }
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user