Skip to content

Commit 06958cb

Browse files
eternauta123jhosefmarks
authored andcommitted
feat(page-login): remember language stored
1 parent 0b7e409 commit 06958cb

File tree

5 files changed

+28
-11
lines changed

5 files changed

+28
-11
lines changed

projects/templates/src/lib/components/po-page-background/po-page-background.component.spec.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import * as utilFunctions from './../../utils/util';
55
import { expectPropertiesValues } from './../../util-test/util-expect.spec';
66

77
import { PoPageBackgroundComponent } from './po-page-background.component';
8+
import { PoLanguageService } from '@po-ui/ng-components';
89

910
describe('PoPageBackgroundComponent:', () => {
1011
let component: PoPageBackgroundComponent;
@@ -76,10 +77,10 @@ describe('PoPageBackgroundComponent:', () => {
7677
});
7778

7879
describe('Methods:', () => {
79-
it('ngOnInit: should get the browserLanguage and apply it to `selectedLanguageOption`', () => {
80+
it('ngOnInit: should get the stored language on localstorage (or browserLanguage by default if en, pt, es or ru) and apply it to `selectedLanguageOption`', () => {
8081
component.ngOnInit();
81-
82-
expect(component.selectedLanguageOption).toBe(utilFunctions.browserLanguage());
82+
const languageService = new PoLanguageService();
83+
expect(component.selectedLanguageOption).toBe(languageService.getShortLanguage());
8384
});
8485

8586
it('onChangeLanguage: should emit `selectedLanguage`', () => {

projects/templates/src/lib/components/po-page-background/po-page-background.component.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { Component, EventEmitter, Input, OnInit, Output } from '@angular/core';
22

33
import { browserLanguage, convertToBoolean, isTypeof } from './../../utils/util';
44
import { PoSelectOption } from '@po-ui/ng-components';
5+
import { PoLanguageService } from '@po-ui/ng-components';
56

67
@Component({
78
selector: 'po-page-background',
@@ -77,8 +78,10 @@ export class PoPageBackgroundComponent implements OnInit {
7778
*/
7879
@Output('p-selected-language') selectedLanguage?: EventEmitter<any> = new EventEmitter<any>();
7980

81+
constructor(public poLanguageService: PoLanguageService) {}
82+
8083
ngOnInit() {
81-
this.selectedLanguageOption = browserLanguage();
84+
this.selectedLanguageOption = this.poLanguageService.getShortLanguage();
8285
}
8386

8487
onChangeLanguage() {

projects/templates/src/lib/components/po-page-login/po-page-login-base.component.spec.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,11 @@ import * as UtilFunctions from './../../utils/util';
99
import { PoPageLoginBaseComponent, poPageLoginLiteralsDefault } from './po-page-login-base.component';
1010
import { PoPageLoginCustomField } from './interfaces/po-page-login-custom-field.interface';
1111
import { PoPageLoginService } from './po-page-login.service';
12+
import { PoLanguageService } from '@po-ui/ng-components';
1213

1314
const routerStub = {
1415
navigate: jasmine.createSpy('navigate')
1516
};
16-
17-
@Directive()
1817
export class PoPageLoginComponent extends PoPageLoginBaseComponent {
1918
protected concatenateLoginHintWithContactEmail(contactEmail: string): void {}
2019
protected concatenateTitleWithProductName(productName: string): void {}
@@ -25,11 +24,12 @@ export class PoPageLoginComponent extends PoPageLoginBaseComponent {
2524
describe('PoPageLoginBaseComponent: ', () => {
2625
let component: PoPageLoginBaseComponent;
2726
let servicePageLogin: PoPageLoginService;
27+
let languageService: PoLanguageService;
2828

2929
beforeEach(async(() => {
3030
TestBed.configureTestingModule({
3131
declarations: [],
32-
providers: [PoPageLoginService]
32+
providers: [PoPageLoginService, PoLanguageService]
3333
}).compileComponents();
3434
}));
3535

@@ -39,7 +39,9 @@ describe('PoPageLoginBaseComponent: ', () => {
3939

4040
beforeEach(() => {
4141
servicePageLogin = new PoPageLoginService(undefined);
42-
component = new PoPageLoginComponent(servicePageLogin, <any>routerStub);
42+
languageService = new PoLanguageService();
43+
44+
component = new PoPageLoginComponent(servicePageLogin, <any>routerStub, languageService);
4345
});
4446

4547
it('should be created', () => {

projects/templates/src/lib/components/po-page-login/po-page-login-base.component.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ import {
1111
poLocaleDefault
1212
} from './../../utils/util';
1313

14+
import { PoLanguageService } from '@po-ui/ng-components';
15+
1416
import { PoPageLogin } from './interfaces/po-page-login.interface';
1517
import { PoPageLoginAuthenticationType } from './enums/po-page-login-authentication-type.enum';
1618
import { PoPageLoginCustomField } from './interfaces/po-page-login-custom-field.interface';
@@ -884,7 +886,13 @@ export abstract class PoPageLoginBaseComponent implements OnDestroy {
884886
};
885887
}
886888

887-
constructor(private loginService: PoPageLoginService, public router: Router) {}
889+
constructor(
890+
private loginService: PoPageLoginService,
891+
public router: Router,
892+
public poLanguageService: PoLanguageService
893+
) {
894+
this.selectedLanguage = this.poLanguageService.getShortLanguage();
895+
}
888896

889897
ngOnDestroy() {
890898
if (this.loginSubscription) {

projects/templates/src/lib/components/po-page-login/po-page-login.component.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ import {
1111
ViewContainerRef
1212
} from '@angular/core';
1313

14+
import { PoLanguageService } from '@po-ui/ng-components';
15+
1416
import { isExternalLink } from '../../utils/util';
1517
import { PoComponentInjectorService } from '@po-ui/ng-components';
1618

@@ -69,9 +71,10 @@ export class PoPageLoginComponent extends PoPageLoginBaseComponent implements Af
6971
private poComponentInjector: PoComponentInjectorService,
7072
differs: IterableDiffers,
7173
loginService: PoPageLoginService,
72-
router: Router
74+
router: Router,
75+
poLanguageService: PoLanguageService
7376
) {
74-
super(loginService, router);
77+
super(loginService, router, poLanguageService);
7578
this.differ = differs.find([]).create(null);
7679
}
7780

0 commit comments

Comments
 (0)