-
Notifications
You must be signed in to change notification settings - Fork 87
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: support for cXML punchout self service configuration (#1683)
Co-authored-by: Stefan Hauke <s.hauke@intershop.de> Co-authored-by: Silke <s.grueber@intershop.de>
- Loading branch information
1 parent
abba089
commit 74bb9cf
Showing
40 changed files
with
1,161 additions
and
40 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
16 changes: 16 additions & 0 deletions
16
src/app/extensions/punchout/models/cxml-configuration/cxml-configuration.interface.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import { CxmlConfigurationInputType } from './cxml-configuration.model'; | ||
|
||
export interface CxmlConfigurationData { | ||
data: { | ||
name: string; | ||
value: string; | ||
}[]; | ||
info?: { | ||
metaData: { | ||
name: string; | ||
defaultValue?: string; | ||
description?: string; | ||
inputType?: CxmlConfigurationInputType; | ||
}[]; | ||
}; | ||
} |
43 changes: 43 additions & 0 deletions
43
src/app/extensions/punchout/models/cxml-configuration/cxml-configuration.mapper.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
import { CxmlConfigurationData } from './cxml-configuration.interface'; | ||
import { CxmlConfigurationMapper } from './cxml-configuration.mapper'; | ||
|
||
describe('Cxml Configuration Mapper', () => { | ||
describe('fromData', () => { | ||
it('should return Cxml Configuration when getting CxmlConfigurationData', () => { | ||
expect(() => CxmlConfigurationMapper.fromData(undefined)).toThrow(); | ||
}); | ||
|
||
it('should map incoming data to model data', () => { | ||
const data: CxmlConfigurationData = { | ||
data: [ | ||
{ | ||
name: 'classificationCatalogID', | ||
value: '1', | ||
}, | ||
], | ||
info: { | ||
metaData: [ | ||
{ | ||
name: 'classificationCatalogID', | ||
defaultValue: 'eCl@ass', | ||
description: 'Enter the type of product classification catalog to be used, e.g. UNSPSC or eCl@ass.', | ||
inputType: 'text-short', | ||
}, | ||
], | ||
}, | ||
}; | ||
const mapped = CxmlConfigurationMapper.fromData(data); | ||
expect(mapped).toMatchInlineSnapshot(` | ||
[ | ||
{ | ||
"defaultValue": "eCl@ass", | ||
"description": "Enter the type of product classification catalog to be used, e.g. UNSPSC or eCl@ass.", | ||
"inputType": "text-short", | ||
"name": "classificationCatalogID", | ||
"value": "1", | ||
}, | ||
] | ||
`); | ||
}); | ||
}); | ||
}); |
25 changes: 25 additions & 0 deletions
25
src/app/extensions/punchout/models/cxml-configuration/cxml-configuration.mapper.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import { Injectable } from '@angular/core'; | ||
|
||
import { CxmlConfigurationData } from './cxml-configuration.interface'; | ||
import { CxmlConfiguration } from './cxml-configuration.model'; | ||
|
||
@Injectable({ providedIn: 'root' }) | ||
export class CxmlConfigurationMapper { | ||
static fromData(cxmlConfigurationData: CxmlConfigurationData): CxmlConfiguration[] { | ||
if (cxmlConfigurationData) { | ||
const { data, info } = cxmlConfigurationData; | ||
|
||
return data?.map(cxmlConfiguration => { | ||
const infoElement = info?.metaData.find(e => e.name === cxmlConfiguration.name); | ||
return { | ||
...cxmlConfiguration, | ||
defaultValue: infoElement?.defaultValue, | ||
description: infoElement?.description, | ||
inputType: infoElement?.inputType, | ||
}; | ||
}); | ||
} else { | ||
throw new Error(`CxmlConfigurationData is required`); | ||
} | ||
} | ||
} |
9 changes: 9 additions & 0 deletions
9
src/app/extensions/punchout/models/cxml-configuration/cxml-configuration.model.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
export interface CxmlConfiguration { | ||
name: string; | ||
value: string; | ||
defaultValue?: string; | ||
description?: string; | ||
inputType?: CxmlConfigurationInputType; | ||
} | ||
|
||
export type CxmlConfigurationInputType = 'text-short' | 'text-long'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
13 changes: 13 additions & 0 deletions
13
...count-punchout-cxml-configuration/account-punchout-cxml-configuration-page.component.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
<ng-container *ngIf="selectedUser$ | async as user"> | ||
<h1>{{ 'account.punchout.configuration.heading' | translate }} - {{ user.login }}</h1> | ||
<p>{{ 'account.punchout.cxml.configuration.helptext' | translate }}</p> | ||
|
||
<ng-container *ngIf="cxmlConfiguration$ | async as cxmlConfiguration; else noConfiguration"> | ||
<ng-container *ngIf="cxmlConfiguration.length > 0" ; else noConfiguration> | ||
<ish-cxml-configuration-form [cxmlConfiguration]="cxmlConfiguration" /> </ng-container | ||
></ng-container> | ||
<ng-template #noConfiguration> | ||
<p>{{ 'account.punchout.cxml.configuration.no_configuration' | translate }}</p> | ||
</ng-template> | ||
</ng-container> | ||
<ish-loading *ngIf="loading$ | async" /> |
64 changes: 64 additions & 0 deletions
64
...nt-punchout-cxml-configuration/account-punchout-cxml-configuration-page.component.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
import { ComponentFixture, TestBed } from '@angular/core/testing'; | ||
import { TranslateModule } from '@ngx-translate/core'; | ||
import { MockComponent } from 'ng-mocks'; | ||
import { of } from 'rxjs'; | ||
import { instance, mock, when } from 'ts-mockito'; | ||
|
||
import { LoadingComponent } from 'ish-shared/components/common/loading/loading.component'; | ||
|
||
import { PunchoutFacade } from '../../facades/punchout.facade'; | ||
import { CxmlConfiguration } from '../../models/cxml-configuration/cxml-configuration.model'; | ||
import { PunchoutUser } from '../../models/punchout-user/punchout-user.model'; | ||
|
||
import { AccountPunchoutCxmlConfigurationPageComponent } from './account-punchout-cxml-configuration-page.component'; | ||
import { CxmlConfigurationFormComponent } from './cxml-configuration-form/cxml-configuration-form.component'; | ||
|
||
describe('Account Punchout Cxml Configuration Page Component', () => { | ||
let component: AccountPunchoutCxmlConfigurationPageComponent; | ||
let fixture: ComponentFixture<AccountPunchoutCxmlConfigurationPageComponent>; | ||
let element: HTMLElement; | ||
let punchoutFacade: PunchoutFacade; | ||
|
||
beforeEach(async () => { | ||
punchoutFacade = mock(PunchoutFacade); | ||
await TestBed.configureTestingModule({ | ||
imports: [TranslateModule.forRoot()], | ||
declarations: [ | ||
AccountPunchoutCxmlConfigurationPageComponent, | ||
MockComponent(CxmlConfigurationFormComponent), | ||
MockComponent(LoadingComponent), | ||
], | ||
providers: [{ provide: PunchoutFacade, useFactory: () => instance(punchoutFacade) }], | ||
}).compileComponents(); | ||
}); | ||
|
||
beforeEach(() => { | ||
fixture = TestBed.createComponent(AccountPunchoutCxmlConfigurationPageComponent); | ||
component = fixture.componentInstance; | ||
element = fixture.nativeElement; | ||
|
||
const user = { | ||
login: '1', | ||
} as PunchoutUser; | ||
const cxmlConfiguration = [{ name: 'test', value: 'test value' }] as CxmlConfiguration[]; | ||
when(punchoutFacade.selectedPunchoutUser$).thenReturn(of(user)); | ||
when(punchoutFacade.cxmlConfiguration$()).thenReturn(of(cxmlConfiguration)); | ||
}); | ||
|
||
it('should be created', () => { | ||
expect(component).toBeTruthy(); | ||
expect(element).toBeTruthy(); | ||
expect(() => fixture.detectChanges()).not.toThrow(); | ||
}); | ||
|
||
it('should display the configuration form after creation', () => { | ||
fixture.detectChanges(); | ||
expect(element.querySelector('ish-cxml-configuration-form')).toBeTruthy(); | ||
}); | ||
|
||
it('should display a loading overlay if the configuration is loading', () => { | ||
when(punchoutFacade.cxmlConfigurationLoading$).thenReturn(of(true)); | ||
fixture.detectChanges(); | ||
expect(element.querySelector('ish-loading')).toBeTruthy(); | ||
}); | ||
}); |
25 changes: 25 additions & 0 deletions
25
...account-punchout-cxml-configuration/account-punchout-cxml-configuration-page.component.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import { ChangeDetectionStrategy, Component, OnInit } from '@angular/core'; | ||
import { Observable } from 'rxjs'; | ||
|
||
import { PunchoutFacade } from '../../facades/punchout.facade'; | ||
import { CxmlConfiguration } from '../../models/cxml-configuration/cxml-configuration.model'; | ||
import { PunchoutUser } from '../../models/punchout-user/punchout-user.model'; | ||
|
||
@Component({ | ||
selector: 'ish-account-punchout-cxml-configuration-page', | ||
templateUrl: './account-punchout-cxml-configuration-page.component.html', | ||
changeDetection: ChangeDetectionStrategy.OnPush, | ||
}) | ||
export class AccountPunchoutCxmlConfigurationPageComponent implements OnInit { | ||
selectedUser$: Observable<PunchoutUser>; | ||
cxmlConfiguration$: Observable<CxmlConfiguration[]>; | ||
loading$: Observable<boolean>; | ||
|
||
constructor(private punchoutFacade: PunchoutFacade) {} | ||
|
||
ngOnInit() { | ||
this.selectedUser$ = this.punchoutFacade.selectedPunchoutUser$; | ||
this.cxmlConfiguration$ = this.punchoutFacade.cxmlConfiguration$(); | ||
this.loading$ = this.punchoutFacade.cxmlConfigurationLoading$; | ||
} | ||
} |
Oops, something went wrong.