Skip to content

Commit

Permalink
Merge pull request #311 from fecgov/bug/230-limit-dropdown
Browse files Browse the repository at this point in the history
Limited contributor type to IND and ORG in group b transactions
  • Loading branch information
mjtravers authored May 26, 2022
2 parents 48a1911 + d932484 commit dc1bf44
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ <h3>Contributor</h3>
</div>
</div>
</div>
<ng-container *ngIf="[ContactTypes.COMMITTEE, ContactTypes.ORGANIZATION].includes(form.get('entity_type')?.value)">
<ng-container *ngIf="form.get('entity_type')?.value === ContactTypes.ORGANIZATION">
<div class="grid">
<div class="col-8">
<div class="field">
Expand All @@ -38,7 +38,7 @@ <h3>Contributor</h3>
</div>
</div>
</ng-container>
<ng-container *ngIf="[ContactTypes.INDIVIDUAL, ContactTypes.CANDIDATE].includes(form.get('entity_type')?.value)">
<ng-container *ngIf="form.get('entity_type')?.value === ContactTypes.INDIVIDUAL">
<div class="grid">
<div class="col-4">
<div class="field">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ describe('TransactionGroupBComponent', () => {
component.form.patchValue({
entity_type: ContactTypes.INDIVIDUAL,
});
expect(component.form.get('contributor_organization_name')?.value).toBe('');
expect(component.form.get('contributor_organization_name')?.value).toBe(null);
expect(component.form.get('contributor_last_name')?.value).toBe('last name');
expect(component.form.get('contributor_first_name')?.value).toBe('first name');

Expand All @@ -113,8 +113,8 @@ describe('TransactionGroupBComponent', () => {
entity_type: ContactTypes.ORGANIZATION,
});
expect(component.form.get('contributor_organization_name')?.value).toBe('org name');
expect(component.form.get('contributor_last_name')?.value).toBe('');
expect(component.form.get('contributor_first_name')?.value).toBe('');
expect(component.form.get('contributor_last_name')?.value).toBe(null);
expect(component.form.get('contributor_first_name')?.value).toBe(null);
});

it('#save() should save a new record', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,9 @@ export class TransactionGroupBComponent implements OnInit, OnDestroy {
'memo_text_description',
];
ContactTypes = ContactTypes;
contactTypeOptions: PrimeOptions = LabelUtils.getPrimeOptions(ContactTypeLabels);
contactTypeOptions: PrimeOptions = LabelUtils.getPrimeOptions(ContactTypeLabels).filter(
option => [ContactTypes.INDIVIDUAL, ContactTypes.ORGANIZATION].includes(option.code as ContactTypes)
);
stateOptions: PrimeOptions = LabelUtils.getPrimeOptions(LabelUtils.getStateCodeLabelsWithoutMilitary());
destroy$: Subject<boolean> = new Subject<boolean>();
formSubmitted = false;
Expand Down Expand Up @@ -78,16 +80,15 @@ export class TransactionGroupBComponent implements OnInit, OnDestroy {
?.get('entity_type')
?.valueChanges.pipe(takeUntil(this.destroy$))
.subscribe((value: string) => {
if ([ContactTypes.INDIVIDUAL, ContactTypes.CANDIDATE].includes(value as ContactTypes)) {
this.form.patchValue({
contributor_organization_name: '',
});
if (value === ContactTypes.INDIVIDUAL) {
this.form.get('contributor_organization_name')?.reset();
}
if ([ContactTypes.ORGANIZATION, ContactTypes.COMMITTEE].includes(value as ContactTypes)) {
this.form.patchValue({
contributor_last_name: '',
contributor_first_name: '',
});
if (value === ContactTypes.ORGANIZATION) {
this.form.get('contributor_last_name')?.reset();
this.form.get('contributor_first_name')?.reset();
this.form.get('contributor_middle_name')?.reset();
this.form.get('contributor_prefix')?.reset();
this.form.get('contributor_suffix')?.reset();
}
});
}
Expand Down

0 comments on commit dc1bf44

Please sign in to comment.