unit tests for manual regression cases (#1841)

* unit test for pagination in shared

* extra tests for sticky headers

* move e2e to unit test
This commit is contained in:
Denys Vuika
2020-12-04 15:06:54 +00:00
committed by GitHub
parent ad58be3d05
commit 97372711ea
5 changed files with 152 additions and 17 deletions

View File

@@ -40,12 +40,6 @@ describe('Empty list views', () => {
done();
});
it('[C280131] empty Personal Files', async () => {
await page.clickPersonalFiles();
expect(await dataTable.isEmpty()).toBe(true, 'list is not empty');
expect(await dataTable.getEmptyDragAndDropText()).toContain('Drag and drop');
});
it('[C217099] empty My Libraries', async () => {
await page.goToMyLibraries();
expect(await dataTable.isEmpty()).toBe(true, 'list is not empty');

View File

@@ -33,15 +33,17 @@ import {
AppConfigPipe,
AlfrescoApiService,
AlfrescoApiServiceMock,
DataTableModule
DataTableModule,
PaginationModule
} from '@alfresco/adf-core';
import { DocumentListComponent, FilterSearch } from '@alfresco/adf-content-services';
import { NodeActionsService } from '../../services/node-actions.service';
import { FilesComponent } from './files.component';
import { AppTestingModule } from '../../testing/app-testing.module';
import { ContentApiService } from '@alfresco/aca-shared';
import { ContentApiService, SharedDirectivesModule } from '@alfresco/aca-shared';
import { of, throwError } from 'rxjs';
import { By } from '@angular/platform-browser';
import { DirectivesModule } from '../../directives/directives.module';
describe('FilesComponent', () => {
let node;
@@ -55,9 +57,20 @@ describe('FilesComponent', () => {
navigate: jasmine.createSpy('navigate')
};
function verifyEmptyFilterTemplate() {
const template = fixture.debugElement.query(By.css('.empty-search__block')).nativeElement as HTMLElement;
expect(template).toBeDefined();
expect(template.innerText).toBe('APP.BROWSE.SEARCH.NO_FILTER_RESULTS');
}
function verifyEmptyTemplate() {
const template = fixture.debugElement.query(By.css('.adf-empty-list_template'));
expect(template).not.toBeNull();
}
beforeEach(() => {
TestBed.configureTestingModule({
imports: [AppTestingModule, DataTableModule],
imports: [AppTestingModule, DataTableModule, PaginationModule, SharedDirectivesModule, DirectivesModule],
declarations: [FilesComponent, DataTableComponent, NodeFavoriteDirective, DocumentListComponent, AppConfigPipe],
providers: [
{ provide: AlfrescoApiService, useClass: AlfrescoApiServiceMock },
@@ -309,17 +322,47 @@ describe('FilesComponent', () => {
});
});
describe('filter header', () => {
it('should show custom empty template if filter headers are applied', async () => {
describe('empty template', () => {
beforeEach(() => {
fixture.detectChanges();
spyOn(component.documentList, 'loadFolder').and.callFake(() => {});
});
it('should show custom empty template if filter headers are applied', async () => {
component.onFilterSelected([{ key: 'name', value: 'aaa' } as FilterSearch]);
fixture.detectChanges();
await fixture.whenStable();
const emptyContentTemplate: HTMLElement = fixture.debugElement.query(By.css('.empty-search__block')).nativeElement;
expect(emptyContentTemplate).toBeDefined();
expect(emptyContentTemplate.innerText).toBe('APP.BROWSE.SEARCH.NO_FILTER_RESULTS');
verifyEmptyFilterTemplate();
});
it('should display custom empty template when no data available', async () => {
spyOn(contentApi, 'getNode').and.returnValue(of({ entry: node }));
fixture.detectChanges();
await fixture.whenStable();
verifyEmptyTemplate();
});
});
it('[C308041] should have sticky headers', async () => {
fixture.detectChanges();
spyOn(component.documentList, 'loadFolder').and.callFake(() => {});
spyOn(contentApi, 'getNode').and.returnValue(of({ entry: node }));
fixture.componentInstance.nodeResult = {
list: {
entries: [{ entry: { id: '1', isFile: true } } as any, { entry: { id: '2', isFile: true } } as any],
pagination: { count: 2 }
}
};
fixture.detectChanges();
await fixture.whenStable();
const header = fixture.nativeElement.querySelector('.adf-sticky-header');
expect(header).not.toBeNull();
});
});

View File

@@ -1,6 +1,6 @@
<aca-page-layout>
<aca-page-layout-header>
<adf-breadcrumb root="APP.BROWSE.SHARED.TITLE"> </adf-breadcrumb>
<adf-breadcrumb root="APP.BROWSE.SHARED.TITLE"></adf-breadcrumb>
<adf-toolbar class="adf-toolbar--inline">
<ng-container *ngFor="let entry of actions; trackBy: trackByActionId">

View File

@@ -0,0 +1,89 @@
/*!
* @license
* Alfresco Example Content Application
*
* Copyright (C) 2005 - 2020 Alfresco Software Limited
*
* This file is part of the Alfresco Example Content Application.
* If the software was purchased under a paid Alfresco license, the terms of
* the paid license agreement will prevail. Otherwise, the software is
* provided under the following open source license terms:
*
* The Alfresco Example Content Application is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* The Alfresco Example Content Application is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with Alfresco. If not, see <http://www.gnu.org/licenses/>.
*/
import { TestBed, ComponentFixture } from '@angular/core/testing';
import { NO_ERRORS_SCHEMA } from '@angular/core';
import { AlfrescoApiService, AlfrescoApiServiceMock, NodeFavoriteDirective, DataTableComponent, AppConfigPipe } from '@alfresco/adf-core';
import { CustomResourcesService, DocumentListComponent } from '@alfresco/adf-content-services';
import { SharedFilesComponent } from './shared-files.component';
import { AppTestingModule } from '../../testing/app-testing.module';
import { Router } from '@angular/router';
import { of } from 'rxjs';
import { By } from '@angular/platform-browser';
import { SharedLinkPaging } from '@alfresco/js-api';
describe('SharedFilesComponent', () => {
let fixture: ComponentFixture<SharedFilesComponent>;
let alfrescoApi: AlfrescoApiService;
let page: SharedLinkPaging;
let customResourcesService: CustomResourcesService;
const mockRouter = {
url: 'shared-files'
};
beforeEach(() => {
page = {
list: {
entries: [{ entry: { id: '1' } }, { entry: { id: '2' } }],
pagination: { count: 2 }
}
};
});
beforeEach(() => {
TestBed.configureTestingModule({
imports: [AppTestingModule],
declarations: [DataTableComponent, NodeFavoriteDirective, DocumentListComponent, SharedFilesComponent, AppConfigPipe],
providers: [
{ provide: AlfrescoApiService, useClass: AlfrescoApiServiceMock },
{
provide: Router,
useValue: mockRouter
}
],
schemas: [NO_ERRORS_SCHEMA]
});
customResourcesService = TestBed.inject(CustomResourcesService);
alfrescoApi = TestBed.inject(AlfrescoApiService);
alfrescoApi.reset();
spyOn(alfrescoApi.sharedLinksApi, 'findSharedLinks').and.returnValue(Promise.resolve(page));
spyOn(customResourcesService, 'loadSharedLinks').and.returnValue(of(page));
fixture = TestBed.createComponent(SharedFilesComponent);
});
it('[C280093] should not display pagination for empty data', async () => {
page = { list: { pagination: { totalItems: 0 }, entries: [] } };
fixture.detectChanges();
await fixture.whenStable();
const pagination = fixture.debugElement.query(By.css('.adf-pagination'));
expect(pagination).toBeNull();
});
});

View File

@@ -28,7 +28,7 @@ import { Subject } from 'rxjs';
import { SetSelectedNodesAction } from '@alfresco/aca-shared/store';
describe('DocumentListDirective', () => {
let documentListDirective;
let documentListDirective: DocumentListDirective;
const documentListMock: any = {
currentFolderId: '',
@@ -101,6 +101,15 @@ describe('DocumentListDirective', () => {
expect(storeMock.dispatch).toHaveBeenCalled();
});
it('should enable sticky headers', () => {
mockRouter.url = '/some-route';
documentListMock.currentFolderId = '-mysites-';
documentListDirective.ngOnInit();
documentListMock.ready.next();
expect(documentListMock.stickyHeader).toBeTruthy();
});
it('should set `isLibrary` to true if selected node is a library', () => {
mockRouter.url = '/some-route';
documentListMock.currentFolderId = '-mysites-';
@@ -122,7 +131,7 @@ describe('DocumentListDirective', () => {
it('should update store selection on `node-select` event', () => {
mockRouter.url = '/some-route';
documentListDirective.ngOnInit();
documentListDirective.onNodeSelect({ detail: { node: {} } });
documentListDirective.onNodeSelect({ detail: { node: {} } } as any);
expect(storeMock.dispatch).toHaveBeenCalled();
});