-
Notifications
You must be signed in to change notification settings - Fork 268
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
* [AAE-16964] Handle amount data table cloumn type * remove not needed reset testing module * improve spacing * update documentation * remove code duplications in unit tests * add type for default currency config * update doc
- Loading branch information
Showing
10 changed files
with
242 additions
and
5 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
10 changes: 10 additions & 0 deletions
10
lib/core/src/lib/datatable/components/amount-cell/amount-cell.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,10 @@ | ||
<ng-container *ngIf="value$ | async as amount"> | ||
<span [title]="amount"> | ||
{{ amount | currency: | ||
(currencyConfig?.code || defaultCurrencyConfig.code): | ||
(currencyConfig?.display || defaultCurrencyConfig.display): | ||
(currencyConfig?.digitsInfo || defaultCurrencyConfig.digitsInfo): | ||
(currencyConfig?.locale || defaultCurrencyConfig.locale) | ||
}} | ||
</span> | ||
</ng-container> |
96 changes: 96 additions & 0 deletions
96
lib/core/src/lib/datatable/components/amount-cell/amount-cell.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,96 @@ | ||
/*! | ||
* @license | ||
* Copyright © 2005-2023 Hyland Software, Inc. and its affiliates. All rights reserved. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
import { ComponentFixture, TestBed } from '@angular/core/testing'; | ||
import { AmountCellComponent } from './amount-cell.component'; | ||
import { CurrencyConfig } from '../../data/data-column.model'; | ||
import { BehaviorSubject } from 'rxjs'; | ||
import { LOCALE_ID } from '@angular/core'; | ||
import { registerLocaleData } from '@angular/common'; | ||
import localePL from '@angular/common/locales/pl'; | ||
|
||
describe('AmountCellComponent', () => { | ||
let component: AmountCellComponent; | ||
let fixture: ComponentFixture<AmountCellComponent>; | ||
|
||
const renderAndCheckCurrencyValue = (currencyConfig: CurrencyConfig, value: number, expectedResult: string) => { | ||
component.value$ = new BehaviorSubject<number>(value); | ||
component.currencyConfig = currencyConfig; | ||
|
||
fixture.detectChanges(); | ||
const displayedAmount = fixture.nativeElement.querySelector('span'); | ||
|
||
expect(displayedAmount).toBeTruthy(); | ||
expect(displayedAmount.textContent.trim()).toBe(expectedResult); | ||
}; | ||
|
||
beforeEach(() => { | ||
TestBed.configureTestingModule({ | ||
imports: [AmountCellComponent] | ||
}); | ||
fixture = TestBed.createComponent(AmountCellComponent); | ||
component = fixture.componentInstance; | ||
}); | ||
|
||
it('should set default currency config', () => { | ||
expect(component.defaultCurrencyConfig.code).toBe('USD'); | ||
expect(component.defaultCurrencyConfig.display).toBe('symbol'); | ||
expect(component.defaultCurrencyConfig.digitsInfo).toBeUndefined(); | ||
expect(component.defaultCurrencyConfig.locale).toBeUndefined(); | ||
}); | ||
|
||
it('should render currency value', () => { | ||
renderAndCheckCurrencyValue(component.currencyConfig, 123.45, '$123.45'); | ||
}); | ||
|
||
it('should render currency value with custom currency code', () => { | ||
renderAndCheckCurrencyValue({ code: 'MY CUSTOM CURRENCY', display: 'symbol' }, 123.45, 'MY CUSTOM CURRENCY123.45'); | ||
}); | ||
|
||
it('should render currency value with custom display code', () => { | ||
renderAndCheckCurrencyValue({ code: 'EUR', display: 'symbol' }, 123.45, '€123.45'); | ||
}); | ||
|
||
it('should render currency value with custom digitsInfo', () => { | ||
renderAndCheckCurrencyValue({ code: 'USD', display: 'symbol', digitsInfo: '1.2-2' }, 123.456789, '$123.46'); | ||
}); | ||
}); | ||
|
||
describe('AmountCellComponent locale', () => { | ||
let component: AmountCellComponent; | ||
let fixture: ComponentFixture<AmountCellComponent>; | ||
|
||
it('should render currency value with custom locale', () => { | ||
TestBed.configureTestingModule({ | ||
imports: [AmountCellComponent], | ||
providers: [{ provide: LOCALE_ID, useValue: 'pl-PL' }] | ||
}); | ||
|
||
fixture = TestBed.createComponent(AmountCellComponent); | ||
component = fixture.componentInstance; | ||
registerLocaleData(localePL); | ||
|
||
component.value$ = new BehaviorSubject<number>(123.45); | ||
component.currencyConfig = { code: 'PLN', display: 'symbol', locale: 'pl-PL' }; | ||
|
||
fixture.detectChanges(); | ||
const displayedAmount = fixture.nativeElement.querySelector('span'); | ||
|
||
expect(displayedAmount).toBeTruthy(); | ||
expect(displayedAmount.textContent.trim()).toMatch(/123,45\s?zł/); | ||
}); | ||
}); |
66 changes: 66 additions & 0 deletions
66
lib/core/src/lib/datatable/components/amount-cell/amount-cell.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,66 @@ | ||
/*! | ||
* @license | ||
* Copyright © 2005-2023 Hyland Software, Inc. and its affiliates. All rights reserved. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
import { | ||
ChangeDetectionStrategy, | ||
Component, | ||
ViewEncapsulation, | ||
Input, | ||
Optional, | ||
OnInit, | ||
DEFAULT_CURRENCY_CODE, | ||
Inject | ||
} from '@angular/core'; | ||
import { DataTableCellComponent } from '../datatable-cell/datatable-cell.component'; | ||
import { DataTableService } from '../../services/datatable.service'; | ||
import { CurrencyConfig } from '../../data/data-column.model'; | ||
import { CommonModule } from '@angular/common'; | ||
|
||
@Component({ | ||
standalone: true, | ||
imports: [CommonModule], | ||
selector: 'adf-amount-cell', | ||
templateUrl: './amount-cell.component.html', | ||
host: { class: 'adf-datatable-content-cell' }, | ||
encapsulation: ViewEncapsulation.None, | ||
changeDetection: ChangeDetectionStrategy.OnPush | ||
}) | ||
export class AmountCellComponent extends DataTableCellComponent implements OnInit { | ||
|
||
@Input() | ||
currencyConfig: CurrencyConfig; | ||
|
||
readonly defaultCurrencyConfig: CurrencyConfig = { | ||
code: this.defaultCurrencyCode, | ||
display: 'symbol', | ||
digitsInfo: undefined, | ||
locale: undefined | ||
}; | ||
|
||
constructor( | ||
@Optional() dataTableService: DataTableService, | ||
@Inject(DEFAULT_CURRENCY_CODE) private readonly defaultCurrencyCode: string | ||
) { | ||
super(dataTableService); | ||
} | ||
|
||
ngOnInit() { | ||
if (this.column?.key && this.row && this.data) { | ||
this.value$.next(this.data.getValue(this.row, this.column, this.resolverFn)); | ||
} | ||
} | ||
} |
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