-
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: display fields in checkout and myaccount
- Loading branch information
Showing
13 changed files
with
102 additions
and
0 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
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
7 changes: 7 additions & 0 deletions
7
...ed/components/checkout/basket-custom-fields-view/basket-custom-fields-view.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,7 @@ | ||
<ng-container *ngIf="visible$ | async"> | ||
<ish-info-box [editRouterLink]="editRouterLink" heading="checkout.widget.custom_fields" class="infobox-wrapper"> | ||
<p> | ||
<ish-custom-fields-view [fields]="fields$ | async" /> | ||
</p> | ||
</ish-info-box> | ||
</ng-container> |
35 changes: 35 additions & 0 deletions
35
...components/checkout/basket-custom-fields-view/basket-custom-fields-view.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,35 @@ | ||
import { ComponentFixture, TestBed } from '@angular/core/testing'; | ||
import { EMPTY } from 'rxjs'; | ||
import { instance, mock, when } from 'ts-mockito'; | ||
|
||
import { AppFacade } from 'ish-core/facades/app.facade'; | ||
|
||
import { BasketCustomFieldsViewComponent } from './basket-custom-fields-view.component'; | ||
|
||
describe('Basket Custom Fields View Component', () => { | ||
let component: BasketCustomFieldsViewComponent; | ||
let fixture: ComponentFixture<BasketCustomFieldsViewComponent>; | ||
let element: HTMLElement; | ||
|
||
beforeEach(async () => { | ||
const appFacade = mock(AppFacade); | ||
when(appFacade.customFieldsForScope$('Basket')).thenReturn(EMPTY); | ||
|
||
await TestBed.configureTestingModule({ | ||
declarations: [BasketCustomFieldsViewComponent], | ||
providers: [{ provide: AppFacade, useFactory: () => instance(appFacade) }], | ||
}).compileComponents(); | ||
}); | ||
|
||
beforeEach(() => { | ||
fixture = TestBed.createComponent(BasketCustomFieldsViewComponent); | ||
component = fixture.componentInstance; | ||
element = fixture.nativeElement; | ||
}); | ||
|
||
it('should be created', () => { | ||
expect(component).toBeTruthy(); | ||
expect(element).toBeTruthy(); | ||
expect(() => fixture.detectChanges()).not.toThrow(); | ||
}); | ||
}); |
37 changes: 37 additions & 0 deletions
37
...ared/components/checkout/basket-custom-fields-view/basket-custom-fields-view.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,37 @@ | ||
import { ChangeDetectionStrategy, Component, Input, OnInit } from '@angular/core'; | ||
import { Observable, ReplaySubject, combineLatest, map } from 'rxjs'; | ||
|
||
import { AppFacade } from 'ish-core/facades/app.facade'; | ||
import { CustomFields, CustomFieldsComponentInput } from 'ish-core/models/custom-field/custom-field.model'; | ||
|
||
@Component({ | ||
selector: 'ish-basket-custom-fields-view', | ||
templateUrl: './basket-custom-fields-view.component.html', | ||
changeDetection: ChangeDetectionStrategy.OnPush, | ||
}) | ||
export class BasketCustomFieldsViewComponent implements OnInit { | ||
@Input() set data(val: { customFields?: CustomFields }) { | ||
this._customFields.next(val.customFields || {}); | ||
} | ||
@Input() editRouterLink: string; | ||
|
||
private _customFields = new ReplaySubject<CustomFields>(1); | ||
|
||
fields$: Observable<CustomFieldsComponentInput[]>; | ||
visible$: Observable<boolean>; | ||
|
||
constructor(private appFacade: AppFacade) {} | ||
|
||
ngOnInit(): void { | ||
this.fields$ = combineLatest([ | ||
this._customFields.asObservable(), | ||
this.appFacade.customFieldsForScope$('Basket'), | ||
]).pipe( | ||
map(([customFields, customFieldsForScope]) => | ||
customFieldsForScope.map(({ name, editable }) => ({ name, value: customFields[name], editable })) | ||
) | ||
); | ||
|
||
this.visible$ = this.fields$.pipe(map(fields => fields.some(field => field.value))); | ||
} | ||
} |
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