From ef25f30f091e41fef8c2729a4cac8ec67b3da40c Mon Sep 17 00:00:00 2001
From: "Zickermann, Jan" <jan.zickermann@dataport.de>
Date: Wed, 28 Feb 2024 15:27:14 +0100
Subject: [PATCH] OZG-4948 Use data-test-id in test

---
 .../postfach-form.component.html              |  5 +++
 .../postfach-form.component.spec.ts           | 35 ++++++++++++-------
 2 files changed, 28 insertions(+), 12 deletions(-)

diff --git a/alfa-client/libs/admin-settings/src/lib/postfach/postfach-container/postfach-form/postfach-form.component.html b/alfa-client/libs/admin-settings/src/lib/postfach/postfach-container/postfach-form/postfach-form.component.html
index a249e953cf..1810d16569 100644
--- a/alfa-client/libs/admin-settings/src/lib/postfach/postfach-container/postfach-form/postfach-form.component.html
+++ b/alfa-client/libs/admin-settings/src/lib/postfach/postfach-container/postfach-form/postfach-form.component.html
@@ -4,26 +4,31 @@
   <div aria-describedby="absender-desc" class="grid-col-1 mb-2 mt-2 grid w-96 gap-1">
     <text-field
       inputId="absender-name"
+	  data-test-id="absender-name"
       label="Name"
       [formControlName]="PostfachFormService.NAME_FIELD"
     ></text-field>
     <text-field
       inputId="absender-anschrift"
+	  data-test-id="absender-anschrift"
       label="Anschrift"
       [formControlName]="PostfachFormService.ANSCHRIFT_FIELD"
     ></text-field>
     <text-field
       inputId="absender-dienst"
+	  data-test-id="absender-dienst"
       label="Dienst"
       [formControlName]="PostfachFormService.DIENST_FIELD"
     ></text-field>
     <text-field
       inputId="absender-mandant"
+	  data-test-id="absender-mandant"
       label="Mandant"
       [formControlName]="PostfachFormService.MANDANT_FIELD"
     ></text-field>
     <text-field
       inputId="absender-gemeindeschluessel"
+	  data-test-id="absender-gemeindeschluessel"
       label="Gemeindeschlüssel"
       [formControlName]="PostfachFormService.GEMEINDESCHLUESSEL_FIELD"
     ></text-field>
diff --git a/alfa-client/libs/admin-settings/src/lib/postfach/postfach-container/postfach-form/postfach-form.component.spec.ts b/alfa-client/libs/admin-settings/src/lib/postfach/postfach-container/postfach-form/postfach-form.component.spec.ts
index 8145697c97..b71dc55347 100644
--- a/alfa-client/libs/admin-settings/src/lib/postfach/postfach-container/postfach-form/postfach-form.component.spec.ts
+++ b/alfa-client/libs/admin-settings/src/lib/postfach/postfach-container/postfach-form/postfach-form.component.spec.ts
@@ -38,18 +38,29 @@ describe('PostfachFormComponent', () => {
   });
 
   describe('Absender section', () => {
-    test.each([
-      [PostfachFormService.NAME_FIELD, 'Name'],
-      [PostfachFormService.ANSCHRIFT_FIELD, 'Anschrift'],
-      [PostfachFormService.DIENST_FIELD, 'Dienst'],
-      [PostfachFormService.MANDANT_FIELD, 'Mandant'],
-      [PostfachFormService.GEMEINDESCHLUESSEL_FIELD, 'Gemeindeschlüssel'],
-    ])('should have label for field "%s" with name "%s"', (fieldId, text) => {
-      const textFieldElement = getElementFromFixture(
-        fixture,
-        `text-field[inputId=absender-${fieldId}]`,
-      );
-      expect(textFieldElement.getAttribute('label')).toBe(text);
+    const fields = [
+      [PostfachFormService.NAME_FIELD, 'Name', 'absender-name'],
+      [PostfachFormService.ANSCHRIFT_FIELD, 'Anschrift', 'absender-anschrift'],
+      [PostfachFormService.DIENST_FIELD, 'Dienst', 'absender-dienst'],
+      [PostfachFormService.MANDANT_FIELD, 'Mandant', 'absender-mandant'],
+      [
+        PostfachFormService.GEMEINDESCHLUESSEL_FIELD,
+        'Gemeindeschlüssel',
+        'absender-gemeindeschluessel',
+      ],
+    ];
+
+    test.each(fields)(
+      'should have label for field "%s" with name "%s"',
+      (fieldName, text, inputId) => {
+        const textFieldElement = getElementFromFixture(fixture, getDataTestIdOf(inputId));
+        expect(textFieldElement.getAttribute('label')).toBe(text);
+      },
+    );
+
+    test.each(fields)('should have inputId for field "%s"', (fieldName, text, inputId) => {
+      const textFieldElement = getElementFromFixture(fixture, getDataTestIdOf(inputId));
+      expect(textFieldElement.getAttribute('inputId')).toBe(inputId);
     });
   });
 
-- 
GitLab