Skip to content

Commit

Permalink
ISREST-677: adjust model and interface
Browse files Browse the repository at this point in the history
  • Loading branch information
skoch-intershop committed Mar 27, 2019
1 parent 1a1cb73 commit 478baab
Show file tree
Hide file tree
Showing 10 changed files with 21 additions and 14 deletions.
2 changes: 2 additions & 0 deletions src/app/core/models/address/address.interface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ export interface AddressData {
postalCode: string;
city: string;
mainDivision?: string;
mainDivisionCode?: string;
mainDivisionName?: string;
country: string;
countryCode: string;
phoneHome: string;
Expand Down
3 changes: 2 additions & 1 deletion src/app/core/models/address/address.mapper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ export class AddressMapper {
addressLine3: data.addressLine3,
postalCode: data.postalCode,
city: data.city,
mainDivision: data.mainDivision,
mainDivision: data.mainDivisionName || data.mainDivision,
mainDivisionCode: data.mainDivisionCode || data.mainDivision,
country: data.country,
countryCode: data.countryCode,
phoneHome: data.phoneHome,
Expand Down
1 change: 1 addition & 0 deletions src/app/core/models/address/address.model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ export interface Address {
postalCode: string;
city: string;
mainDivision?: string;
mainDivisionCode?: string;
country: string;
countryCode: string;
phoneHome: string;
Expand Down
7 changes: 3 additions & 4 deletions src/app/core/store/countries/countries.effects.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import { TestBed } from '@angular/core/testing';
import { provideMockActions } from '@ngrx/effects/testing';
import { Action, StoreModule } from '@ngrx/store';
import { cold, hot } from 'jest-marbles';
import { ROUTER_NAVIGATION_TYPE } from 'ngrx-router';
import { Observable, of, throwError } from 'rxjs';
import { instance, mock, when } from 'ts-mockito';

Expand All @@ -11,7 +10,7 @@ import { HttpError } from '../../models/http-error/http-error.model';
import { CountryService } from '../../services/country/country.service';
import { coreReducers } from '../core-store.module';

import { LoadCountriesFail, LoadCountriesSuccess } from './countries.actions';
import { CountryActionTypes, LoadCountriesFail, LoadCountriesSuccess } from './countries.actions';
import { CountriesEffects } from './countries.effects';

describe('Countries Effects', () => {
Expand Down Expand Up @@ -39,7 +38,7 @@ describe('Countries Effects', () => {

describe('loadCountries$', () => {
it('should load all countries on effects init and dispatch a LoadCountriesSuccess action', () => {
const action = { type: ROUTER_NAVIGATION_TYPE } as Action;
const action = { type: CountryActionTypes.LoadCountries } as Action;
const expected = new LoadCountriesSuccess({ countries });

actions$ = hot('-a-------', { a: action });
Expand All @@ -50,7 +49,7 @@ describe('Countries Effects', () => {
it('should dispatch a LoadCountriesFail action if a load error occurs', () => {
when(countryServiceMock.getCountries()).thenReturn(throwError({ message: 'error' }));

const action = { type: ROUTER_NAVIGATION_TYPE } as Action;
const action = { type: CountryActionTypes.LoadCountries } as Action;
const expected = new LoadCountriesFail({ error: { message: 'error' } as HttpError });

actions$ = hot('-a', { a: action });
Expand Down
3 changes: 1 addition & 2 deletions src/app/core/store/countries/countries.effects.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { Injectable } from '@angular/core';
import { Actions, Effect, ofType } from '@ngrx/effects';
import { Store, select } from '@ngrx/store';
import { ROUTER_NAVIGATION_TYPE } from 'ngrx-router';
import { concatMap, filter, map, withLatestFrom } from 'rxjs/operators';

import { mapErrorToAction } from 'ish-core/utils/operators';
Expand All @@ -16,7 +15,7 @@ export class CountriesEffects {

@Effect()
loadCountries$ = this.actions$.pipe(
ofType(ROUTER_NAVIGATION_TYPE),
ofType(countryActions.CountryActionTypes.LoadCountries),
withLatestFrom(this.store.pipe(select(getAllCountries))),
filter(([, countries]) => !countries.length),
concatMap(() =>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import {
Input,
OnChanges,
OnDestroy,
OnInit,
SimpleChanges,
} from '@angular/core';
import { FormGroup, Validators } from '@angular/forms';
Expand All @@ -14,7 +15,7 @@ import { takeUntil } from 'rxjs/operators';

import { FeatureToggleService } from 'ish-core/feature-toggle.module';
import { Region } from 'ish-core/models/region/region.model';
import { getAllCountries, getCountriesLoading } from 'ish-core/store/countries';
import { LoadCountries, getAllCountries, getCountriesLoading } from 'ish-core/store/countries';
import { LoadRegions, getRegionsByCountryCode } from 'ish-core/store/regions';
import { isBusinessCustomer } from 'ish-core/store/user';
import { determineSalutations, updateValidatorsByDataLength } from '../../../forms/utils/form-utils';
Expand All @@ -32,7 +33,7 @@ import { AddressFormFactoryProvider } from '../../configurations/address-form-fa
templateUrl: './address-form.container.html',
changeDetection: ChangeDetectionStrategy.Default,
})
export class AddressFormContainerComponent implements OnChanges, OnDestroy {
export class AddressFormContainerComponent implements OnInit, OnChanges, OnDestroy {
countries$ = this.store.pipe(select(getAllCountries));
loading$ = this.store.pipe(select(getCountriesLoading));

Expand Down Expand Up @@ -68,6 +69,10 @@ export class AddressFormContainerComponent implements OnChanges, OnDestroy {
);
}

ngOnInit() {
this.store.dispatch(new LoadCountries());
}

ngOnChanges(c: SimpleChanges) {
if (c.parentForm) {
const group = this.afs.getFactory('default').getGroup({ isBusinessAddress: this.isBusinessCustomer });
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ describe('Select Country Component', () => {
it('should set default values properly on creation', () => {
fixture.detectChanges();
expect(component.controlName).toEqual('countryCode');
expect(component.label).toEqual('Country');
expect(component.label).toEqual('account.address.country.label');
});

it('should display countries if component input changes', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import { SelectComponent, SelectOption } from '../select/select.component';
export class SelectCountryComponent extends SelectComponent implements OnChanges {
@Input() countries: Country[];
@Input() controlName = 'countryCode';
@Input() label = 'Country';
@Input() label = 'account.address.country.label';
@Input() errorMessages = { required: 'account.address.country.error.default' };

ngOnChanges(c: SimpleChanges) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ describe('Select Region Component', () => {
it('should set default values properly on creation', () => {
fixture.detectChanges();
expect(component.controlName).toEqual('state');
expect(component.label).toEqual('State/Province');
expect(component.label).toEqual('account.default_address.state.label');
});

it('should get and display regions for a certain country', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import { SelectComponent, SelectOption } from '../select/select.component';
export class SelectRegionComponent extends SelectComponent implements OnChanges {
@Input() regions: Region[];
@Input() controlName = 'state';
@Input() label = 'State/Province';
@Input() label = 'account.default_address.state.label';
@Input() errorMessages = { required: 'Please select a region' }; // ToDo: Translation key

ngOnChanges(c: SimpleChanges) {
Expand All @@ -26,7 +26,7 @@ export class SelectRegionComponent extends SelectComponent implements OnChanges
}
return regions.map(r => ({
label: r.name,
value: r.name,
value: r.regionCode,
}));
}
}

0 comments on commit 478baab

Please sign in to comment.