-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: more adjustments in the tests
- Loading branch information
1 parent
8faf680
commit defdb68
Showing
6 changed files
with
83 additions
and
169 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,85 +1,62 @@ | ||
import { | ||
formElementsMock, | ||
formValuesMock, | ||
handleFormMock, | ||
} from 'tests/mocks/common-configurations' | ||
import { formValuesMock } from 'tests/mocks/common-configurations' | ||
import { getFormValues } from './form-values' | ||
import { generateForm, generateFormEmptyValues } from 'tests/mocks/form-dom' | ||
|
||
function Form() { | ||
const { form, holderNameInput, cvvInput, expirationDateInput, numberInput } = | ||
handleFormMock() | ||
|
||
form.setAttribute(formElementsMock.form, '') | ||
holderNameInput.setAttribute(formElementsMock.holderName, '') | ||
numberInput.setAttribute(formElementsMock.number, '') | ||
cvvInput.setAttribute(formElementsMock.cvv, '') | ||
expirationDateInput.setAttribute(formElementsMock.expirationDate, '') | ||
|
||
document.body.appendChild(form) | ||
form.appendChild(holderNameInput) | ||
form.appendChild(numberInput) | ||
form.appendChild(expirationDateInput) | ||
form.appendChild(cvvInput) | ||
} | ||
describe('getFormValues', () => { | ||
beforeEach(() => { | ||
document.body.innerHTML = '' | ||
}) | ||
test('should be the values of elements equals to sended', () => { | ||
Form() | ||
|
||
const inputs = document.querySelectorAll('input') | ||
inputs[0].value = formValuesMock.holderName | ||
inputs[1].value = formValuesMock.number | ||
inputs[2].value = formValuesMock.expirationDate | ||
inputs[3].value = formValuesMock.cvv | ||
|
||
const formValue = getFormValues({ | ||
form: 'data-malga-tokenization-form', | ||
holderName: 'data-malga-tokenization-holder-name', | ||
number: 'data-malga-tokenization-number', | ||
expirationDate: 'data-malga-tokenization-expiration-date', | ||
cvv: 'data-malga-tokenization-cvv', | ||
describe('form-values', () => { | ||
beforeEach(() => { | ||
document.body.innerHTML = '' | ||
}) | ||
|
||
expect(formValue.holderName).toEqual('Taylor Swift') | ||
expect(formValue.number).toEqual('5173000265860114') | ||
expect(formValue.expirationDate).toEqual('05/08/2024') | ||
expect(formValue.cvv).toEqual('114') | ||
}) | ||
test("should be returned empty when elements aren't finded", () => { | ||
Form() | ||
|
||
const formValue = getFormValues({ | ||
form: 'data-malga-tokenization-form', | ||
holderName: 'data-malga-tokenization-holder-name', | ||
number: 'data-malga-tokenization-number', | ||
expirationDate: 'data-malga-tokenization-expiration-date', | ||
cvv: 'data-malga-tokenization-cvv', | ||
test('should be the values of elements equals to sended', () => { | ||
generateForm() | ||
|
||
const formValue = getFormValues({ | ||
form: 'data-malga-tokenization-form', | ||
holderName: 'data-malga-tokenization-holder-name', | ||
number: 'data-malga-tokenization-number', | ||
expirationDate: 'data-malga-tokenization-expiration-date', | ||
cvv: 'data-malga-tokenization-cvv', | ||
}) | ||
|
||
expect(formValue.holderName).toEqual('Taylor Swift') | ||
expect(formValue.number).toEqual('5173000265860114') | ||
expect(formValue.expirationDate).toEqual('05/08/2024') | ||
expect(formValue.cvv).toEqual('114') | ||
}) | ||
test('should be returned elements with empty values', () => { | ||
generateFormEmptyValues() | ||
|
||
const formValue = getFormValues({ | ||
form: 'data-malga-tokenization-form', | ||
holderName: 'data-malga-tokenization-holder-name', | ||
number: 'data-malga-tokenization-number', | ||
expirationDate: 'data-malga-tokenization-expiration-date', | ||
cvv: 'data-malga-tokenization-cvv', | ||
}) | ||
|
||
expect(formValue.holderName).toBe('') | ||
expect(formValue.number).toBe('') | ||
expect(formValue.expirationDate).toBe('') | ||
expect(formValue.cvv).toBe('') | ||
}) | ||
test('should be possible to return error if the elements are not found', () => { | ||
generateForm() | ||
|
||
const inputs = document.querySelectorAll('input') | ||
inputs[0].value = formValuesMock.holderName | ||
inputs[1].value = formValuesMock.number | ||
inputs[2].value = formValuesMock.expirationDate | ||
inputs[3].value = formValuesMock.cvv | ||
|
||
expect(() => | ||
getFormValues({ | ||
form: 'data-malga-form', | ||
holderName: 'data-malga-holder-name', | ||
number: 'data-malga-number', | ||
expirationDate: 'data-malga-expiration-date', | ||
cvv: 'data-malga-cvv', | ||
}), | ||
).toThrowError() | ||
}) | ||
|
||
expect(formValue.holderName).toBe('') | ||
expect(formValue.number).toBe('') | ||
expect(formValue.expirationDate).toBe('') | ||
expect(formValue.cvv).toBe('') | ||
}) | ||
test('should be possible to return error if the elements are not found', () => { | ||
Form() | ||
|
||
const inputs = document.querySelectorAll('input') | ||
inputs[0].value = formValuesMock.holderName | ||
inputs[1].value = formValuesMock.number | ||
inputs[2].value = formValuesMock.expirationDate | ||
inputs[3].value = formValuesMock.cvv | ||
|
||
expect(() => | ||
getFormValues({ | ||
form: 'data-malga-form', | ||
holderName: 'data-malga-holder-name', | ||
number: 'data-malga-number', | ||
expirationDate: 'data-malga-expiration-date', | ||
cvv: 'data-malga-cvv', | ||
}), | ||
).toThrowError() | ||
}) | ||
}) |
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