aboutsummaryrefslogtreecommitdiffstats
path: root/catalog-ui/src/app/ng2/components/forms/artifacts-form/artifact-form.component.spec.ts
diff options
context:
space:
mode:
Diffstat (limited to 'catalog-ui/src/app/ng2/components/forms/artifacts-form/artifact-form.component.spec.ts')
-rw-r--r--catalog-ui/src/app/ng2/components/forms/artifacts-form/artifact-form.component.spec.ts100
1 files changed, 44 insertions, 56 deletions
diff --git a/catalog-ui/src/app/ng2/components/forms/artifacts-form/artifact-form.component.spec.ts b/catalog-ui/src/app/ng2/components/forms/artifacts-form/artifact-form.component.spec.ts
index fc69509ee9..49a06b27e0 100644
--- a/catalog-ui/src/app/ng2/components/forms/artifacts-form/artifact-form.component.spec.ts
+++ b/catalog-ui/src/app/ng2/components/forms/artifacts-form/artifact-form.component.spec.ts
@@ -7,32 +7,37 @@ import {CacheService} from "../../../services/cache.service";
import {TranslateService} from "../../../shared/translator/translate.service";
import {ArtifactModel} from "../../../../models/artifacts";
import {IDropDownOption} from "onap-ui-angular/dist/form-elements/dropdown/dropdown-models";
-import {Observable, Subject} from "rxjs";
-import {getValue} from "@ngxs/store";
+import {Subject} from "rxjs";
+import {ArtifactConfigService} from "../../../services/artifact-config.service";
+import {ArtifactType, ComponentType} from "../../../../utils/constants";
describe('artifact form component', () => {
let fixture: ComponentFixture<ArtifactFormComponent>;
let cacheServiceMock: Partial<CacheService>;
+ let artifactConfigService: Partial<ArtifactConfigService>;
let onValidationChangeMock: Partial<Subject<boolean>>;
let artifactModel = new ArtifactModel();
+ artifactConfigService = {
+ findAllTypeBy: jest.fn()
+ };
beforeEach(
async(() => {
onValidationChangeMock = {
next: jest.fn()
- }
+ };
cacheServiceMock = {
contains: jest.fn(),
remove: jest.fn(),
set: jest.fn(),
get: jest.fn()
- }
+ };
const configure: ConfigureFn = testBed => {
testBed.configureTestingModule({
@@ -41,6 +46,7 @@ describe('artifact form component', () => {
schemas: [NO_ERRORS_SCHEMA],
providers: [
{provide: CacheService, useValue: cacheServiceMock},
+ {provide: ArtifactConfigService, useValue: artifactConfigService},
{provide: TranslateService, useValue: {}}
],
});
@@ -55,91 +61,73 @@ describe('artifact form component', () => {
it('should verify initArtifactTypes for DEPLOYMENT and ArtifactType = HEAT_ENV', () =>{
- cacheServiceMock.get.mockImplementation(() =>{
- return {
- artifacts: {
- deployment:{
- resourceInstanceDeploymentArtifacts: [{name: "Dummy Value Returned from ui api"}],
- }
- }
+ artifactConfigService.findAllTypeBy.mockImplementation((artifactType, componentType, resourceType) => {
+ if (artifactType == 'DEPLOYMENT' && componentType == ComponentType.RESOURCE_INSTANCE && resourceType == 'VF') {
+ return ['Val1', 'Val2', 'Val3', ArtifactType.HEAT_ENV];
}
});
fixture.componentInstance.artifactType = 'DEPLOYMENT';
+ fixture.componentInstance.resourceType = 'VF';
fixture.componentInstance.artifact = artifactModel;
- fixture.componentInstance.artifact.artifactType = 'HEAT_ENV';
+ fixture.componentInstance.artifact.artifactType = ArtifactType.HEAT_ENV;
fixture.componentInstance.initArtifactTypes();
- expect(fixture.componentInstance.selectedFileType).toEqual(undefined);
+ expect(fixture.componentInstance.selectedFileType).toEqual({"label": ArtifactType.HEAT_ENV, "value": ArtifactType.HEAT_ENV});
});
- it('should verify initArtifactTypes for DEPLOYMENT and ComponentType = RESOURCE', () =>{
+ it('should verify initArtifactTypes for DEPLOYMENT and ComponentType = RESOURCE', () => {
- cacheServiceMock.get.mockImplementation(() =>{
- return {
- artifacts: {
- deployment:{
- resourceDeploymentArtifacts: [{name: "Dummy Value Returned from ui api"}],
- }
- }
+ const expectedSelectedValue = 'Val3';
+ const artifactType = 'DEPLOYMENT';
+ const resourceType = 'VF';
+ artifactConfigService.findAllTypeBy.mockImplementation((artifactType1, componentType1, resourceType1) => {
+ if (artifactType1 == artifactType && componentType1 == ComponentType.RESOURCE && resourceType1 == resourceType) {
+ return ['Val1', 'Val2', expectedSelectedValue, 'Val4'];
}
- });
-
- fixture.componentInstance.artifactType = 'DEPLOYMENT';
- fixture.componentInstance.artifact = artifactModel;
- fixture.componentInstance.componentType = 'RESOURCE';
-
- fixture.componentInstance.initArtifactTypes();
-
- expect(fixture.componentInstance.selectedFileType).toEqual(undefined);
-
- });
-
- it('should verify initArtifactTypes for DEPLOYMENT and NOT ComponentType = RESOURCE OR NOT ArtifactType = HEAT_ENV', () =>{
- cacheServiceMock.get.mockImplementation(() =>{
- return {
- artifacts: {
- deployment:{
- serviceDeploymentArtifacts: [{name: "Dummy Value Returned from ui api"}],
- }
- }
- }
+ return [];
});
- fixture.componentInstance.artifactType = 'DEPLOYMENT';
+ fixture.componentInstance.artifactType = artifactType;
fixture.componentInstance.artifact = artifactModel;
- // fixture.componentInstance.componentType = 'RESOURCE';
+ fixture.componentInstance.resourceType = resourceType;
+ fixture.componentInstance.componentType = ComponentType.RESOURCE;
+ fixture.componentInstance.artifact.artifactType = expectedSelectedValue;
fixture.componentInstance.initArtifactTypes();
- expect(fixture.componentInstance.selectedFileType).toEqual(undefined);
+ expect(fixture.componentInstance.selectedFileType).toEqual({'label': expectedSelectedValue, 'value': expectedSelectedValue});
});
- it('should verify initArtifactTypes for INFORMATION', () =>{
+ it('should verify initArtifactTypes for INFORMATIONAL', () => {
- cacheServiceMock.get.mockImplementation(() =>{
- return {
- artifacts: {
- other: [{name: "Val1"}, {name: "ExpectedValToBeSelected"}, {name: "Val3"}]
- }
+ const expectedSelectedValue = 'Val3';
+ const artifactType = 'INFORMATIONAL';
+ const resourceType = null;
+ artifactConfigService.findAllTypeBy.mockImplementation((artifactType1, componentType1, resourceType1) => {
+ if (artifactType1 == artifactType && componentType1 == ComponentType.SERVICE && resourceType1 == resourceType) {
+ return ['Val1', 'Val2', expectedSelectedValue, 'Val4'];
}
+
+ return [];
});
- fixture.componentInstance.artifactType = 'INFORMATIONAL';
+ fixture.componentInstance.artifactType = artifactType;
fixture.componentInstance.artifact = artifactModel;
- fixture.componentInstance.artifact.artifactType = 'ExpectedValToBeSelected';
+ fixture.componentInstance.resourceType = resourceType;
+ fixture.componentInstance.componentType = ComponentType.SERVICE;
+ fixture.componentInstance.artifact.artifactType = expectedSelectedValue;
fixture.componentInstance.initArtifactTypes();
- expect(fixture.componentInstance.selectedFileType).toEqual({"label": "ExpectedValToBeSelected", "value": "ExpectedValToBeSelected"});
+ expect(fixture.componentInstance.selectedFileType).toEqual({'label': expectedSelectedValue, 'value': expectedSelectedValue});
});
-
it('should match current snapshot of artifact form component', () => {
expect(fixture).toMatchSnapshot();
});
@@ -147,7 +135,7 @@ describe('artifact form component', () => {
it('should verify onUploadFile -> file gets file name', () => {
let file = {
filename:'dummyFileName'
- }
+ };
fixture.componentInstance.verifyTypeAndFileWereFilled = jest.fn();
fixture.componentInstance.artifact = artifactModel;