Skip to content
Snippets Groups Projects
Verified Commit 3299ca58 authored by Sebastian Bergandy's avatar Sebastian Bergandy :keyboard:
Browse files

OZG-6988 add form engine and form id fields

Sub task: OZG-7446
parent b16be9d4
Branches
Tags
1 merge request!27OZG-6988 implement button
<p>admin-statistik-fields-form works!</p>
<h2 class="heading-2" data-test-id="statistik-fields-form-header-text">Felder zur Auswertung hinzufügen</h2>
<ods-text-input
[fieldControl]="formEngineFormControl"
label="Formengine"
placeholder="Tragen Sie hier die Formengine des Formulars ein"
data-test-id="form-engine-input"
></ods-text-input>
<ods-text-input
[fieldControl]="formIdFormControl"
label="FormID"
placeholder="Tragen Sie hier die FormID des Formulars ein"
data-test-id="form-id-input"
></ods-text-input>
import { existsAsHtmlElement, getElementComponentFromFixtureByCss } from '@alfa-client/test-utils';
import { ComponentFixture, TestBed } from '@angular/core/testing';
import { FormBuilder } from '@angular/forms';
import { TextInputComponent } from '@ods/system';
import { getDataTestIdOf } from '../../../../../../tech-shared/test/data-test';
import { AdminStatistikFieldsFormComponent } from './admin-statistik-fields-form.component';
import { StatistikFieldsFormService } from './statistik-fields.formservice';
describe('AdminStatistikFieldsFormComponent', () => {
let component: AdminStatistikFieldsFormComponent;
let fixture: ComponentFixture<AdminStatistikFieldsFormComponent>;
const formEngineInputTestId: string = getDataTestIdOf('form-engine-input');
const formIdInputTestId: string = getDataTestIdOf('form-id-input');
let formService: StatistikFieldsFormService;
beforeEach(() => {
formService = new StatistikFieldsFormService(new FormBuilder());
});
beforeEach(async () => {
await TestBed.configureTestingModule({
imports: [AdminStatistikFieldsFormComponent],
providers: [{ provide: StatistikFieldsFormService, useValue: formService }],
}).compileComponents();
fixture = TestBed.createComponent(AdminStatistikFieldsFormComponent);
......@@ -15,7 +30,57 @@ describe('AdminStatistikFieldsFormComponent', () => {
fixture.detectChanges();
});
it('should create', () => {
expect(component).toBeTruthy();
describe('component', () => {
it('should create', () => {
expect(component).toBeTruthy();
});
it('should set form controls', () => {
expect(component.formEngineFormControl).toBeDefined();
expect(component.formIdFormControl).toBeDefined();
expect(component.dataFieldsFormArray).toBeDefined();
});
});
describe('template', () => {
describe('form engine input', () => {
it('should exists', () => {
fixture.detectChanges();
existsAsHtmlElement(fixture, formEngineInputTestId);
});
it('should have been called with inputs', () => {
fixture.detectChanges();
const formEngineInput: TextInputComponent = getElementComponentFromFixtureByCss<TextInputComponent>(
fixture,
formEngineInputTestId,
);
expect(formEngineInput.fieldControl).toEqual(component.formEngineFormControl);
});
});
describe('form id input', () => {
it('should exists', () => {
fixture.detectChanges();
existsAsHtmlElement(fixture, formIdInputTestId);
});
it('should have been called with inputs', () => {
fixture.detectChanges();
const formIdInput: TextInputComponent = getElementComponentFromFixtureByCss<TextInputComponent>(
fixture,
formIdInputTestId,
);
expect(formIdInput.fieldControl).toEqual(component.formIdFormControl);
});
});
describe('data field input', () => {});
});
});
import { CommonModule } from '@angular/common';
import { Component } from '@angular/core';
import { Component, inject } from '@angular/core';
import { FormArray, FormControl } from '@angular/forms';
import { TextInputComponent } from '@ods/system';
import { StatistikFieldsFormService } from './statistik-fields.formservice';
@Component({
selector: 'admin-statistik-fields-form',
standalone: true,
imports: [CommonModule],
imports: [CommonModule, TextInputComponent],
templateUrl: './admin-statistik-fields-form.component.html',
})
export class AdminStatistikFieldsFormComponent {}
export class AdminStatistikFieldsFormComponent {
private readonly formService = inject(StatistikFieldsFormService);
public readonly formEngineFormControl: FormControl = this.formService.form.controls[
StatistikFieldsFormService.FIELD_FORM_ENGINE
] as FormControl;
public readonly formIdFormControl: FormControl = this.formService.form.controls[
StatistikFieldsFormService.FIELD_FORM_ID
] as FormControl;
public readonly dataFieldsFormArray: FormArray = this.formService.form.controls[
StatistikFieldsFormService.FIELD_DATA_FIELDS
] as FormArray;
}
import { AbstractFormService, EMPTY_STRING, StateResource } from '@alfa-client/tech-shared';
import { Injectable } from '@angular/core';
import { FormArray, FormControl, UntypedFormGroup } from '@angular/forms';
import { Resource } from '@ngxp/rest';
import { EMPTY, Observable } from 'rxjs';
@Injectable()
export class StatistikFieldsFormService extends AbstractFormService {
public static readonly FIELD_FORM_ENGINE: string = 'formEngine';
public static readonly FIELD_FORM_ID: string = 'formId';
public static readonly FIELD_DATA_FIELDS: string = 'dataFields';
protected initForm(): UntypedFormGroup {
return this.formBuilder.group({
[StatistikFieldsFormService.FIELD_FORM_ENGINE]: new FormControl(EMPTY_STRING),
[StatistikFieldsFormService.FIELD_FORM_ID]: new FormControl(EMPTY_STRING),
[StatistikFieldsFormService.FIELD_DATA_FIELDS]: new FormArray([new FormControl(EMPTY_STRING)]),
});
}
protected doSubmit(): Observable<StateResource<Resource>> {
return EMPTY;
}
protected getPathPrefix(): string {
return 'settingBody';
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment