This repository has been archived by the owner on Dec 8, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 65
Contrib > Added truncate and truncateAfter options to numeric pipe #1856
Merged
Blackbaud-SteveBrush
merged 7 commits into
master
from
contrib-feature-numeric-truncate
Jul 31, 2018
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
ce8bf1f
Added truncate and truncateAfter options to numeric pipe
3799593
Adjustments
Blackbaud-SteveBrush 6762dd7
Merge branch 'master' into contrib-feature-numeric-truncate
Blackbaud-SteveBrush 2955216
Merge branch 'master' into contrib-feature-numeric-truncate
Blackbaud-SteveBrush 8c1ec68
Added unit test
Blackbaud-SteveBrush 0df64ac
Merge branch 'contrib-feature-numeric-truncate' of github.com:blackba…
Blackbaud-SteveBrush fabd8bd
Merge branch 'master' into contrib-feature-numeric-truncate
Blackbaud-SteveBrush File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
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'); | ||
}); | ||
|
||
it(`default digits to zero if truncate set to false`, () => { | ||
let options: any = { | ||
truncate: false | ||
}; | ||
expect(skyNumericPipe.transform(42.87, options)).toBe('43'); | ||
}); | ||
}); |
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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Are you sure we want this to default to true? Won't that immediately truncate/"break" anyone currently using the skyNumeric filter?
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.
@blackbaud-conorwright The “truncate” boolean is a new option, so we wouldn’t have to worry about a breaking change with that setting in particular.
Also, the pipe as it stands today truncates automatically; this would allow users to turn off the truncate ability altogether.
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.
Oh alright. I know it's a new option and was worried that having a new option default to applying its effect would be a breaking change. Though if it was always truncating beforehand then this is correct. All good then 👍