Skip to content

Commit

Permalink
[AAE-5962] Storybook stories for FormDefinitionSelectorCloud component (
Browse files Browse the repository at this point in the history
#7332)

* [AAE-5962] added stories and mock

* [AAE-5961] afixed standalone task form mock

* [AAE-5962] added interface for real and mock form definition selector service

* [AAE-5962] renamed mock data
  • Loading branch information
tomgny committed Nov 16, 2021
1 parent 906bab5 commit 3e16ae3
Show file tree
Hide file tree
Showing 6 changed files with 159 additions and 32 deletions.
@@ -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<FormDefinitionSelectorCloudComponent> = (args: FormDefinitionSelectorCloudComponent) => ({
props: args
});

export const primary = template.bind({});
primary.args = {
appName: 'app'
};
@@ -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<FormRepresentation[]> {
return of(mockFormRepresentations.map(response => <FormRepresentation> response.formRepresentation));
}

getStandAloneTaskForms(_appName: string): Observable<FormRepresentation[]> {
return of(mockFormRepresentations.map(response => <FormRepresentation> response.formRepresentation).filter((form: any) => form.standalone ? form : undefined));
}
}
@@ -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
}
}
];
@@ -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<FormRepresentation[]>;
getStandAloneTaskForms(appName: string): Observable<FormRepresentation[]>;
}
Expand Up @@ -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', () => {
Expand Down Expand Up @@ -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();
Expand All @@ -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();
Expand Down
Expand Up @@ -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) {
Expand Down

0 comments on commit 3e16ae3

Please sign in to comment.