diff --git a/lib/process-services-cloud/src/lib/form/components/form-definition-selector-cloud.component.stories.ts b/lib/process-services-cloud/src/lib/form/components/form-definition-selector-cloud.component.stories.ts new file mode 100644 index 0000000000..49ccf1d46b --- /dev/null +++ b/lib/process-services-cloud/src/lib/form/components/form-definition-selector-cloud.component.stories.ts @@ -0,0 +1,48 @@ +/*! + * @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 { FormCloudModule } from '../form-cloud.module'; +import { FormDefinitionSelectorCloudComponent } from './form-definition-selector-cloud.component'; +import { ProcessServicesCloudStoryModule } from '../../testing/process-services-cloud-story.module'; +import { FormDefinitionSelectorCloudService } from '../services/form-definition-selector-cloud.service'; +import { FormDefinitionSelectorCloudServiceMock } from '../mocks/form-definition-selector-cloud.service.mock'; + +export default { + component: FormDefinitionSelectorCloudComponent, + title: 'Process Services Cloud/Components/Form Definition Selector', + decorators: [ + moduleMetadata({ + imports: [ProcessServicesCloudStoryModule, FormCloudModule], + providers: [ + { provide: FormDefinitionSelectorCloudService, useClass: FormDefinitionSelectorCloudServiceMock } + ] + }) + ], + argTypes: { + appName: { table: { disable: true } } + } +} as Meta; + +const template: Story = (args: FormDefinitionSelectorCloudComponent) => ({ + props: args +}); + +export const primary = template.bind({}); +primary.args = { + appName: 'app' +}; diff --git a/lib/process-services-cloud/src/lib/form/mocks/form-definition-selector-cloud.service.mock.ts b/lib/process-services-cloud/src/lib/form/mocks/form-definition-selector-cloud.service.mock.ts new file mode 100644 index 0000000000..84d279f0a0 --- /dev/null +++ b/lib/process-services-cloud/src/lib/form/mocks/form-definition-selector-cloud.service.mock.ts @@ -0,0 +1,36 @@ +/*! + * @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 { Injectable } from '@angular/core'; +import { Observable, of } from 'rxjs'; +import { FormRepresentation } from '../../services/form-fields.interfaces'; +import { FormDefinitionSelectorCloudServiceInterface } from '../services/form-definition-selector-cloud.service.interface'; +import { mockFormRepresentations } from './form-representation.mock'; + +@Injectable({ + providedIn: 'root' +}) +export class FormDefinitionSelectorCloudServiceMock implements FormDefinitionSelectorCloudServiceInterface { + + getForms(_appName: string): Observable { + return of(mockFormRepresentations.map(response => response.formRepresentation)); + } + + getStandAloneTaskForms(_appName: string): Observable { + return of(mockFormRepresentations.map(response => response.formRepresentation).filter((form: any) => form.standalone ? form : undefined)); + } +} diff --git a/lib/process-services-cloud/src/lib/form/mocks/form-representation.mock.ts b/lib/process-services-cloud/src/lib/form/mocks/form-representation.mock.ts new file mode 100644 index 0000000000..07500b9470 --- /dev/null +++ b/lib/process-services-cloud/src/lib/form/mocks/form-representation.mock.ts @@ -0,0 +1,45 @@ +/*! + * @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. + */ + +export const mockFormRepresentations = [ + { + formRepresentation: { + id: 'form-de8895be-d0d7-4434-beef-559b15305d72', + name: 'Form 1', + description: '', + version: 0, + standalone: true + } + }, + { + formRepresentation: { + id: 'form-de8895be-d0d7-4434-beef-fgr34ttgrtgd', + name: 'Form 2', + description: '', + version: 0, + standalone: false + } + }, + { + formRepresentation: { + id: 'form-de8895be-d0d7-4434-beef-53453453452', + name: 'Form 3', + description: '', + version: 0 + } + } +]; diff --git a/lib/process-services-cloud/src/lib/form/services/form-definition-selector-cloud.service.interface.ts b/lib/process-services-cloud/src/lib/form/services/form-definition-selector-cloud.service.interface.ts new file mode 100644 index 0000000000..c31f14de55 --- /dev/null +++ b/lib/process-services-cloud/src/lib/form/services/form-definition-selector-cloud.service.interface.ts @@ -0,0 +1,25 @@ +/*! + * @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 } from 'rxjs'; +import { FormRepresentation } from '../../services/form-fields.interfaces'; + +export interface FormDefinitionSelectorCloudServiceInterface { + + getForms(appName: string): Observable; + getStandAloneTaskForms(appName: string): Observable; +} diff --git a/lib/process-services-cloud/src/lib/form/services/form-definition-selector-cloud.service.spec.ts b/lib/process-services-cloud/src/lib/form/services/form-definition-selector-cloud.service.spec.ts index 365ee9905e..c38b0b5ad9 100644 --- a/lib/process-services-cloud/src/lib/form/services/form-definition-selector-cloud.service.spec.ts +++ b/lib/process-services-cloud/src/lib/form/services/form-definition-selector-cloud.service.spec.ts @@ -20,38 +20,10 @@ import { AlfrescoApiService, setupTestBed } from '@alfresco/adf-core'; import { FormDefinitionSelectorCloudService } from './form-definition-selector-cloud.service'; import { ProcessServiceCloudTestingModule } from '../../testing/process-service-cloud.testing.module'; import { TranslateModule } from '@ngx-translate/core'; +import { mockFormRepresentations } from '../mocks/form-representation.mock'; declare let jasmine: any; -const responseBody = [ - { - formRepresentation: { - id: 'form-de8895be-d0d7-4434-beef-559b15305d72', - name: 'Form 1', - description: '', - version: 0, - standalone: true - } - }, - { - formRepresentation: { - id: 'form-de8895be-d0d7-4434-beef-fgr34ttgrtgd', - name: 'Form 2', - description: '', - version: 0, - standalone: false - } - }, - { - formRepresentation: { - id: 'form-de8895be-d0d7-4434-beef-53453453452', - name: 'Form 3', - description: '', - version: 0 - } - } -]; - const oauth2Auth = jasmine.createSpyObj('oauth2Auth', ['callCustomApi', 'on']); describe('Form Definition Selector Cloud Service', () => { @@ -80,7 +52,7 @@ describe('Form Definition Selector Cloud Service', () => { }); it('should fetch all the forms when getForms is called', (done) => { - oauth2Auth.callCustomApi.and.returnValue(Promise.resolve(responseBody)); + oauth2Auth.callCustomApi.and.returnValue(Promise.resolve(mockFormRepresentations)); service.getForms(appName).subscribe((result) => { expect(result).toBeDefined(); @@ -90,7 +62,7 @@ describe('Form Definition Selector Cloud Service', () => { }); it('should fetch only standalone enabled forms when getStandaloneTaskForms is called', (done) => { - oauth2Auth.callCustomApi.and.returnValue(Promise.resolve(responseBody)); + oauth2Auth.callCustomApi.and.returnValue(Promise.resolve(mockFormRepresentations)); service.getStandAloneTaskForms(appName).subscribe((result) => { expect(result).toBeDefined(); diff --git a/lib/process-services-cloud/src/lib/form/services/form-definition-selector-cloud.service.ts b/lib/process-services-cloud/src/lib/form/services/form-definition-selector-cloud.service.ts index 178451a7df..9bc010f6da 100644 --- a/lib/process-services-cloud/src/lib/form/services/form-definition-selector-cloud.service.ts +++ b/lib/process-services-cloud/src/lib/form/services/form-definition-selector-cloud.service.ts @@ -21,11 +21,12 @@ import { map } from 'rxjs/operators'; import { from, Observable } from 'rxjs'; import { BaseCloudService } from '../../services/base-cloud.service'; import { FormRepresentation } from '../../services/form-fields.interfaces'; +import { FormDefinitionSelectorCloudServiceInterface } from './form-definition-selector-cloud.service.interface'; @Injectable({ providedIn: 'root' }) -export class FormDefinitionSelectorCloudService extends BaseCloudService { +export class FormDefinitionSelectorCloudService extends BaseCloudService implements FormDefinitionSelectorCloudServiceInterface { constructor(apiService: AlfrescoApiService, appConfigService: AppConfigService) {