[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:
Denys Vuika
2020-02-08 01:08:35 +00:00
committed by GitHub
parent a3cbf9bcd3
commit f54bc24317
20 changed files with 471 additions and 297 deletions

View File

@@ -100,10 +100,6 @@ describe('ContentNodeDialogService', () => {
});
});
it('should be able to create the service', () => {
expect(service).not.toBeNull();
});
it('should be able to open the dialog when node has permission', () => {
service.openCopyMoveDialog('fake-action', fakeNode, '!update');
expect(spyOnDialogOpen).toHaveBeenCalled();
@@ -111,8 +107,7 @@ describe('ContentNodeDialogService', () => {
it('should NOT be able to open the dialog when node has NOT permission', () => {
service.openCopyMoveDialog('fake-action', fakeNode, 'noperm').subscribe(
() => {
},
() => {},
(error) => {
expect(spyOnDialogOpen).not.toHaveBeenCalled();
expect(JSON.parse(error.message).error.statusCode).toBe(403);
@@ -121,8 +116,7 @@ describe('ContentNodeDialogService', () => {
it('should be able to open the dialog using a folder id', fakeAsync(() => {
spyOn(documentListService, 'getFolderNode').and.returnValue(of(fakeNodeEntry));
service.openFileBrowseDialogByFolderId('fake-folder-id').subscribe(() => {
});
service.openFileBrowseDialogByFolderId('fake-folder-id').subscribe(() => {});
tick();
expect(spyOnDialogOpen).toHaveBeenCalled();
}));
@@ -130,8 +124,7 @@ describe('ContentNodeDialogService', () => {
it('should be able to open the dialog for files using the first user site', fakeAsync(() => {
spyOn(sitesService, 'getSites').and.returnValue(of(fakeSiteList));
spyOn(documentListService, 'getFolderNode').and.returnValue(of(fakeNodeEntry));
service.openFileBrowseDialogBySite().subscribe(() => {
});
service.openFileBrowseDialogBySite().subscribe(() => {});
tick();
expect(spyOnDialogOpen).toHaveBeenCalled();
}));
@@ -139,8 +132,7 @@ describe('ContentNodeDialogService', () => {
it('should be able to open the dialog for folder using the first user site', fakeAsync(() => {
spyOn(sitesService, 'getSites').and.returnValue(of(fakeSiteList));
spyOn(documentListService, 'getFolderNode').and.returnValue(of(fakeNodeEntry));
service.openFolderBrowseDialogBySite().subscribe(() => {
});
service.openFolderBrowseDialogBySite().subscribe(() => {});
tick();
expect(spyOnDialogOpen).toHaveBeenCalled();
}));

View File

@@ -97,12 +97,13 @@ describe('ContentNodeSelectorComponent', () => {
describe('Parameters', () => {
let documentListService,
sitesService;
let documentListService: DocumentListService;
let sitesService: SitesService;
beforeEach(() => {
documentListService = TestBed.get(DocumentListService);
sitesService = TestBed.get(SitesService);
spyOn(documentListService, 'getFolderNode').and.returnValue(of(<NodeEntry> { entry: { path: { elements: [] } } }));
spyOn(documentListService, 'getFolder').and.returnValue(throwError('No results for test'));
spyOn(sitesService, 'getSites').and.returnValue(of({
@@ -111,6 +112,7 @@ describe('ContentNodeSelectorComponent', () => {
<SiteEntry> { entry: { guid: 'blog', id: 'blog' } }]
}
}));
component.currentFolderId = 'cat-girl-nuku-nuku';
fixture.detectChanges();
});
@@ -202,14 +204,17 @@ describe('ContentNodeSelectorComponent', () => {
describe('Breadcrumbs', () => {
let documentListService, sitesService;
let documentListService: DocumentListService;
let sitesService: SitesService;
beforeEach(() => {
documentListService = TestBed.get(DocumentListService);
sitesService = TestBed.get(SitesService);
spyOn(documentListService, 'getFolderNode').and.returnValue(of(<NodeEntry> { entry: { path: { elements: [] } } }));
spyOn(documentListService, 'getFolder').and.returnValue(throwError('No results for test'));
spyOn(sitesService, 'getSites').and.returnValue(of({ list: { entries: [] } }));
component.currentFolderId = 'cat-girl-nuku-nuku';
fixture.detectChanges();
});
@@ -309,7 +314,7 @@ describe('ContentNodeSelectorComponent', () => {
expect(breadcrumb.componentInstance.folderNode).toEqual(undefined);
}));
it('should keep breadcrumb\'s folderNode unchanged if breadcrumbTransform is NOT defined', (done) => {
it('should keep breadcrumb folderNode unchanged if breadcrumbTransform is NOT defined', (done) => {
fixture.detectChanges();
fixture.whenStable().then(() => {
@@ -322,7 +327,7 @@ describe('ContentNodeSelectorComponent', () => {
});
});
it('should make changes to breadcrumb\'s folderNode if breadcrumbTransform is defined', (done) => {
it('should make changes to breadcrumb folderNode if breadcrumbTransform is defined', (done) => {
const transformedFolderNode = <Node> {
id: 'trans-node',
name: 'trans-node-name',

View File

@@ -136,7 +136,7 @@ describe('DocumentList', () => {
expect(columns[5]).toBe(column);
});
it('should call action\'s handler with node', () => {
it('should call action handler with node', () => {
const node = new FileNode();
const action = new ContentActionModel();
action.handler = () => {
@@ -149,7 +149,7 @@ describe('DocumentList', () => {
});
it('should call action\'s handler with node and permission', () => {
it('should call action handler with node and permission', () => {
const node = new FileNode();
const action = new ContentActionModel();
action.handler = () => {
@@ -162,7 +162,7 @@ describe('DocumentList', () => {
expect(action.handler).toHaveBeenCalledWith(node, documentList, 'fake-permission');
});
it('should call action\'s execute with node if it is defined', () => {
it('should call action execute with node if it is defined', () => {
const node = new FileNode();
const action = new ContentActionModel();
action.execute = () => {
@@ -174,7 +174,7 @@ describe('DocumentList', () => {
expect(action.execute).toHaveBeenCalledWith(node);
});
it('should call action\'s execute only after the handler has been executed', () => {
it('should call action execute only after the handler has been executed', () => {
const deleteObservable: Subject<any> = new Subject<any>();
const node = new FileNode();
const action = new ContentActionModel();

View File

@@ -24,8 +24,7 @@ import {
setupTestBed,
CoreModule,
UserPreferencesService,
SearchTextInputComponent,
ThumbnailService
SearchTextInputComponent
} from '@alfresco/adf-core';
import { noResult, results } from '../../mock';
import { SearchControlComponent } from './search-control.component';
@@ -43,24 +42,14 @@ import { NoopAnimationsModule } from '@angular/platform-browser/animations';
</adf-search-control>
`
})
export class SimpleSearchTestCustomEmptyComponent {
customMessage: string = '';
customMessage = '';
@ViewChild(SearchControlComponent)
searchComponent: SearchControlComponent;
@ViewChild(SearchTextInputComponent)
searchTextInputComponent: SearchTextInputComponent;
constructor() {
}
setCustomMessageForNoResult(message: string) {
this.customMessage = message;
}
}
describe('SearchControlComponent', () => {
@@ -74,7 +63,7 @@ describe('SearchControlComponent', () => {
let fixtureCustom: ComponentFixture<SimpleSearchTestCustomEmptyComponent>;
let elementCustom: HTMLElement;
let componentCustom: SimpleSearchTestCustomEmptyComponent;
let searchServiceSpy: any;
let searchServiceSpy: jasmine.Spy;
let userPreferencesService: UserPreferencesService;
setupTestBed({
@@ -87,11 +76,6 @@ describe('SearchControlComponent', () => {
SearchComponent,
EmptySearchResultComponent,
SimpleSearchTestCustomEmptyComponent
],
providers: [
ThumbnailService,
SearchService,
UserPreferencesService
]
});
@@ -190,7 +174,6 @@ describe('SearchControlComponent', () => {
describe('autocomplete list', () => {
it('should make autocomplete list control hidden initially', (done) => {
fixture.detectChanges();
fixture.whenStable().then(() => {
expect(element.querySelector('#autocomplete-search-result-list')).toBeNull();
@@ -204,10 +187,11 @@ describe('SearchControlComponent', () => {
fixture.detectChanges();
typeWordIntoSearchInput('TEST');
fixture.detectChanges();
fixture.whenStable().then(() => {
fixture.detectChanges();
const resultElement: Element = element.querySelector('#autocomplete-search-result-list');
const resultElement = element.querySelector('#autocomplete-search-result-list');
expect(resultElement).not.toBe(null);
done();
});
@@ -222,7 +206,7 @@ describe('SearchControlComponent', () => {
fixture.detectChanges();
fixture.whenStable().then(() => {
fixture.detectChanges();
const noResultElement: Element = element.querySelector('#search_no_result');
const noResultElement = element.querySelector('#search_no_result');
expect(noResultElement).not.toBe(null);
done();
});
@@ -235,10 +219,11 @@ describe('SearchControlComponent', () => {
const inputDebugElement = debugElement.query(By.css('#adf-control-input'));
typeWordIntoSearchInput('NO RES');
fixture.detectChanges();
fixture.whenStable().then(() => {
fixture.detectChanges();
let resultElement: Element = element.querySelector('#autocomplete-search-result-list');
let resultElement = element.querySelector('#autocomplete-search-result-list');
expect(resultElement).not.toBe(null);
inputDebugElement.nativeElement.dispatchEvent(new Event('blur'));
@@ -256,6 +241,7 @@ describe('SearchControlComponent', () => {
const inputDebugElement = debugElement.query(By.css('#adf-control-input'));
typeWordIntoSearchInput('TEST');
fixture.detectChanges();
fixture.whenStable().then(() => {
fixture.detectChanges();
@@ -277,6 +263,7 @@ describe('SearchControlComponent', () => {
const inputDebugElement = debugElement.query(By.css('#adf-control-input'));
typeWordIntoSearchInput('TEST');
fixture.detectChanges();
fixture.whenStable().then(() => {
fixture.detectChanges();
@@ -301,6 +288,7 @@ describe('SearchControlComponent', () => {
const inputDebugElement = debugElement.query(By.css('#adf-control-input'));
typeWordIntoSearchInput('TEST');
fixture.detectChanges();
fixture.whenStable().then(() => {
fixture.detectChanges();
@@ -319,7 +307,6 @@ describe('SearchControlComponent', () => {
});
it('should focus input element when autocomplete list is cancelled', (done) => {
searchServiceSpy.and.returnValue(of(JSON.parse(JSON.stringify(results))));
fixture.detectChanges();
@@ -328,6 +315,7 @@ describe('SearchControlComponent', () => {
escapeEvent.keyCode = 27;
inputDebugElement.nativeElement.focus();
inputDebugElement.nativeElement.dispatchEvent(escapeEvent);
fixture.detectChanges();
fixture.whenStable().then(() => {
expect(element.querySelector('#result_name_0')).toBeNull();
@@ -363,6 +351,7 @@ describe('SearchControlComponent', () => {
});
fixture.detectChanges();
typeWordIntoSearchInput('TEST');
fixture.detectChanges();
fixture.whenStable().then(() => {
fixture.detectChanges();
@@ -426,13 +415,13 @@ describe('SearchControlComponent', () => {
fixtureCustom.detectChanges();
spyOn(componentCustom.searchComponent.searchTextInput, 'isSearchBarActive').and.returnValue(true);
searchServiceSpy.and.returnValue(of(noResult));
componentCustom.setCustomMessageForNoResult(noResultCustomMessage);
componentCustom.customMessage = noResultCustomMessage;
fixtureCustom.detectChanges();
const inputDebugElement = fixtureCustom.debugElement.query(By.css('#adf-control-input'));
inputDebugElement.nativeElement.value = 'SOMETHING';
inputDebugElement.nativeElement.focus();
inputDebugElement.nativeElement.dispatchEvent(new Event('input'));
const input: HTMLInputElement = fixtureCustom.debugElement.query(By.css('#adf-control-input')).nativeElement;
input.value = 'SOMETHING';
input.focus();
input.dispatchEvent(new Event('input'));
fixtureCustom.detectChanges();
fixtureCustom.whenStable().then(() => {

View File

@@ -17,11 +17,16 @@
import { SearchFilterComponent } from './search-filter.component';
import { SearchQueryBuilderService } from '../../search-query-builder.service';
import { AppConfigService, TranslationMock } from '@alfresco/adf-core';
import { AppConfigService, TranslationMock, CoreModule, TranslationService, SearchService } from '@alfresco/adf-core';
import { Subject } from 'rxjs';
import { FacetFieldBucket } from '../../facet-field-bucket.interface';
import { FacetField } from '../../facet-field.interface';
import { SearchFilterList } from './models/search-filter-list.model';
import { TestBed, async } from '@angular/core/testing';
import { By } from '@angular/platform-browser';
import { NO_ERRORS_SCHEMA } from '@angular/core';
import { NoopAnimationsModule } from '@angular/platform-browser/animations';
import { HttpClientModule } from '@angular/common/http';
describe('SearchFilterComponent', () => {
@@ -31,18 +36,66 @@ describe('SearchFilterComponent', () => {
const translationMock = new TranslationMock();
beforeEach(() => {
appConfig = new AppConfigService(null);
appConfig.config.search = {};
queryBuilder = new SearchQueryBuilderService(appConfig, null);
const searchMock: any = {
dataLoaded: new Subject()
};
translationMock.instant = (key) => `${key}_translated`;
TestBed.configureTestingModule({
imports: [
CoreModule.forRoot(),
HttpClientModule,
NoopAnimationsModule
],
declarations: [SearchFilterComponent],
providers: [
{ provide: SearchService, useValue: searchMock },
{ provide: TranslationService, useValue: translationMock }
],
schemas: [ NO_ERRORS_SCHEMA ]
});
appConfig = TestBed.get(AppConfigService);
appConfig.config.search = {};
queryBuilder = TestBed.get(SearchQueryBuilderService);
component = new SearchFilterComponent(queryBuilder, searchMock, translationMock);
component.ngOnInit();
});
it('should have expandable categories', async(() => {
queryBuilder.categories = [
{
id: 'cat-1',
name: 'category-1',
expanded: false,
enabled: false,
component: {
selector: 'cat-1-component',
settings: null
}
}
];
const fixture = TestBed.createComponent(SearchFilterComponent);
fixture.detectChanges();
fixture.whenStable().then(() => {
const panels = fixture.debugElement.queryAll(By.css('.mat-expansion-panel'));
expect(panels.length).toBe(1);
const element: HTMLElement = panels[0].nativeElement;
(element.childNodes[0] as HTMLElement).click();
fixture.detectChanges();
expect(element.classList.contains('mat-expanded')).toBeTruthy();
(element.childNodes[0] as HTMLElement).click();
fixture.detectChanges();
expect(element.classList.contains('mat-expanded')).toBeFalsy();
});
}));
it('should subscribe to query builder executed event', () => {
spyOn(component, 'onDataLoaded').and.stub();
const data = {};