Skip to content

Commit

Permalink
AAE-20808 Making FeaturesService optional
Browse files Browse the repository at this point in the history
  • Loading branch information
ehsan-2019 committed Dec 3, 2024
1 parent c69cd16 commit cf5d765
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 47 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ import {
import { ProcessFilterCloudModel } from '../models/process-filter-cloud.model';
import { IdentityUserService } from '../../../people/services/identity-user.service';
import { NotificationCloudService } from '../../../services/notification-cloud.service';
import { provideMockFeatureFlags } from '@alfresco/adf-core/feature-flags';

describe('ProcessFilterCloudService', () => {
let service: ProcessFilterCloudService;
Expand All @@ -53,10 +52,7 @@ describe('ProcessFilterCloudService', () => {
beforeEach(() => {
TestBed.configureTestingModule({
imports: [ProcessServiceCloudTestingModule],
providers: [
{ provide: PROCESS_FILTERS_SERVICE_TOKEN, useClass: LocalPreferenceCloudService },
provideMockFeatureFlags({ ['studio-ws-graphql-subprotocol']: false })
]
providers: [{ provide: PROCESS_FILTERS_SERVICE_TOKEN, useClass: LocalPreferenceCloudService }]
});
service = TestBed.inject(ProcessFilterCloudService);

Expand All @@ -72,7 +68,7 @@ describe('ProcessFilterCloudService', () => {
});

it('should create processfilter key by using appName and the username', (done) => {
service.getProcessFilters('mock-appName').subscribe((res: ProcessFilterCloudModel[]) => {
service.getProcessFilters('mock-appName').subscribe((res: any) => {
expect(res).toBeDefined();
expect(getCurrentUserInfoSpy).toHaveBeenCalled();
done();
Expand Down Expand Up @@ -141,7 +137,7 @@ describe('ProcessFilterCloudService', () => {
it('should create the process filters in case the filters are not exist in the user preferences', (done) => {
getPreferencesSpy.and.returnValue(of(fakeProcessCloudFilterWithDifferentEntries));

service.getProcessFilters('mock-appName').subscribe((res: ProcessFilterCloudModel[]) => {
service.getProcessFilters('mock-appName').subscribe((res: any) => {
expect(res).toBeDefined();
expect(res).not.toBeNull();
expect(res.length).toBe(3);
Expand Down Expand Up @@ -247,7 +243,6 @@ describe('ProcessFilterCloudService', () => {
it('should reset filters to default values', async () => {
const changedFilter = new ProcessFilterCloudModel(fakeProcessCloudFilters[0]);
changedFilter.processDefinitionKey = 'modifiedProcessDefinitionKey';
// eslint-disable-next-line @typescript-eslint/no-explicit-any
spyOn<any>(service, 'defaultProcessFilters').and.returnValue(fakeProcessCloudFilters);

await service.resetProcessFilterToDefaults('mock-appName', changedFilter).toPromise();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
*/

import { createClient } from 'graphql-ws';
import { Inject, Injectable } from '@angular/core';
import { Inject, Injectable, Optional } from '@angular/core';
import { GraphQLWsLink } from '@apollo/client/link/subscriptions';
import { WebSocketLink } from '@apollo/client/link/ws';
import {
Expand Down Expand Up @@ -61,7 +61,7 @@ export class WebSocketService {
private readonly apollo: Apollo,
private readonly appConfigService: AppConfigService,
private readonly authService: AuthenticationService,
@Inject(FeaturesServiceToken) private featuresService: IFeaturesService
@Optional() @Inject(FeaturesServiceToken) private featuresService: IFeaturesService
) {
this.host = this.appConfigService.get('bpmHost', '');
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ import { TestbedHarnessEnvironment } from '@angular/cdk/testing/testbed';
import { MatExpansionPanelHarness } from '@angular/material/expansion/testing';
import { MatSelectHarness } from '@angular/material/select/testing';
import { MatProgressSpinnerHarness } from '@angular/material/progress-spinner/testing';
import { provideMockFeatureFlags } from '@alfresco/adf-core/feature-flags';

describe('EditServiceTaskFilterCloudComponent', () => {
let loader: HarnessLoader;
Expand All @@ -51,25 +50,22 @@ describe('EditServiceTaskFilterCloudComponent', () => {
let getTaskFilterSpy: jasmine.Spy;
let getDeployedApplicationsSpy: jasmine.Spy;
let taskService: TaskCloudService;
const afterClosedSubject = new Subject<unknown>();
const afterClosedSubject = new Subject<any>();

beforeEach(() => {
TestBed.configureTestingModule({
imports: [ProcessServiceCloudTestingModule, TaskFiltersCloudModule, MatIconTestingModule],
providers: [
MatDialog,
{ provide: TASK_FILTERS_SERVICE_TOKEN, useClass: LocalPreferenceCloudService },
provideMockFeatureFlags({ ['studio-ws-graphql-subprotocol']: false })
]
providers: [MatDialog, { provide: TASK_FILTERS_SERVICE_TOKEN, useClass: LocalPreferenceCloudService }]
});
fixture = TestBed.createComponent(EditServiceTaskFilterCloudComponent);
component = fixture.componentInstance;
service = TestBed.inject(ServiceTaskFilterCloudService);
appsService = TestBed.inject(AppsProcessCloudService);
taskService = TestBed.inject(TaskCloudService);
dialog = TestBed.inject(MatDialog);
const dialogRefMock = jasmine.createSpyObj('MatDialogRef', ['afterClosed']);
dialogRefMock.afterClosed.and.returnValue(afterClosedSubject);
const dialogRefMock: any = {
afterClosed: () => afterClosedSubject
};
spyOn(dialog, 'open').and.returnValue(dialogRefMock);
getTaskFilterSpy = spyOn(service, 'getTaskFilterById').and.returnValue(of(fakeServiceFilter));
getDeployedApplicationsSpy = spyOn(appsService, 'getDeployedApplicationsByStatus').and.returnValue(of(fakeApplicationInstance));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,6 @@ import { TestbedHarnessEnvironment } from '@angular/cdk/testing/testbed';
import { MatSelectHarness } from '@angular/material/select/testing';
import { MatExpansionPanelHarness } from '@angular/material/expansion/testing';
import { MatProgressSpinnerHarness } from '@angular/material/progress-spinner/testing';
import { provideMockFeatureFlags } from '@alfresco/adf-core/feature-flags';

describe('EditTaskFilterCloudComponent', () => {
let loader: HarnessLoader;
Expand All @@ -71,16 +70,12 @@ describe('EditTaskFilterCloudComponent', () => {
let getTaskFilterSpy: jasmine.Spy;
let getDeployedApplicationsSpy: jasmine.Spy;
let taskService: TaskCloudService;
const afterClosedSubject = new Subject<unknown>();
const afterClosedSubject = new Subject<any>();

beforeEach(() => {
TestBed.configureTestingModule({
imports: [ProcessServiceCloudTestingModule, TaskFiltersCloudModule, PeopleCloudModule, MatIconTestingModule],
providers: [
MatDialog,
{ provide: TASK_FILTERS_SERVICE_TOKEN, useClass: LocalPreferenceCloudService },
provideMockFeatureFlags({ ['studio-ws-graphql-subprotocol']: false })
]
providers: [MatDialog, { provide: TASK_FILTERS_SERVICE_TOKEN, useClass: LocalPreferenceCloudService }]
});
fixture = TestBed.createComponent(EditTaskFilterCloudComponent);
component = fixture.componentInstance;
Expand All @@ -90,8 +85,9 @@ describe('EditTaskFilterCloudComponent', () => {
taskService = TestBed.inject(TaskCloudService);
alfrescoApiService = TestBed.inject(AlfrescoApiService);
dialog = TestBed.inject(MatDialog);
const dialogRefMock = jasmine.createSpyObj('MatDialogRef', ['afterClosed']);
dialogRefMock.afterClosed.and.returnValue(afterClosedSubject);
const dialogRefMock: any = {
afterClosed: () => afterClosedSubject
};
spyOn(dialog, 'open').and.returnValue(dialogRefMock);
spyOn(alfrescoApiService, 'getInstance').and.returnValue(mockAlfrescoApi);
getTaskFilterSpy = spyOn(service, 'getTaskFilterById').and.returnValue(of(fakeFilter));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
*/

import { AppConfigService } from '@alfresco/adf-core';
import { DebugElement, SimpleChange } from '@angular/core';
import { SimpleChange } from '@angular/core';
import { ComponentFixture, TestBed, fakeAsync } from '@angular/core/testing';
import { By } from '@angular/platform-browser';
import { first, of, throwError } from 'rxjs';
Expand All @@ -32,7 +32,6 @@ import { HarnessLoader } from '@angular/cdk/testing';
import { MatActionListItemHarness } from '@angular/material/list/testing';
import { TestbedHarnessEnvironment } from '@angular/cdk/testing/testbed';
import { TaskFilterCloudAdapter } from '../../../models/filter-cloud-model';
import { provideMockFeatureFlags } from '@alfresco/adf-core/feature-flags';

describe('TaskFiltersCloudComponent', () => {
let loader: HarnessLoader;
Expand All @@ -46,14 +45,10 @@ describe('TaskFiltersCloudComponent', () => {
let getTaskListFiltersSpy: jasmine.Spy;
let getTaskListCounterSpy: jasmine.Spy;

const configureTestingModule = (providers: unknown[]) => {
const configureTestingModule = (providers: any[]) => {
TestBed.configureTestingModule({
imports: [ProcessServiceCloudTestingModule, TaskFiltersCloudModule],
providers: [
{ provide: TASK_FILTERS_SERVICE_TOKEN, useClass: LocalPreferenceCloudService },
provideMockFeatureFlags({ ['studio-ws-graphql-subprotocol']: false }),
...providers
]
providers: [{ provide: TASK_FILTERS_SERVICE_TOKEN, useClass: LocalPreferenceCloudService }, ...providers]
});
taskFilterService = TestBed.inject(TaskFilterCloudService);
taskListService = TestBed.inject(TaskListCloudService);
Expand Down Expand Up @@ -107,7 +102,7 @@ describe('TaskFiltersCloudComponent', () => {
fixture.detectChanges();
await fixture.whenStable();

const filters: DebugElement[] = fixture.debugElement.queryAll(By.css('.adf-icon'));
const filters: any = fixture.debugElement.queryAll(By.css('.adf-icon'));
expect(filters.length).toBe(0);
});

Expand Down Expand Up @@ -270,7 +265,7 @@ describe('TaskFiltersCloudComponent', () => {
component.showIcons = false;
fixture.detectChanges();

const filters: DebugElement[] = fixture.debugElement.queryAll(By.css('.adf-icon'));
const filters: any = fixture.debugElement.queryAll(By.css('.adf-icon'));

expect(filters.length).toBe(0);
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ import { IdentityUserService } from '../../../people/services/identity-user.serv
import { ApolloModule } from 'apollo-angular';
import { StorageService } from '@alfresco/adf-core';
import { TaskStatusFilter } from '../public-api';
import { provideMockFeatureFlags } from '@alfresco/adf-core/feature-flags';

describe('TaskFilterCloudService', () => {
let service: TaskFilterCloudService;
Expand All @@ -58,10 +57,7 @@ describe('TaskFilterCloudService', () => {
beforeEach(() => {
TestBed.configureTestingModule({
imports: [HttpClientTestingModule, ProcessServiceCloudTestingModule, ApolloModule],
providers: [
{ provide: TASK_FILTERS_SERVICE_TOKEN, useClass: UserPreferenceCloudService },
provideMockFeatureFlags({ ['studio-ws-graphql-subprotocol']: false })
]
providers: [{ provide: TASK_FILTERS_SERVICE_TOKEN, useClass: UserPreferenceCloudService }]
});
service = TestBed.inject(TaskFilterCloudService);
notificationCloudService = TestBed.inject(NotificationCloudService);
Expand Down Expand Up @@ -270,10 +266,7 @@ describe('Inject [LocalPreferenceCloudService] into the TaskFilterCloudService',
beforeEach(() => {
TestBed.configureTestingModule({
imports: [HttpClientTestingModule, ProcessServiceCloudTestingModule, ApolloModule],
providers: [
{ provide: TASK_FILTERS_SERVICE_TOKEN, useClass: LocalPreferenceCloudService },
provideMockFeatureFlags({ ['studio-ws-graphql-subprotocol']: false })
]
providers: [{ provide: TASK_FILTERS_SERVICE_TOKEN, useClass: LocalPreferenceCloudService }]
});
service = TestBed.inject(TaskFilterCloudService);
preferenceCloudService = service.preferenceService;
Expand Down

0 comments on commit cf5d765

Please sign in to comment.