From 97372711ea3912c0aaa73b0df31049ac8657b71a Mon Sep 17 00:00:00 2001 From: Denys Vuika Date: Fri, 4 Dec 2020 15:06:54 +0000 Subject: [PATCH] unit tests for manual regression cases (#1841) * unit test for pagination in shared * extra tests for sticky headers * move e2e to unit test --- e2e/suites/list-views/empty-list.test.ts | 6 -- .../components/files/files.component.spec.ts | 59 ++++++++++-- .../shared-files/shared-files.component.html | 2 +- .../shared-files.component.spec.ts | 89 +++++++++++++++++++ .../document-list.directive.spec.ts | 13 ++- 5 files changed, 152 insertions(+), 17 deletions(-) create mode 100644 src/app/components/shared-files/shared-files.component.spec.ts diff --git a/e2e/suites/list-views/empty-list.test.ts b/e2e/suites/list-views/empty-list.test.ts index 904bd1b7f..28906af9f 100755 --- a/e2e/suites/list-views/empty-list.test.ts +++ b/e2e/suites/list-views/empty-list.test.ts @@ -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'); diff --git a/src/app/components/files/files.component.spec.ts b/src/app/components/files/files.component.spec.ts index d2c1e0e08..28401effe 100644 --- a/src/app/components/files/files.component.spec.ts +++ b/src/app/components/files/files.component.spec.ts @@ -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(); + }); }); diff --git a/src/app/components/shared-files/shared-files.component.html b/src/app/components/shared-files/shared-files.component.html index 24da505f5..f2d5f025e 100644 --- a/src/app/components/shared-files/shared-files.component.html +++ b/src/app/components/shared-files/shared-files.component.html @@ -1,6 +1,6 @@ - + diff --git a/src/app/components/shared-files/shared-files.component.spec.ts b/src/app/components/shared-files/shared-files.component.spec.ts new file mode 100644 index 000000000..3ec5f4480 --- /dev/null +++ b/src/app/components/shared-files/shared-files.component.spec.ts @@ -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 . + */ + +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; + 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(); + }); +}); diff --git a/src/app/directives/document-list.directive.spec.ts b/src/app/directives/document-list.directive.spec.ts index 51e9deaa6..be9698166 100644 --- a/src/app/directives/document-list.directive.spec.ts +++ b/src/app/directives/document-list.directive.spec.ts @@ -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(); });