From d9644b13f7829d23cc6e85d8da29a94a54870045 Mon Sep 17 00:00:00 2001 From: Francisco Savala Date: Tue, 21 May 2024 00:48:55 -0300 Subject: [PATCH 1/5] Added unified countries for InstructorRequestForm --- .../instructor-request-form.component.ts | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/src/web/app/pages-static/request-page/instructor-request-form/instructor-request-form.component.ts b/src/web/app/pages-static/request-page/instructor-request-form/instructor-request-form.component.ts index 7caa14e3bd9..f74b0597ca3 100644 --- a/src/web/app/pages-static/request-page/instructor-request-form/instructor-request-form.component.ts +++ b/src/web/app/pages-static/request-page/instructor-request-form/instructor-request-form.component.ts @@ -116,10 +116,21 @@ export class InstructorRequestFormComponent { const email = this.email.value!.trim(); const comments = this.comments.value!.trim(); + // Country Mapping + const countryMapping: { [key: string]: string } = { + 'United States': 'USA', + 'US': 'USA', + 'America': 'USA', + 'UK': 'United Kingdom', + 'Deutschland': 'Germany', + }; + + // Combine country and institution const country = this.country.value!.trim(); + const mappedCountry = countryMapping[country] || country; const institution = this.institution.value!.trim(); - const combinedInstitution = `${institution}, ${country}`; + const combinedInstitution = `${institution}, ${mappedCountry}`; const requestData: AccountCreateRequest = { instructorEmail: email, From b9bc5d34736f20ed4b2481e886152379474a0693 Mon Sep 17 00:00:00 2001 From: Francisco Savala Date: Tue, 21 May 2024 00:53:02 -0300 Subject: [PATCH 2/5] Added tests for InstructorRequestForm for unified countries --- .../instructor-request-form.component.spec.ts | 20 +++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/src/web/app/pages-static/request-page/instructor-request-form/instructor-request-form.component.spec.ts b/src/web/app/pages-static/request-page/instructor-request-form/instructor-request-form.component.spec.ts index a0c9bbac2f2..6febc947772 100644 --- a/src/web/app/pages-static/request-page/instructor-request-form/instructor-request-form.component.spec.ts +++ b/src/web/app/pages-static/request-page/instructor-request-form/instructor-request-form.component.spec.ts @@ -114,4 +114,24 @@ describe('InstructorRequestFormComponent', () => { expect(accountService.createAccountRequest).toHaveBeenCalledTimes(1); expect(accountService.createAccountRequest).toHaveBeenCalledWith(expect.objectContaining(typicalCreateRequest)); }); + + it('should auto-unify country when applicable', () => { + jest.spyOn(accountService, 'createAccountRequest').mockReturnValue( + new Observable((subscriber) => { subscriber.next(); })); + const unitedStatesModel: InstructorRequestFormModel = { + ...typicalModel, + country: 'US', + }; + const unitedStatesCreateRequest: AccountCreateRequest = { + ...typicalCreateRequest, + instructorInstitution: `${unitedStatesModel.institution}, USA`, + }; + fillFormWith(unitedStatesModel); + component.onSubmit() + + expect(accountService.createAccountRequest).toHaveBeenCalledTimes(1); + expect(accountService.createAccountRequest).toHaveBeenCalledWith(expect.objectContaining(unitedStatesCreateRequest)); + + }); + }); From b9793d0097f070a1430fd2cc058469fee414f03f Mon Sep 17 00:00:00 2001 From: Francisco Savala Date: Tue, 21 May 2024 08:01:28 -0300 Subject: [PATCH 3/5] Fixed lint errors for InstructorRequestForm --- .../instructor-request-form.component.spec.ts | 6 +++--- .../instructor-request-form.component.ts | 9 ++++----- 2 files changed, 7 insertions(+), 8 deletions(-) diff --git a/src/web/app/pages-static/request-page/instructor-request-form/instructor-request-form.component.spec.ts b/src/web/app/pages-static/request-page/instructor-request-form/instructor-request-form.component.spec.ts index 6febc947772..3cda7345d34 100644 --- a/src/web/app/pages-static/request-page/instructor-request-form/instructor-request-form.component.spec.ts +++ b/src/web/app/pages-static/request-page/instructor-request-form/instructor-request-form.component.spec.ts @@ -127,11 +127,11 @@ describe('InstructorRequestFormComponent', () => { instructorInstitution: `${unitedStatesModel.institution}, USA`, }; fillFormWith(unitedStatesModel); - component.onSubmit() + component.onSubmit(); expect(accountService.createAccountRequest).toHaveBeenCalledTimes(1); - expect(accountService.createAccountRequest).toHaveBeenCalledWith(expect.objectContaining(unitedStatesCreateRequest)); - + expect(accountService.createAccountRequest).toHaveBeenCalledWith( + expect.objectContaining(unitedStatesCreateRequest)); }); }); diff --git a/src/web/app/pages-static/request-page/instructor-request-form/instructor-request-form.component.ts b/src/web/app/pages-static/request-page/instructor-request-form/instructor-request-form.component.ts index f74b0597ca3..c3ddba3de92 100644 --- a/src/web/app/pages-static/request-page/instructor-request-form/instructor-request-form.component.ts +++ b/src/web/app/pages-static/request-page/instructor-request-form/instructor-request-form.component.ts @@ -119,13 +119,12 @@ export class InstructorRequestFormComponent { // Country Mapping const countryMapping: { [key: string]: string } = { 'United States': 'USA', - 'US': 'USA', - 'America': 'USA', - 'UK': 'United Kingdom', - 'Deutschland': 'Germany', + US: 'USA', + America: 'USA', + UK: 'United Kingdom', + Deutschland: 'Germany', }; - // Combine country and institution const country = this.country.value!.trim(); const mappedCountry = countryMapping[country] || country; From 8f0f807367d8b1f1e5bb24e4c3ba73e12ca8c697 Mon Sep 17 00:00:00 2001 From: Francisco Savala Date: Sat, 1 Jun 2024 01:00:14 -0300 Subject: [PATCH 4/5] Added countries and moved countrymapping --- .../instructor-request-form.component.spec.ts | 4 +-- .../instructor-request-form.component.ts | 25 +++++++++++-------- 2 files changed, 17 insertions(+), 12 deletions(-) diff --git a/src/web/app/pages-static/request-page/instructor-request-form/instructor-request-form.component.spec.ts b/src/web/app/pages-static/request-page/instructor-request-form/instructor-request-form.component.spec.ts index 3cda7345d34..ff055296c3c 100644 --- a/src/web/app/pages-static/request-page/instructor-request-form/instructor-request-form.component.spec.ts +++ b/src/web/app/pages-static/request-page/instructor-request-form/instructor-request-form.component.spec.ts @@ -120,11 +120,11 @@ describe('InstructorRequestFormComponent', () => { new Observable((subscriber) => { subscriber.next(); })); const unitedStatesModel: InstructorRequestFormModel = { ...typicalModel, - country: 'US', + country: 'españa', }; const unitedStatesCreateRequest: AccountCreateRequest = { ...typicalCreateRequest, - instructorInstitution: `${unitedStatesModel.institution}, USA`, + instructorInstitution: `${unitedStatesModel.institution}, Spain`, }; fillFormWith(unitedStatesModel); component.onSubmit(); diff --git a/src/web/app/pages-static/request-page/instructor-request-form/instructor-request-form.component.ts b/src/web/app/pages-static/request-page/instructor-request-form/instructor-request-form.component.ts index c3ddba3de92..929cbf33cf0 100644 --- a/src/web/app/pages-static/request-page/instructor-request-form/instructor-request-form.component.ts +++ b/src/web/app/pages-static/request-page/instructor-request-form/instructor-request-form.component.ts @@ -23,6 +23,20 @@ export class InstructorRequestFormComponent { readonly COUNTRY_NAME_MAX_LENGTH = FormValidator.COUNTRY_NAME_MAX_LENGTH; readonly EMAIL_MAX_LENGTH = FormValidator.EMAIL_MAX_LENGTH; + // Country Mapping + countryMapping: { [key: string]: string } = { + 'united states': 'USA', + us: 'USA', + america: 'USA', + uk: 'United Kingdom', + deutschland: 'Germany', + 'united arab emirates': 'UAE', + españa: 'Spain', + méxico: 'Mexico', + belgië: 'Belgium', + holland: 'Netherlands', + }; + // Captcha captchaSiteKey: string = environment.captchaSiteKey; isCaptchaSuccessful: boolean = false; @@ -116,18 +130,9 @@ export class InstructorRequestFormComponent { const email = this.email.value!.trim(); const comments = this.comments.value!.trim(); - // Country Mapping - const countryMapping: { [key: string]: string } = { - 'United States': 'USA', - US: 'USA', - America: 'USA', - UK: 'United Kingdom', - Deutschland: 'Germany', - }; - // Combine country and institution const country = this.country.value!.trim(); - const mappedCountry = countryMapping[country] || country; + const mappedCountry = this.countryMapping[country.toLowerCase()] || country; const institution = this.institution.value!.trim(); const combinedInstitution = `${institution}, ${mappedCountry}`; From fb8190a4acdb68e5039dcc8dcb71c2e79267b97e Mon Sep 17 00:00:00 2001 From: Francisco Savala Date: Sat, 1 Jun 2024 09:19:55 -0300 Subject: [PATCH 5/5] Tests Fixed --- .../instructor-request-form.component.ts | 30 +++++++++---------- 1 file changed, 14 insertions(+), 16 deletions(-) diff --git a/src/web/app/pages-static/request-page/instructor-request-form/instructor-request-form.component.ts b/src/web/app/pages-static/request-page/instructor-request-form/instructor-request-form.component.ts index 929cbf33cf0..a5fd36e8e38 100644 --- a/src/web/app/pages-static/request-page/instructor-request-form/instructor-request-form.component.ts +++ b/src/web/app/pages-static/request-page/instructor-request-form/instructor-request-form.component.ts @@ -23,20 +23,6 @@ export class InstructorRequestFormComponent { readonly COUNTRY_NAME_MAX_LENGTH = FormValidator.COUNTRY_NAME_MAX_LENGTH; readonly EMAIL_MAX_LENGTH = FormValidator.EMAIL_MAX_LENGTH; - // Country Mapping - countryMapping: { [key: string]: string } = { - 'united states': 'USA', - us: 'USA', - america: 'USA', - uk: 'United Kingdom', - deutschland: 'Germany', - 'united arab emirates': 'UAE', - españa: 'Spain', - méxico: 'Mexico', - belgië: 'Belgium', - holland: 'Netherlands', - }; - // Captcha captchaSiteKey: string = environment.captchaSiteKey; isCaptchaSuccessful: boolean = false; @@ -129,10 +115,22 @@ export class InstructorRequestFormComponent { const name = this.name.value!.trim(); const email = this.email.value!.trim(); const comments = this.comments.value!.trim(); - + // Country Mapping + const countryMapping: { [key: string]: string } = { + 'united states': 'USA', + us: 'USA', + america: 'USA', + uk: 'United Kingdom', + deutschland: 'Germany', + 'united arab emirates': 'UAE', + españa: 'Spain', + méxico: 'Mexico', + belgië: 'Belgium', + holland: 'Netherlands', + }; // Combine country and institution const country = this.country.value!.trim(); - const mappedCountry = this.countryMapping[country.toLowerCase()] || country; + const mappedCountry = countryMapping[country.toLowerCase()] || country; const institution = this.institution.value!.trim(); const combinedInstitution = `${institution}, ${mappedCountry}`;