-
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 purchaser widget for b2b customers on checkout and orde…
…r details pages
- Loading branch information
Showing
17 changed files
with
180 additions
and
3 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
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
15 changes: 15 additions & 0 deletions
15
src/app/shared/components/basket/basket-purchaser/basket-purchaser.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,15 @@ | ||
<div *ngIf="object"> | ||
<ng-container *ngIf="customer$ | async as customer; else companyFromInvoice"> | ||
{{ customer.companyName }} {{ customer.companyName2 }} | ||
</ng-container> | ||
<ng-template #companyFromInvoice> | ||
{{ object.invoiceToAddress.companyName1 }} {{ object.invoiceToAddress.companyName2 }} | ||
</ng-template> | ||
<span *ngIf="taxationID" data-testing-id="taxationID"> | ||
<br />{{ 'checkout.widget.purchaser.TaxationID' | translate }} {{ taxationID }} | ||
</span> | ||
<p> | ||
{{ userName }}<br /> | ||
{{ object.email || object.invoiceToAddress?.email }} | ||
</p> | ||
</div> |
53 changes: 53 additions & 0 deletions
53
src/app/shared/components/basket/basket-purchaser/basket-purchaser.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,53 @@ | ||
import { ComponentFixture, TestBed } from '@angular/core/testing'; | ||
import { TranslateModule } from '@ngx-translate/core'; | ||
import { of } from 'rxjs'; | ||
import { instance, mock, when } from 'ts-mockito'; | ||
|
||
import { AccountFacade } from 'ish-core/facades/account.facade'; | ||
import { Customer } from 'ish-core/models/customer/customer.model'; | ||
import { User } from 'ish-core/models/user/user.model'; | ||
import { BasketMockData } from 'ish-core/utils/dev/basket-mock-data'; | ||
|
||
import { BasketPurchaserComponent } from './basket-purchaser.component'; | ||
|
||
describe('Basket Purchaser Component', () => { | ||
let component: BasketPurchaserComponent; | ||
let fixture: ComponentFixture<BasketPurchaserComponent>; | ||
let element: HTMLElement; | ||
let accountFacade: AccountFacade; | ||
|
||
beforeEach(async () => { | ||
accountFacade = mock(AccountFacade); | ||
|
||
await TestBed.configureTestingModule({ | ||
imports: [TranslateModule.forRoot()], | ||
declarations: [BasketPurchaserComponent], | ||
providers: [{ provide: AccountFacade, useFactory: () => instance(accountFacade) }], | ||
}).compileComponents(); | ||
}); | ||
|
||
beforeEach(() => { | ||
accountFacade = mock(AccountFacade); | ||
|
||
fixture = TestBed.createComponent(BasketPurchaserComponent); | ||
component = fixture.componentInstance; | ||
element = fixture.nativeElement; | ||
|
||
component.object = BasketMockData.getBasket(); | ||
|
||
when(accountFacade.user$).thenReturn(of({ firstName: 'Patricia', lastName: 'Miller' } as User)); | ||
when(accountFacade.customer$).thenReturn(of({ companyName: 'OilCorp', taxationID: '1234' } as Customer)); | ||
}); | ||
|
||
it('should be created', () => { | ||
expect(component).toBeTruthy(); | ||
expect(element).toBeTruthy(); | ||
expect(() => fixture.detectChanges()).not.toThrow(); | ||
}); | ||
|
||
it('should display the taxation id of the customer', () => { | ||
fixture.detectChanges(); | ||
expect(element.querySelector('[data-testing-id="taxationID"]')).toBeTruthy(); | ||
expect(element.querySelector('[data-testing-id="taxationID"]').innerHTML).toContain('1234'); | ||
}); | ||
}); |
52 changes: 52 additions & 0 deletions
52
src/app/shared/components/basket/basket-purchaser/basket-purchaser.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,52 @@ | ||
import { ChangeDetectionStrategy, Component, Input, OnDestroy, OnInit } from '@angular/core'; | ||
import { Observable, Subject } from 'rxjs'; | ||
import { first, takeUntil } from 'rxjs/operators'; | ||
|
||
import { AccountFacade } from 'ish-core/facades/account.facade'; | ||
import { Basket } from 'ish-core/models/basket/basket.model'; | ||
import { Customer } from 'ish-core/models/customer/customer.model'; | ||
import { Order } from 'ish-core/models/order/order.model'; | ||
import { User } from 'ish-core/models/user/user.model'; | ||
import { whenTruthy } from 'ish-core/utils/operators'; | ||
|
||
@Component({ | ||
selector: 'ish-basket-purchaser', | ||
templateUrl: './basket-purchaser.component.html', | ||
changeDetection: ChangeDetectionStrategy.OnPush, | ||
}) | ||
export class BasketPurchaserComponent implements OnInit, OnDestroy { | ||
@Input() object: Basket | Order; | ||
|
||
customer$: Observable<Customer>; | ||
user$: Observable<User>; | ||
|
||
taxationID: string; | ||
userName: string; | ||
|
||
private destroy$ = new Subject(); | ||
|
||
constructor(private accountFacade: AccountFacade) {} | ||
|
||
ngOnInit() { | ||
// default values for anonymous users | ||
this.taxationID = this.object.attributes?.find(attr => attr.name === 'taxationID')?.value as string; | ||
this.userName = `${this.object.invoiceToAddress?.firstName} ${this.object.invoiceToAddress?.lastName}`; | ||
|
||
this.customer$ = this.accountFacade.customer$; | ||
this.user$ = this.accountFacade.user$; | ||
|
||
// values for registered users | ||
this.customer$.pipe(whenTruthy(), first(), takeUntil(this.destroy$)).subscribe(customer => { | ||
this.taxationID = customer?.taxationID; | ||
}); | ||
|
||
this.user$.pipe(whenTruthy(), first(), takeUntil(this.destroy$)).subscribe(user => { | ||
this.userName = `${user.firstName} ${user.lastName}`; | ||
}); | ||
} | ||
|
||
ngOnDestroy() { | ||
this.destroy$.next(); | ||
this.destroy$.complete(); | ||
} | ||
} |
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
d31ee1b
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Azure Demo Servers are available: