Skip to content

Commit

Permalink
AAE-3084 Increase coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
pmartinezga committed Jul 30, 2020
1 parent 3ad91b8 commit cfb1ab3
Show file tree
Hide file tree
Showing 2 changed files with 113 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
/*!
* @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 { async, ComponentFixture, TestBed } from '@angular/core/testing';
import { ProcessCloudContentService } from '../../../services/process-cloud-content.service';
import { AttachFileCloudWidgetComponent } from './attach-file-cloud-widget.component';
import {
setupTestBed,
FormFieldModel,
FormModel,
FormFieldTypes,
FormFieldMetadata
} from '@alfresco/adf-core';
import { ProcessServiceCloudTestingModule } from '../../../../testing/process-service-cloud.testing.module';
import { CUSTOM_ELEMENTS_SCHEMA } from '@angular/core';
import { ContentModule } from '@alfresco/adf-content-services';
import { By } from '@angular/platform-browser';
import { of } from 'rxjs';
import { FormCloudModule } from '../../../form-cloud.module';
import { TranslateModule } from '@ngx-translate/core';
import { UploadCloudWidgetComponent } from './upload-cloud.widget';

describe('UploadCloudWidgetComponent', () => {
let widget: UploadCloudWidgetComponent;
let fixture: ComponentFixture<UploadCloudWidgetComponent>;
let processCloudContentService: ProcessCloudContentService;

const onlyLocalParams = {
fileSource: {
serviceId: 'local-file'
}
};

const fakeLocalPngAnswer = {
id: 1155,
nodeId: 1155,
name: 'a_png_file.png',
created: '2017-07-25T17:17:37.099Z',
createdBy: {
id: 1001,
firstName: 'Admin',
lastName: 'admin',
email: 'admin'
},
relatedContent: false,
contentAvailable: true,
link: false,
mimeType: 'image/png',
simpleType: 'image',
previewStatus: 'queued',
thumbnailStatus: 'queued'
};

setupTestBed({
imports: [
TranslateModule.forRoot(),
ProcessServiceCloudTestingModule,
FormCloudModule,
ContentModule.forRoot()
],
schemas: [CUSTOM_ELEMENTS_SCHEMA]
});

beforeEach(async(() => {
fixture = TestBed.createComponent(AttachFileCloudWidgetComponent);
widget = fixture.componentInstance;
processCloudContentService = TestBed.inject(ProcessCloudContentService);
}));

afterEach(() => {
fixture.destroy();
});

it('should emitChanges when file is added', () => {
const emitChangesSpy = spyOn<any>(widget, 'emitChanges');

widget.field = new FormFieldModel(new FormModel(), {
type: FormFieldTypes.UPLOAD,
value: []
});
widget.field.id = 'attach-file-attach';
widget.field.params = <FormFieldMetadata> onlyLocalParams;
spyOn(
processCloudContentService,
'createTemporaryRawRelatedContent'
).and.returnValue(of(fakeLocalPngAnswer));
fixture.detectChanges();
fixture.whenStable().then(() => {
const inputDebugElement = fixture.debugElement.query(
By.css('#uploadFiles')
);
inputDebugElement.triggerEventHandler('change', {
target: { files: [fakeLocalPngAnswer] }
});
fixture.detectChanges();
expect(emitChangesSpy).toHaveBeenCalled();
});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -102,8 +102,6 @@ export class UploadCloudWidgetComponent extends WidgetComponent implements OnIni
this.emitChanges();
}
);
} else {
this.emitChanges();
}
}

Expand Down

0 comments on commit cfb1ab3

Please sign in to comment.