-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* chore: adding tests for core dapp-kit * chore: revert eslint config * chore: revert eslint config * chore: update GH actions * chore: add dapp kit UI tests * chore: move to dev deps * fix: remove useless Id * fix: not using internal connex libs
- Loading branch information
1 parent
d41f892
commit 5f59d5e
Showing
27 changed files
with
468 additions
and
48 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
node_modules/* | ||
dist/* | ||
web-dev-server.config.js | ||
tsup.config.ts | ||
**/test/** | ||
vite.config.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 |
---|---|---|
|
@@ -2,3 +2,5 @@ node_modules/* | |
dist/* | ||
web-dev-server.config.js | ||
tsup.config.ts | ||
test | ||
vite.config.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 |
---|---|---|
@@ -1,11 +1,10 @@ | ||
/node_modules/ | ||
/lib/ | ||
/test/ | ||
custom-elements.json | ||
# top level source | ||
my-element.js | ||
my-element.js.map | ||
my-element.d.ts | ||
my-element.d.ts.map | ||
# only generated for size check | ||
my-element.bundled.js | ||
my-element.bundled.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
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,3 +1,5 @@ | ||
import './components'; | ||
|
||
export * from './client'; | ||
export * from './assets'; | ||
export * from './components'; | ||
|
57 changes: 57 additions & 0 deletions
57
packages/dapp-kit-ui/test/connect-buton-with-modal.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,57 @@ | ||
import { beforeEach, describe, expect, it } from 'vitest'; | ||
|
||
import { | ||
ConnectButton, | ||
ConnectButtonWithModal, | ||
ConnectModal, | ||
DAppKit, | ||
SourceInfo, | ||
} from '../src'; | ||
import { elementQueries } from './helpers/elemnt-queries'; | ||
import { WalletSource } from '@vechainfoundation/dapp-kit/src'; | ||
|
||
describe('connect-button-with-modal', () => { | ||
beforeEach(() => { | ||
DAppKit.configure({ nodeUrl: 'https://mainnet.vechain.org/' }); | ||
}); | ||
|
||
it('Should callback with source when user clicks a wallet', async () => { | ||
const element: ConnectButtonWithModal = window.document.createElement( | ||
'vwk-connect-button-with-modal', | ||
); | ||
|
||
let selectedSource: WalletSource | undefined; | ||
|
||
element.onSourceClick = (source?: SourceInfo) => { | ||
selectedSource = source?.id; | ||
}; | ||
|
||
window.document.body.appendChild(element); | ||
|
||
const connectButton = | ||
(await elementQueries.getConnectButton()) as ConnectButton; | ||
const connectModal = | ||
(await elementQueries.getConnectModal()) as ConnectModal; | ||
|
||
expect(connectModal).toBeDefined(); | ||
expect(connectButton).toBeDefined(); | ||
|
||
expect(connectModal.open).toBe(false); | ||
|
||
connectButton.shadowRoot?.querySelector('button')?.click(); | ||
|
||
await new Promise((resolve) => setTimeout(resolve, 1000)); | ||
|
||
expect(connectModal.open).toBe(true); | ||
|
||
const sourceCards = await elementQueries.getAllSourceCards(); | ||
|
||
expect(sourceCards.length).toBeGreaterThan(0); | ||
|
||
sourceCards[0]?.shadowRoot?.querySelector('div')?.click(); | ||
|
||
await new Promise((resolve) => setTimeout(resolve, 1000)); | ||
|
||
expect(selectedSource).toBeDefined(); | ||
}); | ||
}); |
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,69 @@ | ||
import { ConnectButton, ConnectModal, SourceCard } from '../../src'; | ||
|
||
const performQueryWithTimeout = async <T>( | ||
timeout: number, | ||
query: () => T | undefined | null, | ||
): Promise<T | undefined | null> => { | ||
const startTime = Date.now(); | ||
|
||
let element = query(); | ||
|
||
while (!element && Date.now() - startTime < timeout) { | ||
await new Promise((resolve) => setTimeout(resolve, 10)); | ||
element = query(); | ||
} | ||
|
||
return element; | ||
}; | ||
|
||
const getConnectButton = ( | ||
timeout = 2000, | ||
): Promise<ConnectButton | undefined | null> => { | ||
return performQueryWithTimeout(timeout, () => | ||
window.document.body | ||
.querySelector('vwk-connect-button-with-modal') | ||
?.shadowRoot?.querySelector('vwk-connect-button'), | ||
); | ||
}; | ||
|
||
const getConnectModal = (): Promise<ConnectModal | undefined | null> => { | ||
return performQueryWithTimeout(2000, () => | ||
window.document.body | ||
.querySelector('vwk-connect-button-with-modal') | ||
?.shadowRoot?.querySelector('vwk-connect-modal'), | ||
); | ||
}; | ||
const getAllSourceCards = async (): Promise<SourceCard[]> => { | ||
const res = await performQueryWithTimeout(2000, () => | ||
window.document.body | ||
.querySelector('vwk-connect-button-with-modal') | ||
?.shadowRoot?.querySelector('vwk-connect-modal') | ||
?.shadowRoot?.querySelector('vwk-base-modal') | ||
?.querySelectorAll('vwk-source-card'), | ||
); | ||
|
||
const sourceCards: SourceCard[] = []; | ||
|
||
res?.forEach((sourceCard) => { | ||
sourceCards.push(sourceCard); | ||
}); | ||
|
||
return sourceCards; | ||
}; | ||
|
||
const getWalletConnectQrCode = () => { | ||
return performQueryWithTimeout(2000, () => | ||
window.document.body | ||
.querySelector('vwk-connect-button-with-modal') | ||
?.shadowRoot?.querySelector('vwk-connect-modal') | ||
?.shadowRoot?.querySelector('vwk-base-modal') | ||
?.querySelector('vwk-wallet-connect-qrcode'), | ||
); | ||
}; | ||
|
||
export const elementQueries = { | ||
getConnectButton, | ||
getConnectModal, | ||
getAllSourceCards, | ||
getWalletConnectQrCode, | ||
}; |
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,51 @@ | ||
import { describe, expect, it } from 'vitest'; | ||
import { | ||
ConnectButton, | ||
ConnectButtonWithModal, | ||
DAppKit, | ||
dispatchCustomEvent, | ||
WalletConnectQrCode, | ||
} from '../src'; | ||
import { elementQueries } from './helpers/elemnt-queries'; | ||
|
||
const sampleUri = | ||
'wc:59f6594baa77ca343197f60436e5a188708b045e323aa4d6ce93722772e18deb@2?relay-protocol=irn&symKey=0422890abbd3baf75cefad89e822b01071cd906705d6c9282596de866376a824'; | ||
|
||
describe('qr-code-modal', () => { | ||
beforeEach(() => { | ||
DAppKit.configure({ | ||
nodeUrl: 'https://mainnet.vechain.org/', | ||
walletConnectOptions: { | ||
projectId: '123', | ||
metadata: { | ||
name: 'VeChain', | ||
description: 'VeChain', | ||
icons: ['https://vechain.org/images/logo.svg'], | ||
url: 'https://vechain.org', | ||
}, | ||
}, | ||
}); | ||
}); | ||
|
||
it('should display QR code', async () => { | ||
const element: ConnectButtonWithModal = window.document.createElement( | ||
'vwk-connect-button-with-modal', | ||
); | ||
|
||
window.document.body.appendChild(element); | ||
|
||
const connectButton = | ||
(await elementQueries.getConnectButton()) as ConnectButton; | ||
|
||
connectButton.shadowRoot?.querySelector('button')?.click(); | ||
|
||
dispatchCustomEvent('vwk-open-wc-modal', { uri: sampleUri }); | ||
|
||
const qrCode = | ||
(await elementQueries.getWalletConnectQrCode()) as WalletConnectQrCode; | ||
|
||
expect(qrCode).toBeDefined(); | ||
|
||
expect(qrCode.walletConnectQRcode).toBe(sampleUri); | ||
}); | ||
}); |
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,17 @@ | ||
import { vi } from 'vitest'; | ||
|
||
vi.mock('@walletconnect/modal'); | ||
|
||
Object.defineProperty(window, 'matchMedia', { | ||
writable: true, | ||
value: vi.fn().mockImplementation((query) => ({ | ||
matches: false, | ||
media: query, | ||
onchange: null, | ||
addListener: vi.fn(), // deprecated | ||
removeListener: vi.fn(), // deprecated | ||
addEventListener: vi.fn(), | ||
removeEventListener: vi.fn(), | ||
dispatchEvent: vi.fn(), | ||
})), | ||
}); |
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,29 @@ | ||
/// <reference types="vitest" /> | ||
import { defineConfig } from 'vitest/config'; | ||
import { resolve } from 'node:path'; // eslint-disable-next-line import/no-default-export | ||
|
||
// eslint-disable-next-line import/no-default-export | ||
export default defineConfig({ | ||
test: { | ||
include: ['test/**/*.test.ts'], | ||
environment: 'jsdom', | ||
reporters: 'dot', | ||
setupFiles: [resolve(__dirname, 'test/setup/setup.ts')], | ||
coverage: { | ||
reporter: [ | ||
'text', | ||
'json', | ||
'html', | ||
'lcov', | ||
'json-summary', | ||
'text-summary', | ||
'text', | ||
], | ||
lines: 80, | ||
statements: 80, | ||
functions: 60, | ||
branches: 80, | ||
}, | ||
globals: 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
node_modules/* | ||
dist/* | ||
web-dev-server.config.js | ||
tsup.config.ts | ||
test | ||
vite.config.ts |
File renamed without changes.
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
Oops, something went wrong.