From 12d3e03055aebf497c9873c188c8da5131b9d097 Mon Sep 17 00:00:00 2001 From: suschneider <57661483+suschneider@users.noreply.github.com> Date: Wed, 26 Feb 2020 13:51:53 +0100 Subject: [PATCH] fix: remove preferred language management in user profile (#120) --- .../account/profile-edit-details.page.ts | 4 +- .../integration/pages/account/profile.page.ts | 4 -- ...it-user-preferred-language.b2c.e2e-spec.ts | 68 ------------------- .../account-profile-user.component.html | 6 -- .../account-profile-user.component.spec.ts | 7 -- .../account-profile-user.component.ts | 9 +-- .../account-profile.component.html | 2 - .../account-profile.component.ts | 18 +---- .../registration-form.component.html | 6 +- .../registration/registration-page.module.ts | 2 - .../registration-personal-form.component.html | 9 --- ...gistration-personal-form.component.spec.ts | 58 ---------------- .../registration-personal-form.component.ts | 34 ---------- .../select-language.component.spec.ts | 66 ------------------ .../select-language.component.ts | 33 --------- src/app/shared/forms/forms.module.ts | 2 - src/assets/i18n/de_DE.json | 1 - src/assets/i18n/en_US.json | 1 - src/assets/i18n/fr_FR.json | 1 - 19 files changed, 5 insertions(+), 326 deletions(-) delete mode 100644 e2e/cypress/integration/specs/account/edit-user-preferred-language.b2c.e2e-spec.ts delete mode 100644 src/app/pages/registration/registration-personal-form/registration-personal-form.component.html delete mode 100644 src/app/pages/registration/registration-personal-form/registration-personal-form.component.spec.ts delete mode 100644 src/app/pages/registration/registration-personal-form/registration-personal-form.component.ts delete mode 100644 src/app/shared/forms/components/select-language/select-language.component.spec.ts delete mode 100644 src/app/shared/forms/components/select-language/select-language.component.ts diff --git a/e2e/cypress/integration/pages/account/profile-edit-details.page.ts b/e2e/cypress/integration/pages/account/profile-edit-details.page.ts index 2b511a2840..d25b22045a 100644 --- a/e2e/cypress/integration/pages/account/profile-edit-details.page.ts +++ b/e2e/cypress/integration/pages/account/profile-edit-details.page.ts @@ -2,9 +2,7 @@ import { fillFormField } from '../../framework'; import { Registration } from './registration.page'; -export type ProfileEditDetailsTypes = Partial< - Pick ->; +export type ProfileEditDetailsTypes = Partial>; export class ProfileEditDetailsPage { readonly tag = 'ish-account-profile-user'; diff --git a/e2e/cypress/integration/pages/account/profile.page.ts b/e2e/cypress/integration/pages/account/profile.page.ts index 2d4bfea449..f0ffc01446 100644 --- a/e2e/cypress/integration/pages/account/profile.page.ts +++ b/e2e/cypress/integration/pages/account/profile.page.ts @@ -33,10 +33,6 @@ export class ProfilePage { return cy.get(this.tag).find('[data-testing-id="phone-field"]'); } - get preferredLanguage() { - return cy.get(this.tag).find('[data-testing-id="preferred-language-field"]'); - } - get companyName() { return cy.get(this.tag).find('[data-testing-id="company-field"]'); } diff --git a/e2e/cypress/integration/specs/account/edit-user-preferred-language.b2c.e2e-spec.ts b/e2e/cypress/integration/specs/account/edit-user-preferred-language.b2c.e2e-spec.ts deleted file mode 100644 index 38fb7c872a..0000000000 --- a/e2e/cypress/integration/specs/account/edit-user-preferred-language.b2c.e2e-spec.ts +++ /dev/null @@ -1,68 +0,0 @@ -import { at } from '../../framework'; -import { createUserViaREST } from '../../framework/users'; -import { LoginPage } from '../../pages/account/login.page'; -import { ProfileEditDetailsPage } from '../../pages/account/profile-edit-details.page'; -import { ProfilePage } from '../../pages/account/profile.page'; -import { SupportedLanguage, sensibleDefaults } from '../../pages/account/registration.page'; - -const _ = { - user: { login: `testuser${new Date().getTime()}@test.intershop.de`, ...sensibleDefaults }, - catalog: { - id: 'Cameras-Camcorders', - englishName: 'Cameras', - germanName: 'Kameras', - }, - lang: { - en: { - displayName: 'English (United States)', - }, - de: { - selector: 'de_DE' as SupportedLanguage, - displayName: 'German (Germany)', - }, - }, - pageTitle: { - englishName: 'Profile Settings', - germanName: 'Profileinstellungen', - }, -}; - -describe('Changing User', () => { - before(() => { - createUserViaREST(_.user); - - LoginPage.navigateTo('/account/profile'); - at(LoginPage, page => - page - .fillForm(_.user.login, _.user.password) - .submit() - .its('status') - .should('equal', 200) - ); - }); - - it('should be able to edit preferred language', () => { - at(ProfilePage, page => { - page.title.should('have.text', _.pageTitle.englishName); - page.header.topLevelCategoryLink(_.catalog.id).should('contain', _.catalog.englishName); - page.preferredLanguage.should('have.text', _.lang.en.displayName); - page.editDetails(); - }); - - at(ProfileEditDetailsPage, page => - page - .fillForm({ preferredLanguage: _.lang.de.selector }) - .submit() - .its('status') - .should('equal', 200) - ); - at(ProfilePage, page => page.preferredLanguage.should('have.text', _.lang.de.displayName)); - }); - - xit('should change the language of the page', () => { - at(ProfilePage, page => { - page.title.should('have.text', _.pageTitle.germanName); - page.header.topLevelCategoryLink(_.catalog.id).should('contain', _.catalog.germanName); - }); - }); -}); diff --git a/src/app/pages/account-profile-user/account-profile-user/account-profile-user.component.html b/src/app/pages/account-profile-user/account-profile-user/account-profile-user.component.html index 058902577b..fbad2a633e 100644 --- a/src/app/pages/account-profile-user/account-profile-user/account-profile-user.component.html +++ b/src/app/pages/account-profile-user/account-profile-user/account-profile-user.component.html @@ -36,12 +36,6 @@

{{ 'account.update_profile.heading' | translate }}

- -
diff --git a/src/app/pages/account-profile/account-profile/account-profile.component.ts b/src/app/pages/account-profile/account-profile/account-profile.component.ts index 80a089bd4a..1960e7ec00 100644 --- a/src/app/pages/account-profile/account-profile/account-profile.component.ts +++ b/src/app/pages/account-profile/account-profile/account-profile.component.ts @@ -1,8 +1,6 @@ -import { ChangeDetectionStrategy, Component, Inject, Input } from '@angular/core'; +import { ChangeDetectionStrategy, Component, Input } from '@angular/core'; -import { AVAILABLE_LOCALES } from 'ish-core/configurations/injection-keys'; import { Customer } from 'ish-core/models/customer/customer.model'; -import { Locale } from 'ish-core/models/locale/locale.model'; import { User } from 'ish-core/models/user/user.model'; @Component({ @@ -13,18 +11,4 @@ import { User } from 'ish-core/models/user/user.model'; export class AccountProfileComponent { @Input() user: User; @Input() customer: Customer; - - constructor(@Inject(AVAILABLE_LOCALES) public locales: Locale[]) {} - - get preferredLanguageName(): string { - if ( - !this.user || - !this.user.preferredLanguage || - !this.locales || - !this.locales.some(locale => locale.lang === this.user.preferredLanguage) - ) { - return ''; - } - return this.locales.find(locale => locale.lang === this.user.preferredLanguage).displayLong; - } } diff --git a/src/app/pages/registration/registration-form/registration-form.component.html b/src/app/pages/registration/registration-form/registration-form.component.html index d6bb4bebe5..e1c43ace3b 100644 --- a/src/app/pages/registration/registration-form/registration-form.component.html +++ b/src/app/pages/registration/registration-form/registration-form.component.html @@ -39,10 +39,8 @@

- - - - - diff --git a/src/app/pages/registration/registration-personal-form/registration-personal-form.component.spec.ts b/src/app/pages/registration/registration-personal-form/registration-personal-form.component.spec.ts deleted file mode 100644 index 43fb089280..0000000000 --- a/src/app/pages/registration/registration-personal-form/registration-personal-form.component.spec.ts +++ /dev/null @@ -1,58 +0,0 @@ -import { ComponentFixture, TestBed, async } from '@angular/core/testing'; -import { FormControl, FormGroup, ReactiveFormsModule } from '@angular/forms'; -import { MockComponent } from 'ng-mocks'; - -import { InputBirthdayComponent } from 'ish-shared/forms/components/input-birthday/input-birthday.component'; -import { SelectLanguageComponent } from 'ish-shared/forms/components/select-language/select-language.component'; - -import { RegistrationPersonalFormComponent } from './registration-personal-form.component'; - -describe('Registration Personal Form Component', () => { - let component: RegistrationPersonalFormComponent; - let fixture: ComponentFixture; - let element: HTMLElement; - - beforeEach(async(() => { - TestBed.configureTestingModule({ - declarations: [ - MockComponent(InputBirthdayComponent), - MockComponent(SelectLanguageComponent), - RegistrationPersonalFormComponent, - ], - imports: [ReactiveFormsModule], - }) - .compileComponents() - .then(() => { - fixture = TestBed.createComponent(RegistrationPersonalFormComponent); - component = fixture.componentInstance; - element = fixture.nativeElement; - - const parentForm = new FormGroup({ - preferredLanguage: new FormControl(), - birthday: new FormControl(), - }); - component.parentForm = parentForm; - }); - })); - - it('should be created', () => { - expect(component).toBeTruthy(); - expect(element).toBeTruthy(); - expect(() => fixture.detectChanges()).not.toThrow(); - }); - - it('should throw an error if input parameter parentForm is not set', () => { - component.parentForm = undefined; - expect(() => fixture.detectChanges()).toThrow(); - }); - - it('should throw an error if control preferredLanguage does not exist', () => { - component.parentForm.removeControl('preferredLanguage'); - expect(() => fixture.detectChanges()).toThrowError(/.*required.*preferredLanguage.*/); - }); - - it('should throw an error if control birthday does not exist', () => { - component.parentForm.removeControl('birthday'); - expect(() => fixture.detectChanges()).toThrowError(/.*required.*birthday.*/); - }); -}); diff --git a/src/app/pages/registration/registration-personal-form/registration-personal-form.component.ts b/src/app/pages/registration/registration-personal-form/registration-personal-form.component.ts deleted file mode 100644 index c6e1e357df..0000000000 --- a/src/app/pages/registration/registration-personal-form/registration-personal-form.component.ts +++ /dev/null @@ -1,34 +0,0 @@ -import { ChangeDetectionStrategy, Component, Input, OnInit } from '@angular/core'; -import { FormGroup } from '@angular/forms'; - -import { Locale } from 'ish-core/models/locale/locale.model'; - -@Component({ - selector: 'ish-registration-personal-form', - templateUrl: './registration-personal-form.component.html', - changeDetection: ChangeDetectionStrategy.OnPush, -}) -export class RegistrationPersonalFormComponent implements OnInit { - @Input() parentForm: FormGroup; - @Input() languages: Locale[]; - - ngOnInit() { - this.checkRequired(); - } - - private checkRequired() { - if (!this.parentForm) { - throw new Error('required input parameter is missing for RegistrationPersonalFormComponent'); - } - if (!this.parentForm.get('preferredLanguage')) { - throw new Error( - 'required form control is missing for parentForm of RegistrationPersonalFormComponent' - ); - } - if (!this.parentForm.get('birthday')) { - throw new Error( - 'required form control is missing for parentForm of RegistrationPersonalFormComponent' - ); - } - } -} diff --git a/src/app/shared/forms/components/select-language/select-language.component.spec.ts b/src/app/shared/forms/components/select-language/select-language.component.spec.ts deleted file mode 100644 index fb1f3d872a..0000000000 --- a/src/app/shared/forms/components/select-language/select-language.component.spec.ts +++ /dev/null @@ -1,66 +0,0 @@ -import { SimpleChange, SimpleChanges } from '@angular/core'; -import { ComponentFixture, TestBed, async } from '@angular/core/testing'; -import { FormControl, FormGroup, ReactiveFormsModule } from '@angular/forms'; -import { TranslateModule } from '@ngx-translate/core'; -import { MockComponent, MockDirective } from 'ng-mocks'; - -import { Locale } from 'ish-core/models/locale/locale.model'; -import { FormControlFeedbackComponent } from 'ish-shared/forms/components/form-control-feedback/form-control-feedback.component'; -import { ShowFormFeedbackDirective } from 'ish-shared/forms/directives/show-form-feedback.directive'; - -import { SelectLanguageComponent } from './select-language.component'; - -describe('Select Language Component', () => { - let component: SelectLanguageComponent; - let fixture: ComponentFixture; - let element: HTMLElement; - - beforeEach(async(() => { - TestBed.configureTestingModule({ - declarations: [ - MockComponent(FormControlFeedbackComponent), - MockDirective(ShowFormFeedbackDirective), - SelectLanguageComponent, - ], - imports: [ReactiveFormsModule, TranslateModule.forRoot()], - }) - .compileComponents() - .then(() => { - fixture = TestBed.createComponent(SelectLanguageComponent); - component = fixture.componentInstance; - element = fixture.nativeElement; - - const form = new FormGroup({ - preferredLanguage: new FormControl('en_US'), - }); - component.form = form; - - component.languages = [ - { lang: 'en_US', value: 'en', displayName: 'English' }, - { lang: 'de_DE', value: 'de', displayName: 'Deutsch' }, - ] as Locale[]; - }); - })); - - it('should be created', () => { - expect(component).toBeTruthy(); - expect(element).toBeTruthy(); - expect(() => fixture.detectChanges()).not.toThrow(); - }); - - it('should set default values properly on creation', () => { - fixture.detectChanges(); - expect(component.controlName).toEqual('preferredLanguage'); - expect(component.label).toEqual('account.default_address.preferred_language.label'); - }); - - it('should get and display languages on creation', () => { - const changes: SimpleChanges = { - languages: new SimpleChange(undefined, component.languages, false), - }; - component.ngOnChanges(changes); - fixture.detectChanges(); - expect(component.options).toHaveLength(2); // ToDo: languages are retrieved from a service - expect(element.querySelector('[data-testing-id=preferredLanguage]')).toBeTruthy(); - }); -}); diff --git a/src/app/shared/forms/components/select-language/select-language.component.ts b/src/app/shared/forms/components/select-language/select-language.component.ts deleted file mode 100644 index d66706792c..0000000000 --- a/src/app/shared/forms/components/select-language/select-language.component.ts +++ /dev/null @@ -1,33 +0,0 @@ -import { ChangeDetectionStrategy, Component, Input, OnChanges, SimpleChanges } from '@angular/core'; - -import { Locale } from 'ish-core/models/locale/locale.model'; -import { SelectComponent, SelectOption } from 'ish-shared/forms/components/select/select.component'; - -@Component({ - selector: 'ish-select-language', - templateUrl: '../select/select.component.html', - changeDetection: ChangeDetectionStrategy.Default, -}) -export class SelectLanguageComponent extends SelectComponent implements OnChanges { - @Input() languages: Locale[]; - @Input() controlName = 'preferredLanguage'; - @Input() label = 'account.default_address.preferred_language.label'; - @Input() errorMessages = { required: 'Please select a preferred language' }; // ToDo: Translation key - - ngOnChanges(c: SimpleChanges) { - if (c.languages) { - this.options = this.mapToOptions(this.languages); - } - } - - private mapToOptions(languages: Locale[]): SelectOption[] { - // TODO: insert type - if (!languages) { - return; - } - return languages.map(lang => ({ - label: lang.displayLong, - value: lang.lang, - })); - } -} diff --git a/src/app/shared/forms/forms.module.ts b/src/app/shared/forms/forms.module.ts index 205f558f49..4dc79b4489 100644 --- a/src/app/shared/forms/forms.module.ts +++ b/src/app/shared/forms/forms.module.ts @@ -19,7 +19,6 @@ import { InputComponent } from './components/input/input.component'; import { LoginFormComponent } from './components/login-form/login-form.component'; import { SelectAddressComponent } from './components/select-address/select-address.component'; import { SelectCountryComponent } from './components/select-country/select-country.component'; -import { SelectLanguageComponent } from './components/select-language/select-language.component'; import { SelectRegionComponent } from './components/select-region/select-region.component'; import { SelectSecurityQuestionComponent } from './components/select-security-question/select-security-question.component'; import { SelectTitleComponent } from './components/select-title/select-title.component'; @@ -41,7 +40,6 @@ const exportedComponents = [ SelectAddressComponent, SelectComponent, SelectCountryComponent, - SelectLanguageComponent, SelectRegionComponent, SelectSecurityQuestionComponent, SelectTitleComponent, diff --git a/src/assets/i18n/de_DE.json b/src/assets/i18n/de_DE.json index dce0cd5f70..a63b22a77e 100644 --- a/src/assets/i18n/de_DE.json +++ b/src/assets/i18n/de_DE.json @@ -587,7 +587,6 @@ "account.profile.gender.unknown.label": "keine Angabe", "account.profile.heading": "Profileinstellungen", "account.profile.information.privacy.message": "Hinweis: Diese Informationen werden nur verwendet in Übereinstimmung mit dem Datenschutz, siehe", - "account.profile.language.label": "Sprache", "account.profile.link": "Profileinstellungen", "account.profile.name.label": "Name", "account.profile.newsletter.text": "Newsletter", diff --git a/src/assets/i18n/en_US.json b/src/assets/i18n/en_US.json index 296793c1c5..0ec46e453b 100644 --- a/src/assets/i18n/en_US.json +++ b/src/assets/i18n/en_US.json @@ -587,7 +587,6 @@ "account.profile.gender.unknown.label": "decline", "account.profile.heading": "Profile Settings", "account.profile.information.privacy.message": "Note: This information will only be used in accordance with our", - "account.profile.language.label": "Language", "account.profile.link": "Profile Settings", "account.profile.name.label": "Name", "account.profile.newsletter.text": "Newsletter E-mails", diff --git a/src/assets/i18n/fr_FR.json b/src/assets/i18n/fr_FR.json index 072e5c3c1e..ce40991cb7 100644 --- a/src/assets/i18n/fr_FR.json +++ b/src/assets/i18n/fr_FR.json @@ -587,7 +587,6 @@ "account.profile.gender.unknown.label": "refuser", "account.profile.heading": "Paramètres de profil", "account.profile.information.privacy.message": "Remarque : Ces informations ne seront utilisées que conformément à notre", - "account.profile.language.label": "Langue", "account.profile.link": "Paramètres de profil", "account.profile.name.label": "Nom", "account.profile.newsletter.text": "Courriels newsletter",