-
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 checkout and order prices respecting ICM pricing settings
- Loading branch information
Showing
8 changed files
with
262 additions
and
47 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,59 +1,163 @@ | ||
import { registerLocaleData } from '@angular/common'; | ||
import localeDe from '@angular/common/locales/de'; | ||
import { TestBed } from '@angular/core/testing'; | ||
import { Component } from '@angular/core'; | ||
import { ComponentFixture, TestBed, async, fakeAsync, tick } from '@angular/core/testing'; | ||
import { Store } from '@ngrx/store'; | ||
import { TranslateModule, TranslateService } from '@ngx-translate/core'; | ||
import * as using from 'jasmine-data-provider'; | ||
|
||
import { Customer } from 'ish-core/models/customer/customer.model'; | ||
import { PriceItem } from 'ish-core/models/price-item/price-item.model'; | ||
import { ApplyConfiguration } from 'ish-core/store/configuration'; | ||
import { configurationReducer } from 'ish-core/store/configuration/configuration.reducer'; | ||
import { LoginUserSuccess, LogoutUser } from 'ish-core/store/user'; | ||
import { userReducer } from 'ish-core/store/user/user.reducer'; | ||
import { ngrxTesting } from 'ish-core/utils/dev/ngrx-testing'; | ||
|
||
import { Price } from './price.model'; | ||
import { PricePipe } from './price.pipe'; | ||
|
||
@Component({ template: '~{{ price | ishPrice }}~' }) | ||
class DummyComponent { | ||
price: Price | PriceItem; | ||
} | ||
|
||
describe('Price Pipe', () => { | ||
let pipe: PricePipe; | ||
let fixture: ComponentFixture<DummyComponent>; | ||
let component: DummyComponent; | ||
let element: HTMLElement; | ||
let translateService: TranslateService; | ||
let store$: Store<{}>; | ||
|
||
beforeEach(() => { | ||
registerLocaleData(localeDe); | ||
|
||
beforeEach(async(() => { | ||
TestBed.configureTestingModule({ | ||
imports: [TranslateModule.forRoot()], | ||
declarations: [DummyComponent, PricePipe], | ||
imports: [ | ||
TranslateModule.forRoot(), | ||
ngrxTesting({ reducers: { configuration: configurationReducer, user: userReducer } }), | ||
], | ||
providers: [PricePipe], | ||
}); | ||
pipe = TestBed.get(PricePipe); | ||
})); | ||
|
||
beforeEach(() => { | ||
registerLocaleData(localeDe); | ||
translateService = TestBed.get(TranslateService); | ||
translateService.setDefaultLang('en'); | ||
store$ = TestBed.get(Store); | ||
|
||
fixture = TestBed.createComponent(DummyComponent); | ||
component = fixture.componentInstance; | ||
element = fixture.nativeElement; | ||
}); | ||
|
||
function dataProvider() { | ||
return [ | ||
{ | ||
price: { | ||
type: 'Money', | ||
value: 391.98, | ||
currency: 'USD', | ||
}, | ||
en_US: '$391.98', | ||
de_DE: '391,98\xA0$', | ||
}, | ||
{ | ||
price: { | ||
type: 'ProductPrice', | ||
value: 391.99, | ||
currency: 'EUR', | ||
}, | ||
en_US: '€391.99', | ||
de_DE: '391,99\xA0€', | ||
}, | ||
]; | ||
} | ||
|
||
using(dataProvider, slice => { | ||
it(`should translate price of type ${slice.price.type} correcly when locale en_US is set`, () => { | ||
translateService.use('en_US'); | ||
expect(pipe.transform(slice.price)).toEqual(slice.en_US); | ||
it('should be created', () => { | ||
expect(component).toBeTruthy(); | ||
expect(element).toBeTruthy(); | ||
expect(() => fixture.detectChanges()).not.toThrow(); | ||
}); | ||
|
||
it('should display N/A for default', () => { | ||
translateService.use('en'); | ||
fixture.detectChanges(); | ||
expect(element).toMatchInlineSnapshot(`~product.price.na.text~`); | ||
}); | ||
|
||
describe('Price', () => { | ||
const euroPrice: Price = { | ||
type: 'Money', | ||
value: 12391.98, | ||
currency: 'EUR', | ||
}; | ||
|
||
const dollarPrice: Price = { | ||
type: 'Money', | ||
value: 12391.98, | ||
currency: 'USD', | ||
}; | ||
|
||
it('should display dollar price for english', () => { | ||
component.price = dollarPrice; | ||
translateService.use('en'); | ||
|
||
fixture.detectChanges(); | ||
expect(element).toMatchInlineSnapshot(`~$12,391.98~`); | ||
}); | ||
|
||
it('should display dollar price for german', () => { | ||
component.price = dollarPrice; | ||
translateService.use('de'); | ||
|
||
fixture.detectChanges(); | ||
expect(element).toMatchInlineSnapshot(`~12.391,98 $~`); | ||
}); | ||
|
||
it(`should translate price of type ${slice.price.type} correcly when locale de_DE is set`, () => { | ||
translateService.use('de_DE'); | ||
expect(pipe.transform(slice.price)).toEqual(slice.de_DE); | ||
it('should display euro price for english', () => { | ||
component.price = euroPrice; | ||
translateService.use('en'); | ||
|
||
fixture.detectChanges(); | ||
expect(element).toMatchInlineSnapshot(`~€12,391.98~`); | ||
}); | ||
it('should display euro price for german', () => { | ||
component.price = euroPrice; | ||
translateService.use('de'); | ||
|
||
fixture.detectChanges(); | ||
expect(element).toMatchInlineSnapshot(`~12.391,98 €~`); | ||
}); | ||
}); | ||
|
||
describe('PriceItem', () => { | ||
const priceItem: PriceItem = { | ||
type: 'PriceItem', | ||
gross: 12391.98, | ||
net: 987.6, | ||
currency: 'USD', | ||
}; | ||
|
||
beforeEach(() => { | ||
component.price = priceItem; | ||
translateService.use('en'); | ||
}); | ||
|
||
it('should display price depending on state', fakeAsync(() => { | ||
fixture.detectChanges(); | ||
tick(500); | ||
|
||
expect(element).toMatchInlineSnapshot(`~$12,391.98~`); | ||
|
||
store$.dispatch(new LoginUserSuccess({ customer: { isBusinessCustomer: true } as Customer })); | ||
fixture.detectChanges(); | ||
tick(500); | ||
|
||
expect(element).toMatchInlineSnapshot(`~$987.60~`); | ||
|
||
store$.dispatch(new LogoutUser()); | ||
fixture.detectChanges(); | ||
tick(500); | ||
|
||
expect(element).toMatchInlineSnapshot(`~$12,391.98~`); | ||
|
||
store$.dispatch( | ||
new ApplyConfiguration({ serverConfig: { pricing: { defaultCustomerTypeForPriceDisplay: 'SMB' } } }) | ||
); | ||
fixture.detectChanges(); | ||
tick(500); | ||
|
||
expect(element).toMatchInlineSnapshot(`~$987.60~`); | ||
})); | ||
|
||
it('should display price depending on input', fakeAsync(() => { | ||
fixture.detectChanges(); | ||
tick(500); | ||
|
||
expect(element).toMatchInlineSnapshot(`~$12,391.98~`); | ||
|
||
component.price = { ...priceItem, gross: 123 }; | ||
fixture.detectChanges(); | ||
tick(500); | ||
|
||
expect(element).toMatchInlineSnapshot(`~$123.00~`); | ||
})); | ||
}); | ||
}); |
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
Oops, something went wrong.