mirror of
https://github.com/Alfresco/alfresco-ng2-components.git
synced 2026-09-09 18:03:21 +00:00
AAE-21047 Get rid of enums (#11643)
* Refactor enums to const objects and update ESLint rules - Converted several TypeScript enums to const objects for better type inference and immutability. - Updated ESLint configuration to disable 'no-redeclare' rule and added new restrictions on schema usage. - Adjusted package-lock.json to mark several dependencies as peer dependencies. * Refactor enums to const objects in site-dropdown and new-version-uploader models - Converted TypeScript enums to const objects for improved type safety and immutability in `sites-dropdown.component.ts` and `new-version-uploader.model.ts`. - Updated related types to reflect the changes in both files. - Enhanced error handling in the `DropdownSitesComponent` by using the `subscribe` method with an object for better readability. * Refactor TypeScript types and improve error handling in component tests - Updated type annotations in `upload.service.ts` and `node-actions.service.ts` for better type safety. - Enhanced error handling in various component tests by using more descriptive error messages in `task-attachment-list.component.spec.ts`, `attach-file-widget-dialog.component.spec.ts`, and `task-form.component.spec.ts`. - Removed unnecessary schemas from test configurations in several component spec files to streamline the testing setup. * Refactor TypeScript enums to const objects for improved type safety - Converted multiple TypeScript enums to const objects across various models, including `AppConfigValues`, `Status`, `ShowHeaderMode`, `WidgetTypeEnum`, and others. - Updated related type definitions to enhance type inference and immutability. - Adjusted ESLint configurations by removing the 'no-redeclare' rule to streamline code quality checks. * Refactor TypeScript types for improved type safety and consistency - Updated type annotations in `document-list.component.ts`, `document-actions.service.ts`, and `node-actions.service.ts` to use `Observable` instead of `Subject` for better reactive programming practices. - Enhanced type definitions in `search-date-range.component.ts` and related spec files to allow `inLastValue` to be either a string or a number, improving flexibility in handling date range inputs. - Adjusted test cases to reflect these type changes, ensuring consistency across the application. * Enhance type safety in ViewerComponent by specifying type for closeButtonPosition - Updated the type annotation for `closeButtonPosition` in `viewer.component.ts` to explicitly define it as `CloseButtonPosition`, improving type safety and clarity. * Enhance type safety in DataTableComponent by specifying type for showHeader - Updated the type annotation for `showHeader` in `datatable.component.ts` to explicitly define it as `ShowHeaderMode`, improving type safety and clarity. * Update PDF viewer test to accommodate varying date formats - Modified the test for the annotation popup in `pdf-viewer.component.spec.ts` to check for the presence of date components instead of a specific date format, enhancing test robustness across different locales.
This commit is contained in:
+6
-7
@@ -15,10 +15,10 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import { SimpleChange, Component, CUSTOM_ELEMENTS_SCHEMA } from '@angular/core';
|
||||
import { SimpleChange, Component, DebugElement } from '@angular/core';
|
||||
import { ComponentFixture, TestBed } from '@angular/core/testing';
|
||||
import { By } from '@angular/platform-browser';
|
||||
import { of, throwError } from 'rxjs';
|
||||
import { of, Subscription, throwError } from 'rxjs';
|
||||
import { TaskAttachmentListComponent } from './task-attachment-list.component';
|
||||
import { mockEmittedTaskAttachments, mockTaskAttachments } from '../../testing/mock/task/task-attachments.mock';
|
||||
import { ProcessContentService } from '../../form/services/process-content.service';
|
||||
@@ -34,7 +34,7 @@ describe('TaskAttachmentList', () => {
|
||||
let deleteContentSpy: jasmine.Spy;
|
||||
let getFileRawContentSpy: jasmine.Spy;
|
||||
let getContentPreviewSpy: jasmine.Spy;
|
||||
let disposableSuccess: any;
|
||||
let disposableSuccess: Subscription;
|
||||
let loader: HarnessLoader;
|
||||
|
||||
beforeEach(() => {
|
||||
@@ -76,7 +76,7 @@ describe('TaskAttachmentList', () => {
|
||||
|
||||
it('should emit an error when an error occurs loading attachments', () => {
|
||||
const emitSpy = spyOn(component.error, 'emit');
|
||||
getTaskRelatedContentSpy.and.returnValue(throwError({}));
|
||||
getTaskRelatedContentSpy.and.returnValue(throwError(() => new Error('Error loading attachments')));
|
||||
const change = new SimpleChange(null, '123', true);
|
||||
component.ngOnChanges({ taskId: change });
|
||||
expect(emitSpy).toHaveBeenCalled();
|
||||
@@ -296,8 +296,7 @@ describe('Custom CustomEmptyTemplateComponent', () => {
|
||||
|
||||
beforeEach(() => {
|
||||
TestBed.configureTestingModule({
|
||||
declarations: [CustomEmptyTemplateComponent],
|
||||
schemas: [CUSTOM_ELEMENTS_SCHEMA]
|
||||
declarations: [CustomEmptyTemplateComponent]
|
||||
});
|
||||
fixture = TestBed.createComponent(CustomEmptyTemplateComponent);
|
||||
fixture.detectChanges();
|
||||
@@ -311,7 +310,7 @@ describe('Custom CustomEmptyTemplateComponent', () => {
|
||||
fixture.detectChanges();
|
||||
await fixture.whenStable();
|
||||
|
||||
const title: any = fixture.debugElement.queryAll(By.css('[adf-empty-list-header]'));
|
||||
const title: DebugElement[] = fixture.debugElement.queryAll(By.css('[adf-empty-list-header]'));
|
||||
expect(title.length).toBe(1);
|
||||
expect(title[0].nativeElement.innerText).toBe('Custom header');
|
||||
});
|
||||
|
||||
+3
-4
@@ -18,7 +18,7 @@
|
||||
import { ComponentFixture, TestBed } from '@angular/core/testing';
|
||||
import { MAT_DIALOG_DATA, MatDialogRef } from '@angular/material/dialog';
|
||||
import { ContentNodeSelectorPanelComponent, DocumentListService, SitesService, NodesApiService } from '@alfresco/adf-content-services';
|
||||
import { EventEmitter, NO_ERRORS_SCHEMA } from '@angular/core';
|
||||
import { EventEmitter } from '@angular/core';
|
||||
import { AttachFileWidgetDialogComponent } from './attach-file-widget-dialog.component';
|
||||
import { AuthenticationService, NoopAuthModule } from '@alfresco/adf-core';
|
||||
import { AttachFileWidgetDialogComponentData } from './attach-file-widget-dialog-component.interface';
|
||||
@@ -53,8 +53,7 @@ describe('AttachFileWidgetDialogComponent', () => {
|
||||
providers: [
|
||||
{ provide: MAT_DIALOG_DATA, useValue: data },
|
||||
{ provide: MatDialogRef, useValue: { close: () => of() } }
|
||||
],
|
||||
schemas: [NO_ERRORS_SCHEMA]
|
||||
]
|
||||
});
|
||||
fixture = TestBed.createComponent(AttachFileWidgetDialogComponent);
|
||||
widget = fixture.componentInstance;
|
||||
@@ -71,7 +70,7 @@ describe('AttachFileWidgetDialogComponent', () => {
|
||||
authService.onLogin = new Subject<any>();
|
||||
|
||||
spyOn(documentListService, 'getFolderNode').and.returnValue(of({ entry: { path: { elements: [] } } } as NodeEntry));
|
||||
spyOn(documentListService, 'getFolder').and.returnValue(throwError('No results for test'));
|
||||
spyOn(documentListService, 'getFolder').and.returnValue(throwError(() => new Error('No results for test')));
|
||||
spyOn(nodeService, 'getNode').and.returnValue(
|
||||
of(new Node({ id: 'fake-node', path: { elements: [{ nodeType: 'st:site', name: 'fake-site' }] } }))
|
||||
);
|
||||
|
||||
@@ -18,7 +18,6 @@
|
||||
import { FileViewerWidgetComponent } from './file-viewer.widget';
|
||||
import { ComponentFixture, TestBed } from '@angular/core/testing';
|
||||
import { FormModel, FormService, FormFieldModel, RedirectAuthService } from '@alfresco/adf-core';
|
||||
import { CUSTOM_ELEMENTS_SCHEMA } from '@angular/core';
|
||||
import { EMPTY, of } from 'rxjs';
|
||||
|
||||
describe('FileViewerWidgetComponent', () => {
|
||||
@@ -48,8 +47,7 @@ describe('FileViewerWidgetComponent', () => {
|
||||
providers: [
|
||||
{ provide: FormService, useValue: formServiceStub },
|
||||
{ provide: RedirectAuthService, useValue: { onLogin: EMPTY, onTokenReceived: of() } }
|
||||
],
|
||||
schemas: [CUSTOM_ELEMENTS_SCHEMA]
|
||||
]
|
||||
});
|
||||
|
||||
formServiceStub = TestBed.inject(FormService);
|
||||
|
||||
+2
-3
@@ -15,7 +15,7 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import { NO_ERRORS_SCHEMA, SimpleChange } from '@angular/core';
|
||||
import { SimpleChange } from '@angular/core';
|
||||
import { ComponentFixture, TestBed } from '@angular/core/testing';
|
||||
import { By } from '@angular/platform-browser';
|
||||
import { of } from 'rxjs';
|
||||
@@ -39,8 +39,7 @@ describe('ProcessInstanceDetailsComponent', () => {
|
||||
beforeEach(() => {
|
||||
TestBed.configureTestingModule({
|
||||
imports: [ProcessInstanceDetailsComponent],
|
||||
providers: [{ provide: AlfrescoApiService, useClass: AlfrescoApiServiceMock }],
|
||||
schemas: [NO_ERRORS_SCHEMA]
|
||||
providers: [{ provide: AlfrescoApiService, useClass: AlfrescoApiServiceMock }]
|
||||
});
|
||||
fixture = TestBed.createComponent(ProcessInstanceDetailsComponent);
|
||||
component = fixture.componentInstance;
|
||||
|
||||
+8
-8
@@ -20,7 +20,7 @@ import { ComponentFixture, TestBed } from '@angular/core/testing';
|
||||
import { TaskFormComponent } from './task-form.component';
|
||||
import { FormModel, FormOutcomeEvent, FormOutcomeModel } from '@alfresco/adf-core';
|
||||
import { TaskListService } from '../../services/tasklist.service';
|
||||
import { NO_ERRORS_SCHEMA, SimpleChange } from '@angular/core';
|
||||
import { SimpleChange } from '@angular/core';
|
||||
import { of, throwError } from 'rxjs';
|
||||
import {
|
||||
claimableTaskDetailsMock,
|
||||
@@ -45,7 +45,7 @@ import { By } from '@angular/platform-browser';
|
||||
import { TaskFormService } from '../../../form/services/task-form.service';
|
||||
import { TaskService } from '../../../form/services/task.service';
|
||||
import { PeopleProcessService } from '../../../services/people-process.service';
|
||||
import { TaskRepresentation } from '@alfresco/js-api';
|
||||
import { TaskRepresentation, UserRepresentation } from '@alfresco/js-api';
|
||||
|
||||
describe('TaskFormComponent', () => {
|
||||
let component: TaskFormComponent;
|
||||
@@ -61,7 +61,7 @@ describe('TaskFormComponent', () => {
|
||||
|
||||
beforeEach(() => {
|
||||
TestBed.configureTestingModule({
|
||||
schemas: [NO_ERRORS_SCHEMA]
|
||||
imports: [TaskFormComponent]
|
||||
});
|
||||
fixture = TestBed.createComponent(TaskFormComponent);
|
||||
component = fixture.componentInstance;
|
||||
@@ -77,7 +77,7 @@ describe('TaskFormComponent', () => {
|
||||
taskDetailsMock.processDefinitionId = null;
|
||||
spyOn(taskService, 'getTask').and.returnValue(of(taskDetailsMock));
|
||||
peopleProcessService = TestBed.inject(PeopleProcessService);
|
||||
getBpmLoggedUserSpy = spyOn(peopleProcessService, 'getCurrentUserInfo').and.returnValue(of(fakeUser as any));
|
||||
getBpmLoggedUserSpy = spyOn(peopleProcessService, 'getCurrentUserInfo').and.returnValue(of(fakeUser as UserRepresentation));
|
||||
});
|
||||
|
||||
afterEach(async () => {
|
||||
@@ -754,12 +754,12 @@ describe('TaskFormComponent', () => {
|
||||
|
||||
it('should emit error event in case claim task api fails', (done) => {
|
||||
const mockError = { message: 'Api Failed' };
|
||||
spyOn(taskListService, 'claimTask').and.returnValue(throwError(mockError));
|
||||
spyOn(taskListService, 'claimTask').and.returnValue(throwError(() => mockError));
|
||||
getTaskDetailsSpy.and.returnValue(of(claimableTaskDetailsMock));
|
||||
|
||||
component.taskId = 'mock-task-id';
|
||||
|
||||
component.error.subscribe((error) => {
|
||||
component.error.subscribe((error: unknown) => {
|
||||
expect(error).toEqual(mockError);
|
||||
done();
|
||||
});
|
||||
@@ -792,13 +792,13 @@ describe('TaskFormComponent', () => {
|
||||
|
||||
it('should emit error event in case unclaim task api fails', (done) => {
|
||||
const mockError = { message: 'Api Failed' };
|
||||
spyOn(taskListService, 'unclaimTask').and.returnValue(throwError(mockError));
|
||||
spyOn(taskListService, 'unclaimTask').and.returnValue(throwError(() => mockError));
|
||||
getBpmLoggedUserSpy.and.returnValue(of(claimedTaskDetailsMock.assignee));
|
||||
getTaskDetailsSpy.and.returnValue(of(claimedTaskDetailsMock));
|
||||
|
||||
component.taskId = 'mock-task-id';
|
||||
|
||||
component.error.subscribe((error: any) => {
|
||||
component.error.subscribe((error: unknown) => {
|
||||
expect(error).toEqual(mockError);
|
||||
done();
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user