Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

🦺 trim texts input by user #560

Merged
merged 2 commits into from
Sep 7, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 10 additions & 10 deletions cypress/e2e/billingentity-form.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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('[email protected],');
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(' [email protected],');
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')
Expand Down Expand Up @@ -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('[email protected]{enter}');
cy.get('#phone').type('{selectAll}1234');
cy.get('#line1').type('{selectAll}line1');
Expand Down
2 changes: 1 addition & 1 deletion cypress/e2e/billingentity-members.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down
2 changes: 1 addition & 1 deletion cypress/e2e/invitations-create.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ describe('Test invitation create', () => {
cy.visit('/invitations/create');

cy.get('#title').should('contain.text', 'Invite User');
cy.get('#email').type('[email protected]');
cy.get('#email').type('[email protected] ');
cy.get('#note').type('New Employee working for 👁️');

cy.get('p-checkbox input').should('be.disabled');
Expand Down
4 changes: 2 additions & 2 deletions cypress/e2e/organization-form.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down Expand Up @@ -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');
Expand Down
4 changes: 2 additions & 2 deletions cypress/e2e/organization-members.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down Expand Up @@ -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')
Expand Down
8 changes: 4 additions & 4 deletions cypress/e2e/teams.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down Expand Up @@ -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')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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: [],
},
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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({
Expand All @@ -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({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<string> = new Set();
const rolesToSubjects: Record<string, string[]> = {};
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 },
Expand Down
8 changes: 4 additions & 4 deletions src/app/teams/team-edit/team-edit.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
Loading