-
Notifications
You must be signed in to change notification settings - Fork 65
Added truncate and truncateAfter options to numeric pipe #1823
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -115,6 +115,22 @@ | |
{{1234567 | skyNumeric}} | ||
</sky-definition-list-value> | ||
</p> | ||
<p> | ||
<sky-definition-list-label> | ||
1234567 without truncation | ||
</sky-definition-list-label> | ||
<sky-definition-list-value> | ||
{{1234567 | skyNumeric:{truncate: false} }} | ||
</sky-definition-list-value> | ||
</p> | ||
<p> | ||
<sky-definition-list-label> | ||
15501 with truncation after 10000 and 1 digit | ||
</sky-definition-list-label> | ||
<sky-definition-list-value> | ||
{{15501 | skyNumeric:{digits: 1, truncateAfter: 10000} }} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @Blackbaud-JacobWood If I change There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, original affects of the this component would only occur when the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I gotcha, thanks for the explanation! |
||
</sky-definition-list-value> | ||
</p> | ||
<p> | ||
<sky-definition-list-label> | ||
15.50 as US dollar currency with 2 digits: | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
import { TestBed } from '@angular/core/testing'; | ||
import { SkyNumericModule } from './numeric.module'; | ||
import { SkyNumericService } from './numeric.service'; | ||
import { CurrencyPipe, DecimalPipe } from '@angular/common'; | ||
import { SkyNumericPipe } from './numeric.pipe'; | ||
|
||
describe('Numeric pipe', () => { | ||
let skyNumericPipe: SkyNumericPipe; | ||
let skyNumeric = new SkyNumericService( | ||
new CurrencyPipe('en-US'), | ||
new DecimalPipe('en-US') | ||
); | ||
|
||
beforeEach(() => { | ||
TestBed.configureTestingModule({ | ||
imports: [ | ||
SkyNumericModule | ||
], | ||
providers: [ | ||
SkyNumericPipe, | ||
{ | ||
provide: SkyNumericService, | ||
useValue: skyNumeric | ||
} | ||
] | ||
}); | ||
}); | ||
|
||
beforeEach(() => { | ||
skyNumericPipe = TestBed.get(SkyNumericPipe); | ||
}); | ||
|
||
it('should pass all options to the sky numeric service', () => { | ||
|
||
let options: any = { | ||
digits: 2, | ||
format: 'currency', | ||
iso: 'USD', | ||
truncate: true, | ||
truncateAfter: 10000 | ||
}; | ||
expect(skyNumericPipe.transform(10001.00, options)).toBe('$10K'); | ||
}); | ||
|
||
it(`doesn''t require options to be set`, () => { | ||
expect(skyNumericPipe.transform(42.87, undefined)).toBe('42.9'); | ||
}); | ||
|
||
it(`doesn''t require option properties to be set`, () => { | ||
let options: any = { | ||
random: false | ||
}; | ||
expect(skyNumericPipe.transform(42.87, options)).toBe('42.9'); | ||
}); | ||
}); |
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.
This produced the following:
Is that expected, or should it just be
1,234,567
?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.
I didn’t mess with the default for the digits option which is 1 in the NumericOptions class. When not truncating a decimal, the min and max fraction value are both set to that digits option so as to not mess with the output.