-
Notifications
You must be signed in to change notification settings - Fork 613
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
card add #1373
Merged
danieldelcore
merged 1 commit into
bigcommerce:payment-methods-feature
from
jonathandelefortrie:card-add
Oct 30, 2018
Merged
card add #1373
Changes from all commits
Commits
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
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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
173 changes: 173 additions & 0 deletions
173
assets/js/test-unit/theme/common/payment-method.spec.js
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,173 @@ | ||
import { creditCardType, storeInstrument, Formatters, Validators } from '../../../theme/common/payment-method'; | ||
|
||
describe('PaymentMethod', () => { | ||
describe('creditCardType', () => { | ||
it('should return a credit card type from the first six caracters of a given string', () => { | ||
expect(creditCardType('370000')).toEqual('American Express'); | ||
expect(creditCardType('388000')).toEqual('Diners Club'); | ||
expect(creditCardType('601100')).toEqual('Discover'); | ||
expect(creditCardType('516300')).toEqual('Mastercard'); | ||
expect(creditCardType('411100')).toEqual('Visa'); | ||
}); | ||
}); | ||
|
||
describe('Formatters', () => { | ||
let $form; | ||
|
||
beforeEach(() => { | ||
$form = $( | ||
`<form> | ||
<input name="credit_card_number" /> | ||
<input name="expiration" /> | ||
'</form>` | ||
); | ||
$form.appendTo(document.body); | ||
}); | ||
|
||
afterEach(() => { | ||
$form.remove(); | ||
}); | ||
|
||
describe('setCreditCardNumberFormat', () => { | ||
it('should be formatting the credit card number in a corresponding credit card type format', () => { | ||
Formatters.setCreditCardNumberFormat('form input[name="credit_card_number"]'); | ||
const input = $('form input[name="credit_card_number"]'); | ||
|
||
expect(input.val('370000000000000').trigger('keyup').val()).toEqual('3700 000000 00000'); | ||
expect(input.val('38000000000000').trigger('keyup').val()).toEqual('3800 000000 0000'); | ||
expect(input.val('6011000000000000').trigger('keyup').val()).toEqual('6011 0000 0000 0000'); | ||
expect(input.val('5163000000000000').trigger('keyup').val()).toEqual('5163 0000 0000 0000'); | ||
expect(input.val('4111000000000000').trigger('keyup').val()).toEqual('4111 0000 0000 0000'); | ||
}); | ||
}); | ||
|
||
describe('setExpirationFormat', () => { | ||
it('should be formatting the expiration as month/year', () => { | ||
Formatters.setExpirationFormat('form input[name="expiration"]'); | ||
const input = $('form input[name="expiration"]'); | ||
|
||
expect(input.val('1120').trigger('keyup').val()).toEqual('11/20'); | ||
expect(input.val('0120').trigger('keyup').val()).toEqual('01/20'); | ||
}); | ||
|
||
it('should be adding a separator after month in two digits', () => { | ||
Formatters.setExpirationFormat('form input[name="expiration"]'); | ||
const event = $.Event('keyup'); | ||
const input = $('form input[name="expiration"]'); | ||
input.val('11').trigger(event); | ||
|
||
expect(event.target.value).toEqual('11/'); | ||
}); | ||
|
||
it('should be removing a separator after month on delete', () => { | ||
Formatters.setExpirationFormat('form input[name="expiration"]'); | ||
const event = $.Event('keyup', { which: 8, ctrlKey: false }); | ||
const input = $('form input[name="expiration"]'); | ||
input.val('11/').trigger(event); | ||
|
||
expect(event.target.value).toEqual('11'); | ||
}); | ||
|
||
it('should be completing month for intergers superior to one', () => { | ||
Formatters.setExpirationFormat('form input[name="expiration"]'); | ||
const event = $.Event('keyup'); | ||
const input = $('form input[name="expiration"]'); | ||
input.val('2').trigger(event); | ||
|
||
expect(event.target.value).toEqual('02/'); | ||
}); | ||
|
||
it('should not have more than two separators', () => { | ||
Formatters.setExpirationFormat('form input[name="expiration"]'); | ||
const event = $.Event('keyup'); | ||
const input = $('form input[name="expiration"]'); | ||
input.val('11//').trigger(event); | ||
|
||
expect(event.target.value).toEqual('11/'); | ||
}); | ||
|
||
it('should not have more than two zero', () => { | ||
Formatters.setExpirationFormat('form input[name="expiration"]'); | ||
const event = $.Event('keyup'); | ||
const input = $('form input[name="expiration"]'); | ||
input.val('00').trigger(event); | ||
|
||
expect(event.target.value).toEqual('0'); | ||
}); | ||
}); | ||
}); | ||
|
||
describe('Validators', () => { | ||
describe('setCreditCardNumberValidation', () => { | ||
it('should have invalid input credit card number', () => { | ||
const callback = jasmine.createSpy(); | ||
const validator = { add: ({ validate }) => validate(callback, '4444 3333 2222') }; | ||
Validators.setCreditCardNumberValidation(validator, 'selector'); | ||
|
||
expect(callback).toHaveBeenCalledWith(false); | ||
}); | ||
|
||
it('should have valid input credit card number', () => { | ||
const callback = jasmine.createSpy(); | ||
const validator = { add: ({ validate }) => validate(callback, '4444 3333 2222 1111') }; | ||
Validators.setCreditCardNumberValidation(validator, 'selector'); | ||
|
||
expect(callback).toHaveBeenCalledWith(true); | ||
}); | ||
}); | ||
|
||
describe('setExpirationValidation', () => { | ||
it('should have invalid input expiration date', () => { | ||
const callback = jasmine.createSpy(); | ||
const validator = { add: ({ validate }) => validate(callback, '01/17') }; | ||
Validators.setExpirationValidation(validator, 'selector'); | ||
|
||
expect(callback).toHaveBeenCalledWith(false); | ||
}); | ||
|
||
it('should have valid input expiration date', () => { | ||
const callback = jasmine.createSpy(); | ||
const validator = { add: ({ validate }) => validate(callback, '12/20') }; | ||
Validators.setExpirationValidation(validator, 'selector'); | ||
|
||
expect(callback).toHaveBeenCalledWith(true); | ||
}); | ||
}); | ||
|
||
describe('setNameOnCardValidation', () => { | ||
it('should have invalid input name on card', () => { | ||
const callback = jasmine.createSpy(); | ||
const validator = { add: ({ validate }) => validate(callback, '') }; | ||
Validators.setNameOnCardValidation(validator, 'selector'); | ||
|
||
expect(callback).toHaveBeenCalledWith(false); | ||
}); | ||
|
||
it('should have valid input name on card', () => { | ||
const callback = jasmine.createSpy(); | ||
const validator = { add: ({ validate }) => validate(callback, 'Foo Bar') }; | ||
Validators.setNameOnCardValidation(validator, 'selector'); | ||
|
||
expect(callback).toHaveBeenCalledWith(true); | ||
}); | ||
}); | ||
|
||
describe('setCvvValidation', () => { | ||
it('should have invalid input cvv', () => { | ||
const callback = jasmine.createSpy(); | ||
const validator = { add: ({ validate }) => validate(callback, '12') }; | ||
Validators.setCvvValidation(validator, 'selector'); | ||
|
||
expect(callback).toHaveBeenCalledWith(false); | ||
}); | ||
|
||
it('should have valid input cvv', () => { | ||
const callback = jasmine.createSpy(); | ||
const validator = { add: ({ validate }) => validate(callback, '123') }; | ||
Validators.setCvvValidation(validator, 'selector'); | ||
|
||
expect(callback).toHaveBeenCalledWith(true); | ||
}); | ||
}); | ||
}); | ||
}); |
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.
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.
Hey @junedkazi , we have removed the dynamic input fields for the static components. however, I had to inject the validation through javascript because it was breaking the template engine.