-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: pr review, adding test and validation for address
- Loading branch information
Showing
8 changed files
with
143 additions
and
19 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 +1 @@ | ||
export { default } from './address-input'; | ||
export { AddressInput } from './address-input'; |
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,2 +1,3 @@ | ||
export { AmountSelector } from './amount-selector'; | ||
export { NetworkSelector } from './network-selector'; | ||
export { AddressInput } from './address-input'; |
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
87 changes: 87 additions & 0 deletions
87
packages/widget/tests/unit/components/address-input/address-input.test.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,87 @@ | ||
import { afterEach, assert, describe, it, vi } from 'vitest'; | ||
import { fixture, fixtureCleanup, oneEvent } from '@open-wc/testing-helpers'; | ||
import { html } from 'lit'; | ||
import { AddressInput } from '../../../../src/components'; | ||
|
||
describe('address-input component', function () { | ||
afterEach(() => { | ||
fixtureCleanup(); | ||
}); | ||
|
||
const handleAddress = (address: string) => console.log(address); | ||
|
||
it('is defined', () => { | ||
const el = document.createElement('sygma-address-input'); | ||
assert.instanceOf(el, AddressInput); | ||
}); | ||
it('renders input field with address value', async () => { | ||
const el = await fixture(html` | ||
<sygma-address-input | ||
.address=${'0x123'} | ||
.handleAddress=${handleAddress} | ||
></sygma-address-input> | ||
`); | ||
|
||
const input = el.shadowRoot!.querySelector( | ||
'.input-address' | ||
) as HTMLInputElement; | ||
|
||
console.log(input.value); | ||
assert.equal(input.value, '0x123'); | ||
}); | ||
it('triggers callback on address change and validates Substrate address', async () => { | ||
const mockAddressChangeHandler = vi.fn(); | ||
|
||
const el = await fixture(html` | ||
<sygma-address-input | ||
.network=${'substrate'} | ||
.handleAddress=${mockAddressChangeHandler} | ||
></sygma-address-input> | ||
`); | ||
|
||
const input = el.shadowRoot!.querySelector( | ||
'.input-address' | ||
) as HTMLInputElement; | ||
|
||
const listener = oneEvent(input, 'change', false); | ||
|
||
input.value = '42sydUvocBuEorweEPqxY5vZae1VaTtWoJFiKMrPbRamy2BL'; | ||
|
||
input.dispatchEvent(new Event('change')); | ||
|
||
await listener; | ||
|
||
assert.equal(mockAddressChangeHandler.mock.calls.length, 1); | ||
assert.deepEqual(mockAddressChangeHandler.mock.lastCall, [ | ||
'42sydUvocBuEorweEPqxY5vZae1VaTtWoJFiKMrPbRamy2BL' | ||
]); | ||
}); | ||
|
||
it('triggers callback on address change and validates Ethereum address', async () => { | ||
const mockAddressChangeHandler = vi.fn(); | ||
|
||
const el = await fixture(html` | ||
<sygma-address-input | ||
.network=${'evm'} | ||
.handleAddress=${mockAddressChangeHandler} | ||
></sygma-address-input> | ||
`); | ||
|
||
const input = el.shadowRoot!.querySelector( | ||
'.input-address' | ||
) as HTMLInputElement; | ||
|
||
const listener = oneEvent(input, 'change', false); | ||
|
||
input.value = '0xebFC7A970CAAbC18C8e8b7367147C18FC7585492'; | ||
|
||
input.dispatchEvent(new Event('change')); | ||
|
||
await listener; | ||
|
||
assert.equal(mockAddressChangeHandler.mock.calls.length, 1); | ||
assert.deepEqual(mockAddressChangeHandler.mock.lastCall, [ | ||
'0xebFC7A970CAAbC18C8e8b7367147C18FC7585492' | ||
]); | ||
}); | ||
}); |
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