-
Notifications
You must be signed in to change notification settings - Fork 467
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(addon-commerce): use pipe instead getter for improve performance
- Loading branch information
Showing
10 changed files
with
84 additions
and
12 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
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
File renamed without changes.
File renamed without changes.
9 changes: 9 additions & 0 deletions
9
projects/addon-commerce/pipes/format-card/format-card.module.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,9 @@ | ||
import {NgModule} from '@angular/core'; | ||
|
||
import {TuiFormatCardPipe} from './format-card.pipe'; | ||
|
||
@NgModule({ | ||
declarations: [TuiFormatCardPipe], | ||
exports: [TuiFormatCardPipe], | ||
}) | ||
export class TuiFormatCardModule {} |
13 changes: 13 additions & 0 deletions
13
projects/addon-commerce/pipes/format-card/format-card.pipe.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,13 @@ | ||
import {Pipe, PipeTransform} from '@angular/core'; | ||
|
||
@Pipe({name: 'tuiFormatCard'}) | ||
export class TuiFormatCardPipe implements PipeTransform { | ||
transform(value: string | null = '', cardPrefilled: boolean = false): string { | ||
return value && !cardPrefilled | ||
? value | ||
.split('') | ||
.map((char, index) => (index && index % 4 === 0 ? ` ${char}` : char)) | ||
.join('') | ||
: ''; | ||
} | ||
} |
28 changes: 28 additions & 0 deletions
28
projects/addon-commerce/pipes/format-card/tests/format-card.pipe.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,28 @@ | ||
import {TuiFormatCardPipe} from '@taiga-ui/addon-commerce/pipes'; | ||
|
||
describe('TuiFormatCardPipe', () => { | ||
const pipe = new TuiFormatCardPipe(); | ||
|
||
it('value is empty', () => { | ||
expect(pipe.transform()).toEqual(''); | ||
expect(pipe.transform(undefined)).toEqual(''); | ||
expect(pipe.transform(null)).toEqual(''); | ||
expect(pipe.transform(null, true)).toEqual(''); | ||
expect(pipe.transform(undefined, true)).toEqual(''); | ||
expect(pipe.transform(null, true)).toEqual(''); | ||
}); | ||
|
||
it('value has card', () => { | ||
expect(pipe.transform('1234')).toEqual('1234'); | ||
expect(pipe.transform('123456')).toEqual('1234 56'); | ||
expect(pipe.transform('1234567891011111')).toEqual('1234 5678 9101 1111'); | ||
}); | ||
|
||
it('card value has whitespaces', () => { | ||
expect(pipe.transform('1234 5678 9101')).toEqual('1234 567 8 91 01'); | ||
expect(pipe.transform('1234 5678 9101 1111')).toEqual('1234 567 8 91 01 1 111'); | ||
expect(pipe.transform('1234 56 78 9101 11 11')).toEqual( | ||
'1234 56 78 9 101 11 1 1', | ||
); | ||
}); | ||
}); |
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,2 +1,4 @@ | ||
export * from './currency.module'; | ||
export * from './currency.pipe'; | ||
export * from './currency/currency.module'; | ||
export * from './currency/currency.pipe'; | ||
export * from './format-card/format-card.module'; | ||
export * from './format-card/format-card.pipe'; |
22 changes: 22 additions & 0 deletions
22
projects/demo-integrations/cypress/tests/addon-commerce/input-card-grouped.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,22 @@ | ||
describe('InputCardGrouped', () => { | ||
beforeEach(() => { | ||
cy.viewport('macbook-13'); | ||
cy.tuiVisit('components/input-card-grouped/API?tuiMode=null'); | ||
cy.get('#demoContent').as('wrapper'); | ||
}); | ||
|
||
it('set value and clear after', () => { | ||
cy.get('@wrapper') | ||
.findByAutomationId('tui-input-card-grouped__card') | ||
.type('1234 4567 8910 1112') | ||
.wait(5000); // waiting before closing toast for skip flaky test | ||
|
||
cy.matchImageSnapshot('01-input-card-grouped-filled', {capture: 'viewport'}); | ||
|
||
cy.get('@wrapper').find('[src="tuiIconCloseLarge"]').click({force: true}); | ||
cy.matchImageSnapshot('02-input-card-grouped-cleared', {capture: 'viewport'}); | ||
|
||
cy.get('@wrapper').click({force: true}); | ||
cy.matchImageSnapshot('03-input-card-grouped-unfocused', {capture: 'viewport'}); | ||
}); | ||
}); |