mirror of
https://github.com/Alfresco/alfresco-ng2-components.git
synced 2025-10-08 14:51:32 +00:00
[AAE-1695] reduce manual tests (#5455)
* tests cleanup * cleanup search control tests * EmptyContentComponent tests * fix names * search filter category test * task list test and code polish * process list tests and cleanup * extra task-list tests * extra start-task tests * code cleanup
This commit is contained in:
@@ -42,10 +42,6 @@ describe('SidebarActionMenuComponent', () => {
|
||||
fixture.destroy();
|
||||
});
|
||||
|
||||
it('should create instance of SidebarActionMenuComponent', () => {
|
||||
expect(fixture.componentInstance instanceof SidebarActionMenuComponent).toBe(true, 'should create SidebarActionMenuComponent');
|
||||
});
|
||||
|
||||
it('should display title', () => {
|
||||
component.title = 'Fake-Title';
|
||||
component.expanded = true;
|
||||
@@ -104,10 +100,6 @@ describe('Custom SidebarActionMenuComponent', () => {
|
||||
element = fixture.nativeElement;
|
||||
});
|
||||
|
||||
it('should create instance of CustomSidebarActionMenuComponent', () => {
|
||||
expect(component instanceof CustomSidebarActionMenuComponent).toBe(true, 'should create CustomSidebarActionMenuComponent');
|
||||
});
|
||||
|
||||
it('should defined adf-sidebar-action-menu', () => {
|
||||
fixture.detectChanges();
|
||||
element = fixture.nativeElement.querySelector('adf-sidebar-action-menu');
|
||||
|
@@ -25,168 +25,155 @@ import { LogService } from './log.service';
|
||||
import { setupTestBed } from '../testing/setupTestBed';
|
||||
|
||||
@Component({
|
||||
template: '',
|
||||
providers: [LogService]
|
||||
template: '',
|
||||
providers: [LogService]
|
||||
})
|
||||
class ProvidesLogComponent {
|
||||
constructor(public logService: LogService) {
|
||||
constructor(public logService: LogService) {}
|
||||
|
||||
}
|
||||
error() {
|
||||
this.logService.error('Test message');
|
||||
}
|
||||
|
||||
error() {
|
||||
this.logService.error('Test message');
|
||||
}
|
||||
info() {
|
||||
this.logService.info('Test message');
|
||||
}
|
||||
|
||||
info() {
|
||||
this.logService.info('Test message');
|
||||
}
|
||||
warn() {
|
||||
this.logService.warn('Test message');
|
||||
}
|
||||
|
||||
warn() {
|
||||
this.logService.warn('Test message');
|
||||
}
|
||||
log() {
|
||||
this.logService.log('Test message');
|
||||
}
|
||||
|
||||
log() {
|
||||
this.logService.log('Test message');
|
||||
}
|
||||
|
||||
debug() {
|
||||
this.logService.debug('Test message');
|
||||
}
|
||||
|
||||
trace() {
|
||||
this.logService.trace('Test message');
|
||||
}
|
||||
debug() {
|
||||
this.logService.debug('Test message');
|
||||
}
|
||||
|
||||
trace() {
|
||||
this.logService.trace('Test message');
|
||||
}
|
||||
}
|
||||
|
||||
describe('Log Service', () => {
|
||||
describe('LogService', () => {
|
||||
let providesLogComponent: ComponentFixture<ProvidesLogComponent>;
|
||||
let appConfigService: AppConfigService;
|
||||
|
||||
let providesLogComponent: ComponentFixture<ProvidesLogComponent>;
|
||||
let appConfigService: AppConfigService;
|
||||
setupTestBed({
|
||||
imports: [HttpClientModule],
|
||||
declarations: [ProvidesLogComponent],
|
||||
providers: [LogService, AppConfigService]
|
||||
});
|
||||
|
||||
setupTestBed({
|
||||
imports: [
|
||||
HttpClientModule
|
||||
],
|
||||
declarations: [ProvidesLogComponent],
|
||||
providers: [
|
||||
LogService,
|
||||
AppConfigService
|
||||
]
|
||||
});
|
||||
beforeEach(() => {
|
||||
appConfigService = TestBed.get(AppConfigService);
|
||||
providesLogComponent = TestBed.createComponent(ProvidesLogComponent);
|
||||
});
|
||||
|
||||
beforeEach(() => {
|
||||
appConfigService = TestBed.get(AppConfigService);
|
||||
});
|
||||
it('should not log anything if is silent', () => {
|
||||
appConfigService.config['logLevel'] = 'silent';
|
||||
|
||||
it('should not log anything if is silent', () => {
|
||||
appConfigService.config['logLevel'] = 'silent';
|
||||
providesLogComponent = TestBed.createComponent(ProvidesLogComponent);
|
||||
spyOn(console, 'log');
|
||||
spyOn(console, 'trace');
|
||||
spyOn(console, 'debug');
|
||||
spyOn(console, 'info');
|
||||
spyOn(console, 'warn');
|
||||
spyOn(console, 'error');
|
||||
|
||||
spyOn(console, 'log');
|
||||
spyOn(console, 'trace');
|
||||
spyOn(console, 'debug');
|
||||
spyOn(console, 'info');
|
||||
spyOn(console, 'warn');
|
||||
spyOn(console, 'error');
|
||||
providesLogComponent.componentInstance.log();
|
||||
providesLogComponent.componentInstance.trace();
|
||||
providesLogComponent.componentInstance.debug();
|
||||
providesLogComponent.componentInstance.info();
|
||||
providesLogComponent.componentInstance.warn();
|
||||
providesLogComponent.componentInstance.error();
|
||||
|
||||
providesLogComponent.componentInstance.log();
|
||||
providesLogComponent.componentInstance.trace();
|
||||
providesLogComponent.componentInstance.debug();
|
||||
providesLogComponent.componentInstance.info();
|
||||
providesLogComponent.componentInstance.warn();
|
||||
providesLogComponent.componentInstance.error();
|
||||
expect(console.log).not.toHaveBeenCalled();
|
||||
expect(console.trace).not.toHaveBeenCalled();
|
||||
expect(console.debug).not.toHaveBeenCalled();
|
||||
expect(console.info).not.toHaveBeenCalled();
|
||||
expect(console.warn).not.toHaveBeenCalled();
|
||||
expect(console.error).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
expect(console.log).not.toHaveBeenCalled();
|
||||
expect(console.trace).not.toHaveBeenCalled();
|
||||
expect(console.debug).not.toHaveBeenCalled();
|
||||
expect(console.info).not.toHaveBeenCalled();
|
||||
expect(console.warn).not.toHaveBeenCalled();
|
||||
expect(console.error).not.toHaveBeenCalled();
|
||||
});
|
||||
it('should log only warning and errors if is warning level', () => {
|
||||
appConfigService.config['logLevel'] = 'WARN';
|
||||
|
||||
it('should log only warning and errors if is warning level', () => {
|
||||
appConfigService.config['logLevel'] = 'WARN';
|
||||
providesLogComponent = TestBed.createComponent(ProvidesLogComponent);
|
||||
spyOn(console, 'log');
|
||||
spyOn(console, 'error');
|
||||
spyOn(console, 'trace');
|
||||
spyOn(console, 'warn');
|
||||
|
||||
spyOn(console, 'log');
|
||||
spyOn(console, 'error');
|
||||
spyOn(console, 'trace');
|
||||
spyOn(console, 'warn');
|
||||
providesLogComponent.componentInstance.log();
|
||||
providesLogComponent.componentInstance.error();
|
||||
providesLogComponent.componentInstance.trace();
|
||||
providesLogComponent.componentInstance.warn();
|
||||
|
||||
providesLogComponent.componentInstance.log();
|
||||
providesLogComponent.componentInstance.error();
|
||||
providesLogComponent.componentInstance.trace();
|
||||
providesLogComponent.componentInstance.warn();
|
||||
expect(console.log).not.toHaveBeenCalled();
|
||||
expect(console.error).toHaveBeenCalled();
|
||||
expect(console.warn).toHaveBeenCalled();
|
||||
expect(console.trace).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
expect(console.log).not.toHaveBeenCalled();
|
||||
expect(console.error).toHaveBeenCalled();
|
||||
expect(console.warn).toHaveBeenCalled();
|
||||
expect(console.trace).not.toHaveBeenCalled();
|
||||
});
|
||||
it('should debug level not log trace and log', () => {
|
||||
appConfigService.config['logLevel'] = 'debug';
|
||||
|
||||
it('should debug level not log trace and log', () => {
|
||||
appConfigService.config['logLevel'] = 'debug';
|
||||
providesLogComponent = TestBed.createComponent(ProvidesLogComponent);
|
||||
spyOn(console, 'log');
|
||||
spyOn(console, 'trace');
|
||||
spyOn(console, 'debug');
|
||||
spyOn(console, 'info');
|
||||
spyOn(console, 'warn');
|
||||
spyOn(console, 'error');
|
||||
|
||||
spyOn(console, 'log');
|
||||
spyOn(console, 'trace');
|
||||
spyOn(console, 'debug');
|
||||
spyOn(console, 'info');
|
||||
spyOn(console, 'warn');
|
||||
spyOn(console, 'error');
|
||||
providesLogComponent.componentInstance.log();
|
||||
providesLogComponent.componentInstance.trace();
|
||||
providesLogComponent.componentInstance.debug();
|
||||
providesLogComponent.componentInstance.info();
|
||||
providesLogComponent.componentInstance.warn();
|
||||
providesLogComponent.componentInstance.error();
|
||||
|
||||
providesLogComponent.componentInstance.log();
|
||||
providesLogComponent.componentInstance.trace();
|
||||
providesLogComponent.componentInstance.debug();
|
||||
providesLogComponent.componentInstance.info();
|
||||
providesLogComponent.componentInstance.warn();
|
||||
providesLogComponent.componentInstance.error();
|
||||
expect(console.log).not.toHaveBeenCalled();
|
||||
expect(console.trace).not.toHaveBeenCalled();
|
||||
expect(console.debug).toHaveBeenCalled();
|
||||
expect(console.info).toHaveBeenCalled();
|
||||
expect(console.warn).toHaveBeenCalled();
|
||||
expect(console.error).toHaveBeenCalled();
|
||||
});
|
||||
|
||||
expect(console.log).not.toHaveBeenCalled();
|
||||
expect(console.trace).not.toHaveBeenCalled();
|
||||
expect(console.debug).toHaveBeenCalled();
|
||||
expect(console.info).toHaveBeenCalled();
|
||||
expect(console.warn).toHaveBeenCalled();
|
||||
expect(console.error).toHaveBeenCalled();
|
||||
});
|
||||
it('should trace level log all', () => {
|
||||
appConfigService.config['logLevel'] = 'trace';
|
||||
|
||||
it('should trace level log all', () => {
|
||||
appConfigService.config['logLevel'] = 'trace';
|
||||
providesLogComponent = TestBed.createComponent(ProvidesLogComponent);
|
||||
spyOn(console, 'log');
|
||||
spyOn(console, 'trace');
|
||||
spyOn(console, 'debug');
|
||||
spyOn(console, 'info');
|
||||
spyOn(console, 'warn');
|
||||
spyOn(console, 'error');
|
||||
|
||||
spyOn(console, 'log');
|
||||
spyOn(console, 'trace');
|
||||
spyOn(console, 'debug');
|
||||
spyOn(console, 'info');
|
||||
spyOn(console, 'warn');
|
||||
spyOn(console, 'error');
|
||||
providesLogComponent.componentInstance.log();
|
||||
providesLogComponent.componentInstance.trace();
|
||||
providesLogComponent.componentInstance.debug();
|
||||
providesLogComponent.componentInstance.info();
|
||||
providesLogComponent.componentInstance.warn();
|
||||
providesLogComponent.componentInstance.error();
|
||||
|
||||
providesLogComponent.componentInstance.log();
|
||||
providesLogComponent.componentInstance.trace();
|
||||
providesLogComponent.componentInstance.debug();
|
||||
providesLogComponent.componentInstance.info();
|
||||
providesLogComponent.componentInstance.warn();
|
||||
providesLogComponent.componentInstance.error();
|
||||
expect(console.log).toHaveBeenCalled();
|
||||
expect(console.trace).toHaveBeenCalled();
|
||||
expect(console.debug).toHaveBeenCalled();
|
||||
expect(console.info).toHaveBeenCalled();
|
||||
expect(console.warn).toHaveBeenCalled();
|
||||
expect(console.error).toHaveBeenCalled();
|
||||
});
|
||||
|
||||
expect(console.log).toHaveBeenCalled();
|
||||
expect(console.trace).toHaveBeenCalled();
|
||||
expect(console.debug).toHaveBeenCalled();
|
||||
expect(console.info).toHaveBeenCalled();
|
||||
expect(console.warn).toHaveBeenCalled();
|
||||
expect(console.error).toHaveBeenCalled();
|
||||
});
|
||||
it('message Observable', done => {
|
||||
appConfigService.config['logLevel'] = 'trace';
|
||||
|
||||
it('message Observable', (done) => {
|
||||
appConfigService.config['logLevel'] = 'trace';
|
||||
providesLogComponent = TestBed.createComponent(ProvidesLogComponent);
|
||||
|
||||
providesLogComponent.componentInstance.logService.onMessage.subscribe(() => {
|
||||
done();
|
||||
});
|
||||
|
||||
providesLogComponent.componentInstance.log();
|
||||
|
||||
});
|
||||
providesLogComponent.componentInstance.logService.onMessage.subscribe(
|
||||
() => {
|
||||
done();
|
||||
}
|
||||
);
|
||||
|
||||
providesLogComponent.componentInstance.log();
|
||||
});
|
||||
});
|
||||
|
@@ -23,13 +23,13 @@ import { PageTitleService } from './page-title.service';
|
||||
import { TranslationService } from './translation.service';
|
||||
import { Title } from '@angular/platform-browser';
|
||||
|
||||
describe('AppTitle service', () => {
|
||||
describe('PageTitleService', () => {
|
||||
|
||||
let titleService: any;
|
||||
let translationService: any;
|
||||
let pageTitleService: any;
|
||||
let appConfigService: any;
|
||||
let titleServiceSpy: any;
|
||||
let titleService: Title;
|
||||
let translationService: TranslationService;
|
||||
let pageTitleService: PageTitleService;
|
||||
let appConfigService: AppConfigService;
|
||||
let titleServiceSpy: jasmine.Spy;
|
||||
|
||||
setupTestBed({
|
||||
imports: [
|
||||
|
@@ -69,11 +69,6 @@ describe('TranslationService', () => {
|
||||
jasmine.Ajax.uninstall();
|
||||
});
|
||||
|
||||
it('is defined', () => {
|
||||
expect(translationService).toBeDefined();
|
||||
expect(translationService instanceof TranslationService).toBeTruthy();
|
||||
});
|
||||
|
||||
it('should be able to get translations of the KEY: TEST', () => {
|
||||
translationService.get('TEST').subscribe((res: string) => {
|
||||
expect(res).toEqual('This is a test');
|
||||
|
109
lib/core/templates/empty-content/empty-content.component.spec.ts
Normal file
109
lib/core/templates/empty-content/empty-content.component.spec.ts
Normal file
@@ -0,0 +1,109 @@
|
||||
/*!
|
||||
* @license
|
||||
* Copyright 2019 Alfresco Software, Ltd.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import { Component } from '@angular/core';
|
||||
import { ComponentFixture, TestBed, async } from '@angular/core/testing';
|
||||
import { By } from '@angular/platform-browser';
|
||||
import { setupTestBed, CoreModule, TranslationService } from '@alfresco/adf-core';
|
||||
import { NoopAnimationsModule } from '@angular/platform-browser/animations';
|
||||
import { TemplateModule } from '../template.module';
|
||||
import { TranslationMock } from '../../mock/translation.service.mock';
|
||||
import { TranslateService } from '@ngx-translate/core';
|
||||
import { of } from 'rxjs';
|
||||
|
||||
@Component({
|
||||
selector: 'adf-test-component',
|
||||
template: `
|
||||
<adf-empty-content
|
||||
icon="delete"
|
||||
[title]="'CUSTOM_TITLE'"
|
||||
[subtitle]="'CUSTOM_SUBTITLE'">
|
||||
<div class="adf-empty-content__text">SUBTITLE-1</div>
|
||||
<div class="adf-empty-content__text">SUBTITLE-2</div>
|
||||
<div class="adf-empty-content__text">SUBTITLE-3</div>
|
||||
</adf-empty-content>
|
||||
`
|
||||
})
|
||||
class TestComponent {}
|
||||
|
||||
describe('EmptyContentComponent', () => {
|
||||
|
||||
let fixture: ComponentFixture<TestComponent>;
|
||||
let translateService: TranslateService;
|
||||
|
||||
setupTestBed({
|
||||
imports: [
|
||||
NoopAnimationsModule,
|
||||
CoreModule.forRoot(),
|
||||
TemplateModule
|
||||
],
|
||||
declarations: [
|
||||
TestComponent
|
||||
],
|
||||
providers: [
|
||||
{ provide: TranslationService, useClass: TranslationMock }
|
||||
]
|
||||
});
|
||||
|
||||
beforeEach(() => {
|
||||
fixture = TestBed.createComponent(TestComponent);
|
||||
translateService = TestBed.get(TranslateService);
|
||||
});
|
||||
|
||||
it('should render custom title', async(() => {
|
||||
fixture.detectChanges();
|
||||
fixture.whenStable().then(() => {
|
||||
const title = fixture.debugElement.query(By.css('.adf-empty-content__title'));
|
||||
expect(title).toBeDefined('title element not found');
|
||||
expect(title.nativeElement.textContent).toContain('CUSTOM_TITLE', 'incorrect title value');
|
||||
});
|
||||
}));
|
||||
|
||||
it('should translate title and subtitle', async(() => {
|
||||
spyOn(translateService, 'get').and.callFake((key: string) => {
|
||||
switch (key) {
|
||||
case 'CUSTOM_TITLE':
|
||||
return of('ENG_CUSTOM_TITLE');
|
||||
case 'CUSTOM_SUBTITLE':
|
||||
return of('ENG_CUSTOM_SUBTITLE');
|
||||
default:
|
||||
return of(key);
|
||||
}
|
||||
});
|
||||
|
||||
fixture.detectChanges();
|
||||
fixture.whenStable().then(() => {
|
||||
const title = fixture.debugElement.query(By.css('.adf-empty-content__title'));
|
||||
const subtitle = fixture.debugElement.query(By.css('.adf-empty-content__subtitle'));
|
||||
|
||||
expect(title).toBeDefined('title element not found');
|
||||
expect(title.nativeElement.textContent).toContain('ENG_CUSTOM_TITLE', 'incorrect title value');
|
||||
|
||||
expect(subtitle).toBeDefined('subtitle element not found');
|
||||
expect(subtitle.nativeElement.textContent).toContain('ENG_CUSTOM_SUBTITLE', 'incorrect subtitle value');
|
||||
});
|
||||
}));
|
||||
|
||||
it('should render multiple subtitle elements', () => {
|
||||
const subTitles = fixture.debugElement.queryAll(By.css('.adf-empty-content__text'));
|
||||
|
||||
expect(subTitles.length).toBe(3);
|
||||
expect(subTitles[0].nativeElement.textContent).toContain('SUBTITLE-1', 'missing SUBTITLE-1');
|
||||
expect(subTitles[1].nativeElement.textContent).toContain('SUBTITLE-2', 'missing SUBTITLE-2');
|
||||
expect(subTitles[2].nativeElement.textContent).toContain('SUBTITLE-3', 'missing SUBTITLE-3');
|
||||
});
|
||||
});
|
Reference in New Issue
Block a user