From 2aa5ed987e196560dfce850a55444a02f997bcd1 Mon Sep 17 00:00:00 2001 From: Steffi Erne Date: Wed, 6 Sep 2023 15:25:13 +0200 Subject: [PATCH] =?UTF-8?q?=F0=9F=A6=BA=20trim=20texts=20input=20by=20user?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- cypress/e2e/billingentity-form.cy.ts | 20 +++++++++---------- cypress/e2e/billingentity-members.cy.ts | 2 +- cypress/e2e/invitations-create.cy.ts | 2 +- cypress/e2e/organization-form.cy.ts | 4 ++-- cypress/e2e/organization-members.cy.ts | 4 ++-- cypress/e2e/teams.cy.ts | 8 ++++---- .../billing-entity-form.component.ts | 18 ++++++++--------- .../billing-entity-members.component.ts | 6 +++++- .../invitation-form.component.ts | 2 +- .../organization-form.component.ts | 6 +++--- .../organization-members-edit.component.ts | 19 ++++++++++-------- .../teams/team-edit/team-edit.component.ts | 8 ++++---- 12 files changed, 53 insertions(+), 46 deletions(-) diff --git a/cypress/e2e/billingentity-form.cy.ts b/cypress/e2e/billingentity-form.cy.ts index 98cd8f74..b9a57afa 100644 --- a/cypress/e2e/billingentity-form.cy.ts +++ b/cypress/e2e/billingentity-form.cy.ts @@ -202,17 +202,17 @@ describe('Test billing entity create', () => { cy.visit('/billingentities/$new?edit=y'); cy.get('#title').should('contain.text', 'New Billing'); - cy.get('#displayName').type('➡️ Engineering GmbH'); - - cy.get('#companyEmail').find('input').type('hallo@nxt.engineering,'); - cy.get('#phone').type('☎️'); - cy.get('#line1').type('📃'); - cy.get('#line2').type('📋'); - cy.get('#postal').type('🏤'); - cy.get('#city').type('🏙️'); + cy.get('#displayName').type('➡️ Engineering GmbH '); + + cy.get('#companyEmail').find('input').type(' hallo@nxt.engineering,'); + cy.get('#phone').type('☎️ '); + cy.get('#line1').type('📃 '); + cy.get('#line2').type('📋 '); + cy.get('#postal').type('🏤 '); + cy.get('#city').type('🏙️ '); cy.get('p-dropdown').click().contains('Switzerland').click(); - cy.get('#accountingName').type('mig'); + cy.get('#accountingName').type('mig '); cy.get('button[type="submit"]').should('be.enabled').click(); cy.wait('@createBillingEntity') @@ -322,7 +322,7 @@ describe('Test billing entity edit', () => { cy.get('#displayName').should('have.value', '➡️ Engineering GmbH'); - cy.get('#displayName').type('{selectAll}nxt Engineering'); + cy.get('#displayName').type('{selectAll}nxt Engineering '); cy.get('#companyEmail').type('info@nxt.engineering{enter}'); cy.get('#phone').type('{selectAll}1234'); cy.get('#line1').type('{selectAll}line1'); diff --git a/cypress/e2e/billingentity-members.cy.ts b/cypress/e2e/billingentity-members.cy.ts index fa9cc6ac..2d4dc4b9 100644 --- a/cypress/e2e/billingentity-members.cy.ts +++ b/cypress/e2e/billingentity-members.cy.ts @@ -76,7 +76,7 @@ describe('billing entity edit members with existing roles', () => { cy.visit('/billingentities/be-2345/members'); cy.get('.text-3xl').should('contain.text', '➡️ Engineering GmbH Members'); - cy.get('[data-cy="name-input-1"]').type('crc'); + cy.get('[data-cy="name-input-1"]').type('crc '); cy.get('p-multiselect').eq(1).click().contains('billingentities-be-2345-admin').click(); cy.get('button[type=submit]').click(); cy.wait('@updateViewer'); diff --git a/cypress/e2e/invitations-create.cy.ts b/cypress/e2e/invitations-create.cy.ts index 007f69f9..40cf8858 100644 --- a/cypress/e2e/invitations-create.cy.ts +++ b/cypress/e2e/invitations-create.cy.ts @@ -81,7 +81,7 @@ describe('Test invitation create', () => { cy.visit('/invitations/create'); cy.get('#title').should('contain.text', 'Invite User'); - cy.get('#email').type('dev@nxt.engineering'); + cy.get('#email').type('dev@nxt.engineering '); cy.get('#note').type('New Employee working for 👁️'); cy.get('p-checkbox input').should('be.disabled'); diff --git a/cypress/e2e/organization-form.cy.ts b/cypress/e2e/organization-form.cy.ts index 3f6aca60..43ae664c 100644 --- a/cypress/e2e/organization-form.cy.ts +++ b/cypress/e2e/organization-form.cy.ts @@ -44,7 +44,7 @@ describe('Test organization add', () => { cy.get('#addOrganizationButton').click(); - cy.get('#displayName').type('VSHN - the DevOps Company'); + cy.get('#displayName').type('VSHN - the DevOps Company '); cy.get('#id').should('contain.value', 'vshn-the-dev-ops-company'); const button = cy.get('button[type=submit]'); button.should('be.disabled'); @@ -204,7 +204,7 @@ describe('Test organization edit', () => { cy.get('#title').should('contain.text', 'vshn'); cy.get('#selectedBillingEntity').should('contain.text', '👁️ AG'); cy.get('#displayName').type('{selectall}'); - cy.get('#displayName').type('VSHN - the DevOps Company'); + cy.get('#displayName').type('VSHN - the DevOps Company '); cy.get('#selectedBillingEntity').click().contains('➡️ Engineering GmbH').click(); cy.get('button[type=submit]').click(); cy.wait('@update'); diff --git a/cypress/e2e/organization-members.cy.ts b/cypress/e2e/organization-members.cy.ts index ed8532c0..5d4d6224 100644 --- a/cypress/e2e/organization-members.cy.ts +++ b/cypress/e2e/organization-members.cy.ts @@ -115,7 +115,7 @@ describe('Test organization members', () => { cy.get('.text-3xl').should('contain.text', 'nxt Engineering GmbH Members'); cy.get('[data-cy="name-input-0"]').should('have.value', 'hans.meier'); cy.get('[data-cy="name-input-1"]').should('have.value', 'peter.muster'); - cy.get('[data-cy="name-input-1"]').type('{selectall}test'); + cy.get('[data-cy="name-input-1"]').type('{selectall}test '); cy.get('p-multiselect').eq(1).click().contains('control-api:organization-admin').click(); cy.get('button[type=submit]').click(); cy.wait('@save'); @@ -193,7 +193,7 @@ describe('Test organization members', () => { cy.get('.text-3xl').should('contain.text', 'nxt Engineering GmbH Members'); cy.get('[data-cy="name-input-0"]').first().should('have.value', 'hans.meier'); cy.get('[data-cy="name-input-1"]').should('have.value', 'peter.muster'); - cy.get('[data-cy="name-input-2"]').type('{selectall}test'); + cy.get('[data-cy="name-input-2"]').type('{selectall} test'); cy.get('button[type=submit]').click(); cy.wait('@save'); cy.get('@save') diff --git a/cypress/e2e/teams.cy.ts b/cypress/e2e/teams.cy.ts index 1f5233c9..08c10675 100644 --- a/cypress/e2e/teams.cy.ts +++ b/cypress/e2e/teams.cy.ts @@ -166,10 +166,10 @@ describe('Test team edit', () => { cy.get(':nth-child(2) > .flex-row > :nth-child(2) > [title="Edit team"]').click(); cy.get('.text-3xl').should('contain.text', 'team1'); - cy.get('#displayName').type('{selectall}Awesome Team!'); + cy.get('#displayName').type('{selectall}Awesome Team! '); cy.get(':nth-child(3) > :nth-child(3) > .p-ripple').click(); - cy.get(':nth-child(3) > .p-inputtext').type('cma'); + cy.get(':nth-child(3) > .p-inputtext').type('cma '); cy.get('button[type=submit]').click(); cy.wait('@update'); cy.get('@update') @@ -247,9 +247,9 @@ describe('Test teams add', () => { cy.get('.text-3xl > .ng-star-inserted').should('contain.text', 'New Team'); cy.get('#name').type('new-team'); - cy.get('#displayName').type('New Team!'); + cy.get('#displayName').type(' New Team! '); - cy.get('.flex > .p-inputtext').type('test'); + cy.get('.flex > .p-inputtext').type('test '); cy.get('button[type=submit]').click(); cy.wait('@create'); cy.get('@create') diff --git a/src/app/billingentity/billingentity-form/billing-entity-form.component.ts b/src/app/billingentity/billingentity-form/billing-entity-form.component.ts index 3ccc3d0f..e187db8e 100644 --- a/src/app/billingentity/billingentity-form/billing-entity-form.component.ts +++ b/src/app/billingentity/billingentity-form/billing-entity-form.component.ts @@ -134,21 +134,21 @@ export class BillingEntityFormComponent implements OnInit { const be = this.billingEntity; be.spec = { ...be.spec, - name: controls.displayName.value, - phone: controls.phone.value, + name: controls.displayName.value.trim(), + phone: controls.phone.value.trim(), address: { ...be.spec.address, - line1: controls.line1.value, - line2: controls.line2.value, - postalCode: controls.postal.value, - city: controls.city.value, + line1: controls.line1.value.trim(), + line2: controls.line2.value.trim(), + postalCode: controls.postal.value.trim(), + city: controls.city.value.trim(), country: controls.country.value?.name, }, - emails: controls.companyEmail.value, + emails: controls.companyEmail.value.map((email) => email.trim()), accountingContact: { ...be.spec.accountingContact, - name: controls.accountingName.value, - emails: controls.accountingEmail.value, + name: controls.accountingName.value.trim(), + emails: controls.accountingEmail.value.map((email) => email.trim()), }, }; if (this.isNewBillingEntity(be)) { diff --git a/src/app/billingentity/billingentity-members/billing-entity-members.component.ts b/src/app/billingentity/billingentity-members/billing-entity-members.component.ts index 5d622b93..8e62912c 100644 --- a/src/app/billingentity/billingentity-members/billing-entity-members.component.ts +++ b/src/app/billingentity/billingentity-members/billing-entity-members.component.ts @@ -226,7 +226,11 @@ export class BillingEntityMembersComponent implements OnInit, OnDestroy { roleBindings.forEach((binding) => { binding.subjects = []; // reset to remove other unselected users. userRefs - .filter((ref) => ref.userName) + .map((ref) => ({ + ...ref, + userName: ref.userName?.trim(), + })) + .filter((ref) => ref.userName?.trim()) .forEach((ref) => { const hasSelected = ref.selectedRoles.some((role) => role === binding.roleRef.name); if (hasSelected) { diff --git a/src/app/invitations/invitation-form/invitation-form.component.ts b/src/app/invitations/invitation-form/invitation-form.component.ts index bedc99b7..2e777874 100644 --- a/src/app/invitations/invitation-form/invitation-form.component.ts +++ b/src/app/invitations/invitation-form/invitation-form.component.ts @@ -119,7 +119,7 @@ export class InvitationFormComponent implements OnInit { }, spec: { note: this.form.controls.note.value, - email: this.form.controls.email.value, + email: this.form.controls.email.value.trim(), targetRefs: [], }, }; diff --git a/src/app/organizations/organization-form/organization-form.component.ts b/src/app/organizations/organization-form/organization-form.component.ts index 9c59b5fc..b53e34f0 100644 --- a/src/app/organizations/organization-form/organization-form.component.ts +++ b/src/app/organizations/organization-form/organization-form.component.ts @@ -133,8 +133,8 @@ export class OrganizationFormComponent implements OnInit, OnDestroy { private addOrg(): void { const rawValue = this.form.getRawValue(); const org = newOrganization( - rawValue.organizationId, - rawValue.displayName ?? '', + rawValue.organizationId.trim(), + rawValue.displayName?.trim() ?? '', rawValue.billingEntity?.value.metadata.name ?? '' ); this.organizationCollectionService.add(org).subscribe({ @@ -147,7 +147,7 @@ export class OrganizationFormComponent implements OnInit, OnDestroy { const rawValue = this.form.getRawValue(); const org = structuredClone(this.organization); org.spec = { - displayName: rawValue.displayName ?? '', + displayName: rawValue.displayName?.trim() ?? '', billingEntityRef: rawValue.billingEntity?.value.metadata.name, }; this.organizationCollectionService.update(org).subscribe({ diff --git a/src/app/organizations/organization-members-edit/organization-members-edit.component.ts b/src/app/organizations/organization-members-edit/organization-members-edit.component.ts index 1115bc72..14eb978e 100644 --- a/src/app/organizations/organization-members-edit/organization-members-edit.component.ts +++ b/src/app/organizations/organization-members-edit/organization-members-edit.component.ts @@ -170,23 +170,26 @@ export class OrganizationMembersEditComponent implements OnInit { if (!this.form) { return; } - const userNames: string[] = this.form - .getRawValue() - .userRefs?.map((userDetails: { userName: string; selectedRoles: string[] }) => userDetails.userName) - .filter((val: string) => val); + const userNames: Set = new Set(); const rolesToSubjects: Record = {}; - this.form.getRawValue().userRefs?.forEach((userDetails: { userName: string; selectedRoles: string[] }) => { - userDetails.selectedRoles?.forEach((role) => { + + this.form.getRawValue().userRefs?.forEach(({ userName, selectedRoles }) => { + userName = userName?.trim(); + if (!userName) { + return; + } + userNames.add(userName); + selectedRoles?.forEach((role) => { if (!rolesToSubjects[role]) { rolesToSubjects[role] = []; } - rolesToSubjects[role].push(userDetails.userName); + rolesToSubjects[role].push(userName); }); }); forkJoin([ - this.membersService.update(this.newOrganizationMembers(payload.members, userNames)), + this.membersService.update(this.newOrganizationMembers(payload.members, Array.from(userNames))), ...payload.roleBindings.map((roleBinding) => this.rolebindingService.update({ metadata: { ...roleBinding.metadata }, diff --git a/src/app/teams/team-edit/team-edit.component.ts b/src/app/teams/team-edit/team-edit.component.ts index 3af1278f..526c5c6d 100644 --- a/src/app/teams/team-edit/team-edit.component.ts +++ b/src/app/teams/team-edit/team-edit.component.ts @@ -130,13 +130,13 @@ export class TeamEditComponent implements OnInit { private getTeamFromForm(team: Team): Team { const clone = structuredClone(team); - clone.metadata.name = this.form.getRawValue().name; + clone.metadata.name = this.form.getRawValue().name.trim(); clone.spec = { - displayName: this.form.getRawValue().displayName, + displayName: this.form.getRawValue().displayName.trim(), userRefs: this.form .getRawValue() - .userRefs.filter((name?: string) => !!name) - .map((name: string) => ({ name })), + .userRefs.filter((name?: string) => !!name?.trim()) + .map((name: string) => ({ name: name.trim() })), }; return clone; }