mirror of
https://github.com/Alfresco/alfresco-ng2-components.git
synced 2025-05-26 17:24:56 +00:00
[ACA-4205] safety checks to avoid crashes in doclist (#6432)
* safety checks to avoid crashes in doclist * reduce shared state in tests * fix test
This commit is contained in:
parent
c45a9c4489
commit
751ca03975
@ -21,7 +21,7 @@ import { ComponentFixture, TestBed } from '@angular/core/testing';
|
|||||||
import { ContentNodeSelectorComponent } from './content-node-selector.component';
|
import { ContentNodeSelectorComponent } from './content-node-selector.component';
|
||||||
import { Node, NodeEntry } from '@alfresco/js-api';
|
import { Node, NodeEntry } from '@alfresco/js-api';
|
||||||
import { By } from '@angular/platform-browser';
|
import { By } from '@angular/platform-browser';
|
||||||
import { setupTestBed, SitesService, ContentService } from '@alfresco/adf-core';
|
import { SitesService, ContentService } from '@alfresco/adf-core';
|
||||||
import { of } from 'rxjs';
|
import { of } from 'rxjs';
|
||||||
import { ContentTestingModule } from '../testing/content.testing.module';
|
import { ContentTestingModule } from '../testing/content.testing.module';
|
||||||
import { DocumentListService } from '../document-list/services/document-list.service';
|
import { DocumentListService } from '../document-list/services/document-list.service';
|
||||||
@ -34,62 +34,65 @@ import { ContentNodeSelectorPanelComponent } from './content-node-selector-panel
|
|||||||
describe('ContentNodeSelectorComponent', () => {
|
describe('ContentNodeSelectorComponent', () => {
|
||||||
let component: ContentNodeSelectorComponent;
|
let component: ContentNodeSelectorComponent;
|
||||||
let fixture: ComponentFixture<ContentNodeSelectorComponent>;
|
let fixture: ComponentFixture<ContentNodeSelectorComponent>;
|
||||||
|
let data: any;
|
||||||
const dialogRef = {
|
|
||||||
keydownEvents: () => of(null),
|
|
||||||
backdropClick: () => of(null),
|
|
||||||
close: jasmine.createSpy('close')
|
|
||||||
};
|
|
||||||
|
|
||||||
const data: any = {
|
|
||||||
title: 'Choose along citizen...',
|
|
||||||
actionName: 'choose',
|
|
||||||
select: new EventEmitter<Node>(),
|
|
||||||
rowFilter: (shareDataRow) => shareDataRow.node.entry.name === 'impossible-name',
|
|
||||||
imageResolver: () => 'piccolo',
|
|
||||||
currentFolderId: 'cat-girl-nuku-nuku',
|
|
||||||
selectionMode: 'multiple',
|
|
||||||
showLocalUploadButton: true
|
|
||||||
};
|
|
||||||
|
|
||||||
const fakeFolderNodeWithPermission = new NodeEntry({
|
|
||||||
entry: {
|
|
||||||
allowableOperations: [
|
|
||||||
'create',
|
|
||||||
'update'
|
|
||||||
],
|
|
||||||
isFolder: true,
|
|
||||||
name: 'Folder Fake Name',
|
|
||||||
nodeType: 'cm:folder'
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
setupTestBed({
|
|
||||||
imports: [
|
|
||||||
TranslateModule.forRoot(),
|
|
||||||
ContentTestingModule,
|
|
||||||
MatDialogModule,
|
|
||||||
UploadModule
|
|
||||||
],
|
|
||||||
providers: [
|
|
||||||
{ provide: MAT_DIALOG_DATA, useValue: data },
|
|
||||||
{ provide: MatDialogRef, useValue: dialogRef }
|
|
||||||
],
|
|
||||||
schemas: [CUSTOM_ELEMENTS_SCHEMA]
|
|
||||||
});
|
|
||||||
|
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
const documentListService: DocumentListService = TestBed.inject(DocumentListService);
|
data = {
|
||||||
|
title: 'Choose along citizen...',
|
||||||
|
actionName: 'choose',
|
||||||
|
select: new EventEmitter<Node>(),
|
||||||
|
rowFilter: (shareDataRow) => shareDataRow.node.entry.name === 'impossible-name',
|
||||||
|
imageResolver: () => 'piccolo',
|
||||||
|
currentFolderId: 'cat-girl-nuku-nuku',
|
||||||
|
selectionMode: 'multiple',
|
||||||
|
showLocalUploadButton: true
|
||||||
|
};
|
||||||
|
|
||||||
|
TestBed.configureTestingModule({
|
||||||
|
imports: [
|
||||||
|
TranslateModule.forRoot(),
|
||||||
|
ContentTestingModule,
|
||||||
|
MatDialogModule,
|
||||||
|
UploadModule
|
||||||
|
],
|
||||||
|
providers: [
|
||||||
|
{ provide: MAT_DIALOG_DATA, useValue: data },
|
||||||
|
{
|
||||||
|
provide: MatDialogRef,
|
||||||
|
useValue: {
|
||||||
|
keydownEvents: () => of(null),
|
||||||
|
backdropClick: () => of(null),
|
||||||
|
close: jasmine.createSpy('close')
|
||||||
|
}
|
||||||
|
}
|
||||||
|
],
|
||||||
|
schemas: [CUSTOM_ELEMENTS_SCHEMA]
|
||||||
|
});
|
||||||
|
|
||||||
|
const documentListService = TestBed.inject(DocumentListService);
|
||||||
const sitesService: SitesService = TestBed.inject(SitesService);
|
const sitesService: SitesService = TestBed.inject(SitesService);
|
||||||
|
|
||||||
spyOn(documentListService, 'getFolder').and.returnValue(of({ list: [] }));
|
spyOn(documentListService, 'getFolder').and.callThrough();
|
||||||
spyOn(documentListService, 'getFolderNode').and.returnValue(of({ entry: {} }));
|
spyOn(documentListService, 'getFolderNode').and.callThrough();
|
||||||
spyOn(sitesService, 'getSites').and.returnValue(of({ list: { entries: [] } }));
|
spyOn(sitesService, 'getSites').and.returnValue(of({ list: { entries: [] } }));
|
||||||
|
|
||||||
fixture = TestBed.createComponent(ContentNodeSelectorComponent);
|
fixture = TestBed.createComponent(ContentNodeSelectorComponent);
|
||||||
component = fixture.componentInstance;
|
component = fixture.componentInstance;
|
||||||
const contentService = TestBed.inject(ContentService);
|
const contentService = TestBed.inject(ContentService);
|
||||||
spyOn(contentService, 'hasAllowableOperations').and.returnValue(true);
|
spyOn(contentService, 'hasAllowableOperations').and.returnValue(true);
|
||||||
|
|
||||||
|
const fakeFolderNodeWithPermission = new NodeEntry({
|
||||||
|
entry: {
|
||||||
|
allowableOperations: [
|
||||||
|
'create',
|
||||||
|
'update'
|
||||||
|
],
|
||||||
|
isFolder: true,
|
||||||
|
name: 'Folder Fake Name',
|
||||||
|
nodeType: 'cm:folder'
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
spyOn(contentService, 'getNode').and.returnValue(of(fakeFolderNodeWithPermission));
|
spyOn(contentService, 'getNode').and.returnValue(of(fakeFolderNodeWithPermission));
|
||||||
|
|
||||||
component.data.showLocalUploadButton = true;
|
component.data.showLocalUploadButton = true;
|
||||||
@ -100,7 +103,6 @@ describe('ContentNodeSelectorComponent', () => {
|
|||||||
|
|
||||||
afterEach(() => {
|
afterEach(() => {
|
||||||
fixture.destroy();
|
fixture.destroy();
|
||||||
TestBed.resetTestingModule();
|
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('Data injecting with the "Material dialog way"', () => {
|
describe('Data injecting with the "Material dialog way"', () => {
|
||||||
|
@ -501,7 +501,9 @@ export class DocumentListComponent implements OnInit, OnChanges, OnDestroy, Afte
|
|||||||
this.ngZone.run(() => {
|
this.ngZone.run(() => {
|
||||||
this.resetSelection();
|
this.resetSelection();
|
||||||
if (this.node) {
|
if (this.node) {
|
||||||
this.data.loadPage(this.node, this._pagination.merge, null, this.getPreselectNodesBasedOnSelectionMode());
|
if (this.data) {
|
||||||
|
this.data.loadPage(this.node, this._pagination.merge, null, this.getPreselectNodesBasedOnSelectionMode());
|
||||||
|
}
|
||||||
this.onPreselectNodes();
|
this.onPreselectNodes();
|
||||||
this.syncPagination();
|
this.syncPagination();
|
||||||
this.onDataReady(this.node);
|
this.onDataReady(this.node);
|
||||||
@ -698,7 +700,9 @@ export class DocumentListComponent implements OnInit, OnChanges, OnDestroy, Afte
|
|||||||
|
|
||||||
onPageLoaded(nodePaging: NodePaging) {
|
onPageLoaded(nodePaging: NodePaging) {
|
||||||
if (nodePaging) {
|
if (nodePaging) {
|
||||||
this.data.loadPage(nodePaging, this._pagination.merge, this.allowDropFiles, this.getPreselectNodesBasedOnSelectionMode());
|
if (this.data) {
|
||||||
|
this.data.loadPage(nodePaging, this._pagination.merge, this.allowDropFiles, this.getPreselectNodesBasedOnSelectionMode());
|
||||||
|
}
|
||||||
this.onPreselectNodes();
|
this.onPreselectNodes();
|
||||||
this.setLoadingState(false);
|
this.setLoadingState(false);
|
||||||
this.onDataReady(nodePaging);
|
this.onDataReady(nodePaging);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user