Skip to content

Commit

Permalink
feature(publish): #535 added test
Browse files Browse the repository at this point in the history
  • Loading branch information
ds-mmaul committed Jan 26, 2024
1 parent 938772d commit e37fafe
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ describe('AssetPublisherComponent', () => {
const policyServiceSpy = jasmine.createSpyObj('PolicyService', ['getPolicies', 'publishAssets']);
const isOpenSubject = new BehaviorSubject<boolean>(true);

const renderAssetPublisherComponent = (input?) => {
const renderAssetPublisherComponent = () => {
return renderComponent(AssetPublisherComponent, {
providers: [ { provide: PolicyService, useValue: policyServiceSpy }],
componentInputs: {
Expand All @@ -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');

Expand All @@ -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();
});
});

});
Original file line number Diff line number Diff line change
@@ -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',
Expand Down Expand Up @@ -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() {
Expand Down

0 comments on commit e37fafe

Please sign in to comment.