Skip to content

Commit

Permalink
[ACS-7679] Reduce the usage of AppConfigService in components and tes…
Browse files Browse the repository at this point in the history
…ts (#9563)

* remove unused app config setting

* remove unused app config setting

* remove unnecessary app config service reference

* remove unnecessary app config service reference

* remove unnecessary app config service reference

* remove unnecessary app config service reference

* remove unnecessary app config service reference

* support input params for the viewer; optional configuration

* remove useless imports [ci:force]

* fix imports [ci:force]
  • Loading branch information
DenysVuika authored Apr 18, 2024
1 parent 99ae729 commit 4132517
Show file tree
Hide file tree
Showing 12 changed files with 50 additions and 127 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,12 @@

import { TestBed, fakeAsync, tick } from '@angular/core/testing';
import { NodeEntry, Node, SitePaging, Site } from '@alfresco/js-api';
import { AppConfigService } from '@alfresco/adf-core';
import { DocumentListService } from '../document-list/services/document-list.service';
import { DocumentListService, NodeAction } from '../document-list';
import { ContentNodeDialogService } from './content-node-dialog.service';
import { MatDialog } from '@angular/material/dialog';
import { Subject, of } from 'rxjs';
import { ContentTestingModule } from '../testing/content.testing.module';
import { NodeAction } from '../document-list/models/node-action.enum';
import { SitesService } from '../common/services/sites.service';
import { SitesService } from '../common';

const fakeNodeEntry = {
entry: {
Expand Down Expand Up @@ -71,9 +69,6 @@ describe('ContentNodeDialogService', () => {
TestBed.configureTestingModule({
imports: [ContentTestingModule]
});
const appConfig: AppConfigService = TestBed.inject(AppConfigService);
appConfig.config.ecmHost = 'http://localhost:9876/ecm';

service = TestBed.inject(ContentNodeDialogService);
documentListService = TestBed.inject(DocumentListService);
materialDialog = TestBed.inject(MatDialog);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,8 @@ import { CUSTOM_ELEMENTS_SCHEMA } from '@angular/core';
import { ComponentFixture, fakeAsync, TestBed, tick } from '@angular/core/testing';
import { By } from '@angular/platform-browser';
import { Node, NodeEntry, NodePaging, ResultSetPaging, Site, SiteEntry, SitePaging, SitePagingList, UserInfo } from '@alfresco/js-api';
import { AppConfigService, DataRow, ThumbnailService, DataColumn } from '@alfresco/adf-core';
import { ContentService } from '../common/services/content.service';
import { UploadService } from '../common/services/upload.service';
import { NodesApiService } from '../common/services/nodes-api.service';
import { FileModel, FileUploadStatus } from '../common/models/file.model';
import { FileUploadCompleteEvent } from '../common/events/file.event';
import { DataRow, ThumbnailService, DataColumn } from '@alfresco/adf-core';
import { ContentService, UploadService, NodesApiService, SitesService, FileModel, FileUploadStatus, FileUploadCompleteEvent } from '../common';
import { of, throwError } from 'rxjs';
import { DropdownBreadcrumbComponent } from '../breadcrumb';
import { ContentNodeSelectorPanelComponent } from './content-node-selector-panel.component';
Expand All @@ -35,7 +31,6 @@ import { NodeEntryEvent, ShareDataRow, ShareDataTableAdapter } from '../document
import { SearchQueryBuilderService } from '../search';
import { ContentNodeSelectorPanelService } from './content-node-selector-panel.service';
import { mockContentModelTextProperty } from '../mock/content-model.mock';
import { SitesService } from '../common/services/sites.service';

const fakeResultSetPaging: ResultSetPaging = {
list: {
Expand Down Expand Up @@ -732,32 +727,6 @@ describe('ContentNodeSelectorPanelComponent', () => {
});
});

describe('Sorting', () => {
let appConfigService: AppConfigService;

beforeEach(() => {
appConfigService = TestBed.inject(AppConfigService);
});

it('should read the sorting value from appConfig json in case it is present', async () => {
const fakeSortingConfig = ['fakeKey', 'fakeAsc'];

appConfigService.config = Object.assign(appConfigService.config, {
'adf-content-node-selector': { sorting: fakeSortingConfig }
});
fixture.detectChanges();

expect(component.sorting).toEqual(fakeSortingConfig);
});

it('should take default sorting when there is no content node selector sorting config in appConfig json', async () => {
appConfigService.config = null;
fixture.detectChanges();

expect(component.sorting).toEqual(['createdAt', 'desc']);
});
});

describe('Selected nodes counter', () => {
it('should getSelectedCount return 0 by default', () => {
expect(component.getSelectedCount()).toBe(0);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,26 +22,22 @@ import {
UserPreferenceValues,
InfinitePaginationComponent,
PaginatedComponent,
AppConfigService,
DataSorting,
ShowHeaderMode
} from '@alfresco/adf-core';
import { NodesApiService } from '../common/services/nodes-api.service';
import { UploadService } from '../common/services/upload.service';
import { FileUploadCompleteEvent, FileUploadDeleteEvent } from '../common/events/file.event';
import { NodesApiService, UploadService, FileUploadCompleteEvent, FileUploadDeleteEvent, SitesService } from '../common';
import { UntypedFormControl } from '@angular/forms';
import { Node, NodePaging, Pagination, SiteEntry, SitePaging, NodeEntry, SearchRequest, RequestScope } from '@alfresco/js-api';
import { DocumentListComponent } from '../document-list/components/document-list.component';
import { RowFilter } from '../document-list/data/row-filter.model';
import { ImageResolver } from '../document-list/data/image-resolver.model';
import { debounceTime, takeUntil } from 'rxjs/operators';
import { CustomResourcesService } from '../document-list/services/custom-resources.service';
import { ShareDataRow } from '../document-list/data/share-data-row.model';
import { NodeEntryEvent } from '../document-list/components/node.event';
import { debounceTime, takeUntil } from 'rxjs/operators';
import { Subject } from 'rxjs';
import { SearchQueryBuilderService } from '../search/services/search-query-builder.service';
import { SearchQueryBuilderService } from '../search';
import { ContentNodeSelectorPanelService } from './content-node-selector-panel.service';
import { NodeEntryEvent } from '../document-list/components/node.event';
import { SitesService } from '../common/services/sites.service';

export type ValidationFunction = (entry: Node) => boolean;

Expand Down Expand Up @@ -262,7 +258,7 @@ export class ContentNodeSelectorPanelComponent implements OnInit, OnDestroy {
preselectedNodes: NodeEntry[] = [];
currentUploadBatch: NodeEntry[] = [];

sorting: string[] | DataSorting;
sorting: string[] | DataSorting = ['createdAt', 'desc'];

searchPanelExpanded: boolean = false;

Expand All @@ -275,7 +271,6 @@ export class ContentNodeSelectorPanelComponent implements OnInit, OnDestroy {
private nodesApiService: NodesApiService,
private uploadService: UploadService,
private sitesService: SitesService,
private appConfigService: AppConfigService,
private contentNodeSelectorPanelService: ContentNodeSelectorPanelService
) {}

Expand Down Expand Up @@ -347,8 +342,6 @@ export class ContentNodeSelectorPanelComponent implements OnInit, OnDestroy {
this.documentList.$folderNode.pipe(takeUntil(this.onDestroy$)).subscribe((currentNode: Node) => {
this.currentFolder.emit(currentNode);
});

this.sorting = this.appConfigService.get('adf-content-node-selector.sorting', ['createdAt', 'desc']);
}

ngOnDestroy() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,8 @@
import { TestBed, ComponentFixture } from '@angular/core/testing';
import { MatDialogRef, MAT_DIALOG_DATA, MatDialog } from '@angular/material/dialog';
import { of } from 'rxjs';
import { NotificationService, AppConfigService } from '@alfresco/adf-core';
import { NodesApiService } from '../common/services/nodes-api.service';
import { RenditionService } from '../common/services/rendition.service';
import { NotificationService } from '@alfresco/adf-core';
import { NodesApiService, RenditionService } from '../common';
import { SharedLinksApiService } from './services/shared-links-api.service';
import { ShareDialogComponent } from './content-node-share.dialog';
import { ContentTestingModule } from '../testing/content.testing.module';
Expand All @@ -43,7 +42,6 @@ describe('ShareDialogComponent', () => {
let nodesApiService: NodesApiService;
let fixture: ComponentFixture<ShareDialogComponent>;
let component: ShareDialogComponent;
let appConfigService: AppConfigService;

const shareToggleId = '[data-automation-id="adf-share-toggle"]';
const expireToggle = '[data-automation-id="adf-expire-toggle"]';
Expand Down Expand Up @@ -77,7 +75,6 @@ describe('ShareDialogComponent', () => {
sharedLinksApiService = TestBed.inject(SharedLinksApiService);
renditionService = TestBed.inject(RenditionService);
nodesApiService = TestBed.inject(NodesApiService);
appConfigService = TestBed.inject(AppConfigService);

node = {
entry: {
Expand Down Expand Up @@ -330,10 +327,7 @@ describe('ShareDialogComponent', () => {
});

it('should update node with input date and end of day time when type is `date`', async () => {
const dateTimePickerType = 'date';
const date = new Date('2525-01-01');
spyOn(appConfigService, 'get').and.callFake(() => dateTimePickerType as any);

fixture.detectChanges();

const toggle = await loader.getHarness(MatSlideToggleHarness.with({ selector: expireToggle }));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,38 +15,16 @@
* limitations under the License.
*/

import { NgModule, ModuleWithProviders } from '@angular/core';
import { NgModule } from '@angular/core';
import { CommonModule } from '@angular/common';
import { CoreModule } from '@alfresco/adf-core';
import { MaterialModule } from '../material.module';
import { ShareDialogComponent } from './content-node-share.dialog';
import { NodeSharedDirective } from './content-node-share.directive';

@NgModule({
imports: [
CoreModule,
CommonModule,
MaterialModule
],
declarations: [
ShareDialogComponent,
NodeSharedDirective
],
exports: [
ShareDialogComponent,
NodeSharedDirective
]
imports: [CoreModule, CommonModule, MaterialModule],
declarations: [ShareDialogComponent, NodeSharedDirective],
exports: [ShareDialogComponent, NodeSharedDirective]
})
export class ContentNodeShareModule {
static forRoot(): ModuleWithProviders<ContentNodeShareModule> {
return {
ngModule: ContentNodeShareModule
};
}

static forChild(): ModuleWithProviders<ContentNodeShareModule> {
return {
ngModule: ContentNodeShareModule
};
}
}
export class ContentNodeShareModule {}
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,8 @@ import {
DataRow,
DataTableService,
DataTableSchema,
DataColumn
DataColumn,
ViewerComponentConfig
} from '@alfresco/adf-core';
import { NodesApiService } from '../../common/services/nodes-api.service';
import { Node, NodeEntry, NodePaging, NodesApi, Pagination } from '@alfresco/js-api';
Expand Down Expand Up @@ -789,9 +790,10 @@ export class DocumentListComponent extends DataTableSchema implements OnInit, On
onPreviewFile(node: NodeEntry) {
if (node) {
const sizeInMB = node.entry?.content?.sizeInBytes / BYTES_TO_MB_CONVERSION_VALUE;
const config = this.appConfig.get<ViewerComponentConfig>('viewer');

const fileAutoDownloadFlag: boolean = this.appConfig.get('viewer.enableFileAutoDownload', true);
const sizeThreshold: number = this.appConfig.get('viewer.fileAutoDownloadSizeThresholdInMB', 15);
const fileAutoDownloadFlag = config?.enableFileAutoDownload ?? true;
const sizeThreshold = config?.fileAutoDownloadSizeThresholdInMB ?? 15;

if (fileAutoDownloadFlag && sizeInMB && sizeInMB > sizeThreshold) {
this.dialog.open(FileAutoDownloadComponent, { disableClose: true, data: node });
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
*/

import { TestBed } from '@angular/core/testing';
import { AppConfigService } from '@alfresco/adf-core';
import { Observable } from 'rxjs';
import { FileNode, FolderNode } from '../../mock';
import { ContentActionHandler } from '../models/content-action.model';
Expand All @@ -33,9 +32,6 @@ describe('FolderActionsService', () => {
TestBed.configureTestingModule({
imports: [ContentTestingModule]
});
const appConfig: AppConfigService = TestBed.inject(AppConfigService);
appConfig.config.ecmHost = 'http://localhost:9876/ecm';

documentListService = TestBed.inject(DocumentListService);
service = TestBed.inject(FolderActionsService);
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@

import { fakeAsync, TestBed, tick } from '@angular/core/testing';
import { Node, NodeEntry } from '@alfresco/js-api';
import { AppConfigService } from '@alfresco/adf-core';
import { DocumentListService } from './document-list.service';
import { NodeActionsService } from './node-actions.service';
import { ContentNodeDialogService } from '../../content-node-selector/content-node-dialog.service';
Expand All @@ -43,9 +42,6 @@ describe('NodeActionsService', () => {
imports: [ContentTestingModule],
providers: [{ provide: MatDialogRef, useValue: dialogRef }]
});
const appConfig: AppConfigService = TestBed.inject(AppConfigService);
appConfig.config.ecmHost = 'http://localhost:9876/ecm';

service = TestBed.inject(NodeActionsService);
documentListService = TestBed.inject(DocumentListService);
contentDialogService = TestBed.inject(ContentNodeDialogService);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
*/

import { TestBed } from '@angular/core/testing';
import { AppConfigService } from '@alfresco/adf-core';
import { NodePermissionDialogService } from './node-permission-dialog.service';
import { MatDialog } from '@angular/material/dialog';
import { of, Subject, throwError } from 'rxjs';
Expand All @@ -35,8 +34,6 @@ describe('NodePermissionDialogService', () => {
TestBed.configureTestingModule({
imports: [ContentTestingModule]
});
const appConfig: AppConfigService = TestBed.inject(AppConfigService);
appConfig.config.ecmHost = 'http://localhost:9876/ecm';
service = TestBed.inject(NodePermissionDialogService);
materialDialog = TestBed.inject(MatDialog);
afterOpenObservable = new Subject<any>();
Expand Down
3 changes: 0 additions & 3 deletions lib/content-services/src/lib/tag/tag-list.component.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
*/

import { ComponentFixture, TestBed } from '@angular/core/testing';
import { AppConfigService } from '@alfresco/adf-core';
import { TagService } from './services/tag.service';
import { TagListComponent } from '././tag-list.component';
import { of } from 'rxjs';
Expand Down Expand Up @@ -53,8 +52,6 @@ describe('TagList', () => {
TestBed.configureTestingModule({
imports: [ContentTestingModule]
});
const appConfig: AppConfigService = TestBed.inject(AppConfigService);
appConfig.config.ecmHost = 'http://localhost:9876/ecm';

tagService = TestBed.inject(TagService);
spyOn(tagService, 'getAllTheTags').and.returnValue(of(dataTag));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ import { CoreTestingModule } from '../../../testing/core.testing.module';
import { ClipboardService } from '../../../clipboard/clipboard.service';
import { CardViewDatetimeItemModel } from '../../models/card-view-datetimeitem.model';
import { TranslateModule } from '@ngx-translate/core';
import { AppConfigService } from '../../../app-config/app-config.service';
import { MatDatetimepickerInputEvent } from '@mat-datetimepicker/core';
import { HarnessLoader } from '@angular/cdk/testing';
import { TestbedHarnessEnvironment } from '@angular/cdk/testing/testbed';
Expand All @@ -34,18 +33,11 @@ describe('CardViewDateItemComponent', () => {
let loader: HarnessLoader;
let fixture: ComponentFixture<CardViewDateItemComponent>;
let component: CardViewDateItemComponent;
let appConfigService: AppConfigService;

beforeEach(() => {
TestBed.configureTestingModule({
imports: [TranslateModule.forRoot(), CoreTestingModule]
});
appConfigService = TestBed.inject(AppConfigService);
appConfigService.config.dateValues = {
defaultDateFormat: 'shortDate',
defaultDateTimeFormat: 'M/d/yy, h:mm a',
defaultLocale: 'uk'
};

fixture = TestBed.createComponent(CardViewDateItemComponent);
component = fixture.componentInstance;
Expand Down
Loading

0 comments on commit 4132517

Please sign in to comment.