Skip to content

Commit

Permalink
[AAE-5958] Storybook stories for ProcessHeaderCloud component (#7374)
Browse files Browse the repository at this point in the history
* [AAE-5958] added stories and mocks

* [AAE-5958] arefactored mocks

* [AAE-5958] added interface for mock and live process cloud service

* [AAE-5958] added story and mock for header placeholders
  • Loading branch information
tomgny committed Nov 17, 2021
1 parent 3e16ae3 commit 18d57e4
Show file tree
Hide file tree
Showing 8 changed files with 242 additions and 31 deletions.
@@ -0,0 +1,79 @@
/*!
* @license
* Copyright 2019 Alfresco Software, Ltd.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

import { LogService } from '@alfresco/adf-core';
import { Injectable } from '@angular/core';
import { Observable, of, Subject, throwError } from 'rxjs';
import { ProcessInstanceCloud } from '../start-process/models/process-instance-cloud.model';
import { ProcessDefinitionCloud } from '../../models/process-definition-cloud.model';
import { ApplicationVersionModel } from '../../models/application-version.model';
import { processInstancePlaceholdersCloudMock, processInstanceDetailsCloudMock } from './process-instance-details-cloud.mock';
import { fakeProcessDefinitions } from '../start-process/mock/start-process.component.mock';
import { mockAppVersions } from '../process-filters/mock/process-filters-cloud.mock';
import { ProcessCloudInterface } from '../services/process-cloud.interface';

@Injectable({
providedIn: 'root'
})
export class ProcessCloudServiceMock implements ProcessCloudInterface {

dataChangesDetected = new Subject<ProcessInstanceCloud>();

constructor(private logService: LogService) { }

getProcessInstanceById(appName: string, processInstanceId: string): Observable<ProcessInstanceCloud> {
if (appName === 'app-placeholders' && processInstanceId) {
return of(processInstancePlaceholdersCloudMock);
}

if (appName && processInstanceId) {
return of(processInstanceDetailsCloudMock);

} else {
this.logService.error('AppName and ProcessInstanceId are mandatory for querying a process');
return throwError('AppName/ProcessInstanceId not configured');
}
}

getProcessDefinitions(appName: string): Observable<ProcessDefinitionCloud[]> {
if (appName || appName === '') {
return of(fakeProcessDefinitions);

} else {
this.logService.error('AppName is mandatory for querying task');
return throwError('AppName not configured');
}
}

getApplicationVersions(appName: string): Observable<ApplicationVersionModel[]> {
if (appName) {
return of(mockAppVersions);
} else {
this.logService.error('AppName is mandatory for querying the versions of an application');
return throwError('AppName not configured');
}
}

cancelProcess(appName: string, processInstanceId: string): Observable<ProcessInstanceCloud> {
if (appName && processInstanceId) {
return of();
} else {
this.logService.error('App name and Process id are mandatory for deleting a process');
return throwError('App name and process id not configured');
}
}
}
@@ -0,0 +1,42 @@
/*!
* @license
* Copyright 2019 Alfresco Software, Ltd.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

import { ProcessInstanceCloud } from '../start-process/models/process-instance-cloud.model';

export const processInstanceDetailsCloudMock: ProcessInstanceCloud = {
appName: 'app-form-mau',
businessKey: 'MyBusinessKey',
id: '00fcc4ab-4290-11e9-b133-0a586460016a',
initiator: 'devopsuser',
lastModified: new Date(1552152187081),
name: 'new name',
parentId: '00fcc4ab-4290-11e9-b133-0a586460016b',
startDate: new Date(1552152187080),
status: 'RUNNING'
};

export const processInstancePlaceholdersCloudMock: ProcessInstanceCloud = {
appName: 'app-placeholders',
businessKey: '',
id: '00fcc4ab-4290-11e9-b133-0a586460016a',
initiator: 'devopsuser',
lastModified: new Date(1552152187081),
name: '',
parentId: '',
startDate: new Date(1552152187080),
status: 'RUNNING'
};
Expand Up @@ -37,9 +37,9 @@ import { LocalPreferenceCloudService } from '../../../services/local-preference-
import { TranslateModule } from '@ngx-translate/core';
import { ProcessCloudService } from '../../services/process-cloud.service';
import { DateCloudFilterType } from '../../../models/date-cloud-filter.model';
import { ApplicationVersionModel } from '../../../models/application-version.model';
import { MatIconTestingModule } from '@angular/material/icon/testing';
import { ProcessDefinitionCloud } from '../../../models/process-definition-cloud.model';
import { mockAppVersions } from '../mock/process-filters-cloud.mock';

describe('EditProcessFilterCloudComponent', () => {
let component: EditProcessFilterCloudComponent;
Expand Down Expand Up @@ -603,23 +603,8 @@ describe('EditProcessFilterCloudComponent', () => {
});

it('should fetch appVersionMultiple options when appVersionMultiple filter property is set', async () => {
const mockAppVersion1: ApplicationVersionModel = {
entry: {
id: 'mock-version-1-id',
name: 'mock-version-1-name',
version: '1'
}
};

const mockAppVersion2: ApplicationVersionModel = {
entry: {
id: 'mock-version-2-id',
name: 'mock-version-2-name',
version: '2'
}
};

const applicationVersionsSpy = spyOn(processService, 'getApplicationVersions').and.returnValue(of([mockAppVersion1, mockAppVersion2]));
const applicationVersionsSpy = spyOn(processService, 'getApplicationVersions').and.returnValue(of(mockAppVersions));
fixture.detectChanges();

component.filterProperties = ['appVersionMultiple'];
Expand Down
Expand Up @@ -17,6 +17,7 @@

import { ProcessFilterCloudModel } from '../models/process-filter-cloud.model';
import { DateCloudFilterType } from '../../../../..';
import { ApplicationVersionModel } from '../../../models/application-version.model';

export const fakeProcessCloudFilters = [
{
Expand Down Expand Up @@ -167,3 +168,21 @@ export const fakeProcessCloudFilterWithDifferentEntries = {
}
}
};

const mockAppVersion1: ApplicationVersionModel = {
entry: {
id: 'mock-version-1-id',
name: 'mock-version-1-name',
version: '1'
}
};

const mockAppVersion2: ApplicationVersionModel = {
entry: {
id: 'mock-version-2-id',
name: 'mock-version-2-name',
version: '2'
}
};

export const mockAppVersions = [mockAppVersion1, mockAppVersion2];
Expand Up @@ -24,19 +24,7 @@ import { ProcessHeaderCloudComponent } from './process-header-cloud.component';
import { ProcessHeaderCloudModule } from '../process-header-cloud.module';
import { ProcessCloudService } from '../../services/process-cloud.service';
import { TranslateModule } from '@ngx-translate/core';
import { ProcessInstanceCloud } from '../../start-process/models/process-instance-cloud.model';

const processInstanceDetailsCloudMock: ProcessInstanceCloud = {
appName: 'app-form-mau',
businessKey: 'MyBusinessKey',
id: '00fcc4ab-4290-11e9-b133-0a586460016a',
initiator: 'devopsuser',
lastModified: new Date(1552152187081),
name: 'new name',
parentId: '00fcc4ab-4290-11e9-b133-0a586460016b',
startDate: new Date(1552152187080),
status: 'RUNNING'
};
import { processInstanceDetailsCloudMock } from '../../mock/process-instance-details-cloud.mock';

describe('ProcessHeaderCloudComponent', () => {
let component: ProcessHeaderCloudComponent;
Expand Down
@@ -0,0 +1,66 @@
/*!
* @license
* Copyright 2019 Alfresco Software, Ltd.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

import { Meta, moduleMetadata, Story } from '@storybook/angular';
import { ProcessHeaderCloudModule } from '../process-header-cloud.module';
import { ProcessServicesCloudStoryModule } from '../../../testing/process-services-cloud-story.module';
import { ProcessHeaderCloudComponent } from './process-header-cloud.component';
import { ProcessCloudServiceMock } from '../../mock/process-cloud.service.mock';
import { ProcessCloudService } from '../../services/process-cloud.service';

export default {
component: ProcessHeaderCloudComponent,
title: 'Process Services Cloud/Components/Process Header',
decorators: [
moduleMetadata({
imports: [ProcessServicesCloudStoryModule, ProcessHeaderCloudModule],
providers: [{ provide: ProcessCloudService, useClass: ProcessCloudServiceMock }]
})
],
argTypes: {
appName: { table: { disable: true } },
processInstanceId: { table: { disable: true } }
}
} as Meta;

const template: Story<ProcessHeaderCloudComponent> = (args: ProcessHeaderCloudComponent) => ({
props: args
});

export const primary = template.bind({});
primary.args = {
appName: 'app',
processInstanceId: 'mock-process-id'
};

export const noParentAndBusinessAndName = template.bind({});
noParentAndBusinessAndName.args = {
appName: 'app-placeholders',
processInstanceId: 'mock-process-id'
};

export const invalidOrMissingAppName = template.bind({});
invalidOrMissingAppName.args = {
appName: undefined,
processInstanceId: 'mock-process-id'
};

export const invalidOrMissingProcessInstanceID = template.bind({});
invalidOrMissingProcessInstanceID.args = {
appName: 'app',
processInstanceId: undefined
};
@@ -0,0 +1,31 @@
/*!
* @license
* Copyright 2019 Alfresco Software, Ltd.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

import { Observable, Subject } from 'rxjs';
import { ProcessInstanceCloud } from '../start-process/models/process-instance-cloud.model';
import { ProcessDefinitionCloud } from '../../models/process-definition-cloud.model';
import { ApplicationVersionModel } from '../../models/application-version.model';

export interface ProcessCloudInterface {

dataChangesDetected: Subject<ProcessInstanceCloud>;

getProcessInstanceById(appName: string, processInstanceId: string): Observable<ProcessInstanceCloud>;
getProcessDefinitions(appName: string): Observable<ProcessDefinitionCloud[]>;
getApplicationVersions(appName: string): Observable<ApplicationVersionModel[]>;
cancelProcess(appName: string, processInstanceId: string): Observable<ProcessInstanceCloud>;
}
Expand Up @@ -23,11 +23,12 @@ import { ProcessInstanceCloud } from '../start-process/models/process-instance-c
import { BaseCloudService } from '../../services/base-cloud.service';
import { ProcessDefinitionCloud } from '../../models/process-definition-cloud.model';
import { ApplicationVersionModel, ApplicationVersionResponseModel } from '../../models/application-version.model';
import { ProcessCloudInterface } from './process-cloud.interface';

@Injectable({
providedIn: 'root'
})
export class ProcessCloudService extends BaseCloudService {
export class ProcessCloudService extends BaseCloudService implements ProcessCloudInterface {

dataChangesDetected = new Subject<ProcessInstanceCloud>();

Expand Down

0 comments on commit 18d57e4

Please sign in to comment.