diff --git a/frontend/src/app/modules/shared/components/asset-publisher/asset-publisher.component.spec.ts b/frontend/src/app/modules/shared/components/asset-publisher/asset-publisher.component.spec.ts index c69762f40f..179dec1717 100644 --- a/frontend/src/app/modules/shared/components/asset-publisher/asset-publisher.component.spec.ts +++ b/frontend/src/app/modules/shared/components/asset-publisher/asset-publisher.component.spec.ts @@ -9,7 +9,7 @@ describe('AssetPublisherComponent', () => { const policyServiceSpy = jasmine.createSpyObj('PolicyService', ['getPolicies', 'publishAssets']); const isOpenSubject = new BehaviorSubject(true); - const renderAssetPublisherComponent = (input?) => { + const renderAssetPublisherComponent = () => { return renderComponent(AssetPublisherComponent, { providers: [ { provide: PolicyService, useValue: policyServiceSpy }], componentInputs: { @@ -30,7 +30,7 @@ describe('AssetPublisherComponent', () => { const dummyPolicy: Policy = { policyId: 'id-1', createdOn: 'testdate', validUntil: 'testdate' }; policyServiceSpy.publishAssets.and.returnValue(of({})); - policyServiceSpy.getPolicies.and.returnValue(of([dummyPolicy])) + policyServiceSpy.getPolicies.and.returnValue(of([dummyPolicy])); const submittedSpy = spyOn(componentInstance.submitted, 'emit'); @@ -46,4 +46,31 @@ describe('AssetPublisherComponent', () => { }); }); + it('should set policies when requesting policies', async function() { + const { fixture } = await renderAssetPublisherComponent(); + const { componentInstance } = fixture; + const dummyPolicy: Policy = { policyId: 'id-1', createdOn: 'testdate', validUntil: 'testdate' }; + + const submittedSpy = spyOn(componentInstance.submitted, 'emit'); + + + + policyServiceSpy.publishAssets.and.returnValue(of({})); + policyServiceSpy.getPolicies.and.returnValue(of([dummyPolicy])) + + + componentInstance.policyFormControl.setValue(dummyPolicy.policyId); + fixture.detectChanges(); + + componentInstance.publish(); + + fixture.whenStable().then(() => { + expect(policyServiceSpy.publishAssets).toHaveBeenCalledWith([], dummyPolicy.policyId); + expect(policyServiceSpy.getPolicies).toHaveBeenCalled(); + expect(componentInstance.policiesList).toEqual([dummyPolicy]); + expect(componentInstance.policyFormControl.value).toBeNull(); + expect(submittedSpy).toHaveBeenCalled(); + }); + }); + }); diff --git a/frontend/src/app/modules/shared/components/asset-publisher/asset-publisher.component.ts b/frontend/src/app/modules/shared/components/asset-publisher/asset-publisher.component.ts index 9892d86feb..62d75b9f3c 100644 --- a/frontend/src/app/modules/shared/components/asset-publisher/asset-publisher.component.ts +++ b/frontend/src/app/modules/shared/components/asset-publisher/asset-publisher.component.ts @@ -1,9 +1,9 @@ -import {Component, EventEmitter, Input, Output} from '@angular/core'; -import {FormControl, Validators} from '@angular/forms'; -import {ImportState, Part} from '@page/parts/model/parts.model'; -import {Policy} from '@page/policies/model/policy.model'; -import {PolicyService} from '@shared/service/policy.service'; -import {Observable, Subscription} from 'rxjs'; +import { Component, EventEmitter, Input, Output } from '@angular/core'; +import { FormControl, Validators } from '@angular/forms'; +import { ImportState, Part } from '@page/parts/model/parts.model'; +import { Policy } from '@page/policies/model/policy.model'; +import { PolicyService } from '@shared/service/policy.service'; +import { Observable, Subscription } from 'rxjs'; @Component({ selector: 'app-asset-publisher', @@ -46,13 +46,12 @@ export class AssetPublisherComponent { publish(): void { const selectedAssetIds = this.selectedAssets.map(part => part.id); - this.policyFormControl.reset(); - this.selectedAssets = []; this.policyService.publishAssets(selectedAssetIds, this.policyFormControl.value).subscribe({ next: data => {this.submitted.emit(null);}, error: error => {this.submitted.emit(error);} }); - + this.policyFormControl.reset(); + this.selectedAssets = []; } private getPolicies() {