-
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 information for B2B users above my account navigation (#…
…298)
- Loading branch information
Showing
8 changed files
with
137 additions
and
2 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
1 change: 1 addition & 0 deletions
1
src/app/pages/account/account-navigation/account-navigation.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
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/pages/account/account-user-info/account-user-info.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,16 @@ | ||
<li *ngIf="isBusinessUser$ | async" class="account-welcome"> | ||
<ng-container *ngIf="user$ | async as user"> | ||
<ng-container *ngIf="user.lastName && user.firstName; else email"> | ||
<h4>{{ user.lastName }}, {{ user.firstName }}</h4> | ||
</ng-container> | ||
<ng-template #email> | ||
<h4 class="ellipsis">{{ user.login }}</h4> | ||
</ng-template> | ||
</ng-container> | ||
<p *ngIf="customer$ | async as customer"> | ||
<small>{{ customer.companyName }}</small> | ||
</p> | ||
<p *ngIf="roles$ | async as roles"> | ||
<small>{{ roles }}</small> | ||
</p> | ||
</li> |
78 changes: 78 additions & 0 deletions
78
src/app/pages/account/account-user-info/account-user-info.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,78 @@ | ||
import { ComponentFixture, TestBed, async } from '@angular/core/testing'; | ||
import { EMPTY, 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 { AccountUserInfoComponent } from './account-user-info.component'; | ||
|
||
describe('Account User Info Component', () => { | ||
let component: AccountUserInfoComponent; | ||
let fixture: ComponentFixture<AccountUserInfoComponent>; | ||
let element: HTMLElement; | ||
let accountFacade: AccountFacade; | ||
|
||
beforeEach(async(() => { | ||
accountFacade = mock(AccountFacade); | ||
when(accountFacade.customer$).thenReturn(EMPTY); | ||
when(accountFacade.roles$).thenReturn(EMPTY); | ||
|
||
TestBed.configureTestingModule({ | ||
declarations: [AccountUserInfoComponent], | ||
providers: [{ provide: AccountFacade, useFactory: () => instance(accountFacade) }], | ||
}).compileComponents(); | ||
})); | ||
|
||
beforeEach(() => { | ||
fixture = TestBed.createComponent(AccountUserInfoComponent); | ||
component = fixture.componentInstance; | ||
element = fixture.nativeElement; | ||
}); | ||
|
||
it('should be created', () => { | ||
expect(component).toBeTruthy(); | ||
expect(element).toBeTruthy(); | ||
expect(() => fixture.detectChanges()).not.toThrow(); | ||
}); | ||
|
||
it('should not render when user is private customer', () => { | ||
when(accountFacade.customer$).thenReturn(of({ isBusinessCustomer: false } as Customer)); | ||
|
||
fixture.detectChanges(); | ||
|
||
expect(element).toMatchInlineSnapshot(`N/A`); | ||
}); | ||
|
||
it('should render when user is business customer', () => { | ||
when(accountFacade.customer$).thenReturn(of({ isBusinessCustomer: true, companyName: 'Foods Inc.' } as Customer)); | ||
when(accountFacade.user$).thenReturn(of({ firstName: 'Max', lastName: 'Mustermann' } as User)); | ||
when(accountFacade.roles$).thenReturn(of(['Approver', 'Buyer'])); | ||
|
||
fixture.detectChanges(); | ||
|
||
expect(element).toMatchInlineSnapshot(` | ||
<li class="account-welcome"> | ||
<h4>Mustermann, Max</h4> | ||
<p><small>Foods Inc.</small></p> | ||
<p><small>Approver, Buyer</small></p> | ||
</li> | ||
`); | ||
}); | ||
|
||
it('should display email when user has no name', () => { | ||
when(accountFacade.customer$).thenReturn(of({ isBusinessCustomer: true, companyName: 'Foods Inc.' } as Customer)); | ||
when(accountFacade.user$).thenReturn(of({ login: 'max.mustermann@test.de' } as User)); | ||
when(accountFacade.roles$).thenReturn(EMPTY); | ||
|
||
fixture.detectChanges(); | ||
|
||
expect(element).toMatchInlineSnapshot(` | ||
<li class="account-welcome"> | ||
<h4 class="ellipsis">max.mustermann@test.de</h4> | ||
<p><small>Foods Inc.</small></p> | ||
</li> | ||
`); | ||
}); | ||
}); |
28 changes: 28 additions & 0 deletions
28
src/app/pages/account/account-user-info/account-user-info.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,28 @@ | ||
import { ChangeDetectionStrategy, Component, OnInit } from '@angular/core'; | ||
import { User } from '@sentry/browser'; | ||
import { Observable } from 'rxjs'; | ||
import { map } from 'rxjs/operators'; | ||
|
||
import { AccountFacade } from 'ish-core/facades/account.facade'; | ||
import { Customer } from 'ish-core/models/customer/customer.model'; | ||
|
||
@Component({ | ||
selector: 'ish-account-user-info', | ||
templateUrl: './account-user-info.component.html', | ||
changeDetection: ChangeDetectionStrategy.OnPush, | ||
}) | ||
export class AccountUserInfoComponent implements OnInit { | ||
isBusinessUser$: Observable<boolean>; | ||
user$: Observable<User>; | ||
customer$: Observable<Customer>; | ||
roles$: Observable<string>; | ||
|
||
constructor(private accountFacade: AccountFacade) {} | ||
|
||
ngOnInit() { | ||
this.isBusinessUser$ = this.accountFacade.customer$.pipe(map(user => !!user?.isBusinessCustomer)); | ||
this.user$ = this.accountFacade.user$; | ||
this.customer$ = this.accountFacade.customer$; | ||
this.roles$ = this.accountFacade.roles$.pipe(map(a => a.join(', '))); | ||
} | ||
} |
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 |
---|---|---|
|
@@ -59,6 +59,12 @@ | |
color: $text-color-primary; | ||
} | ||
} | ||
|
||
&.account-welcome { | ||
&:hover { | ||
background: $color-tertiary; | ||
} | ||
} | ||
} | ||
} | ||
|
||
|