Skip to content

Commit

Permalink
feat: added test workflow (#10)
Browse files Browse the repository at this point in the history
Co-authored-by: Alissa Crane <[email protected]>
  • Loading branch information
abcrane123 and alissacrane-cb authored Aug 8, 2024
1 parent 195c1c0 commit fd8a462
Show file tree
Hide file tree
Showing 5 changed files with 107 additions and 7 deletions.
26 changes: 26 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
name: Kit Test
on:
push:
branches: ['main']
pull_request:
branches: ['main']
jobs:
build:
runs-on: ubuntu-latest
strategy:
matrix:
node-version: [18.x]
# See supported Node.js release schedule at https://nodejs.org/en/about/releases/
steps:
- name: Checkout
uses: actions/checkout@v4

- name: Setup Bun
uses: oven-sh/setup-bun@v2

- name: Template Install dependencies
run: bun install

- name: Kit Test
# When fails, please check your tests
run: bun run test:coverage
42 changes: 42 additions & 0 deletions src/components/TransactionWrapper.test.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import { QueryClient, QueryClientProvider } from '@tanstack/react-query';
import { render, screen } from '@testing-library/react';
import { describe, expect, it } from 'vitest';
import { http, WagmiProvider, createConfig } from 'wagmi';
import { base } from 'wagmi/chains';
import { mock } from 'wagmi/connectors';
import TransactionWrapper from './TransactionWrapper';

const config = createConfig({
chains: [base],
connectors: [
mock({
accounts: [
'0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266',
'0x70997970c51812dc3a010c7d01b50e0d17dc79c8',
'0x3C44CdDdB6a900fa2b585dd299e03d12FA4293BC',
],
}),
],
transports: {
[base.id]: http(),
},
});
const queryClient = new QueryClient();

const renderWithProviders = (component: JSX.Element) => {
return render(
<WagmiProvider config={config}>
<QueryClientProvider client={queryClient}>
{component}
</QueryClientProvider>
</WagmiProvider>,
);
};

describe('TransactionWrapper', () => {
it('should renders', () => {
renderWithProviders(<TransactionWrapper address="0x" />);
const transaction = screen.getByText('Collect');
expect(transaction).toBeInTheDocument();
});
});
6 changes: 3 additions & 3 deletions src/components/TransactionWrapper.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ import type {
TransactionError,
TransactionResponse,
} from '@coinbase/onchainkit/transaction';
import type { Address, ContractFunctionParameters } from 'viem';
import { parseEther } from 'viem';
import {
BASE_SEPOLIA_CHAIN_ID,
collectionAddress,
Expand All @@ -19,9 +21,7 @@ import {
mintReferral,
quantity,
tokenId,
} from 'src/constants';
import type { Address, ContractFunctionParameters } from 'viem';
import { parseEther } from 'viem';
} from '../constants';

type TransactionWrapperParams = {
address: Address;
Expand Down
38 changes: 35 additions & 3 deletions src/components/WalletWrapper.test.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,42 @@
import { render } from '@testing-library/react';
import { QueryClient, QueryClientProvider } from '@tanstack/react-query';
import { render, screen } from '@testing-library/react';
import { describe, expect, it } from 'vitest';
import { http, WagmiProvider, createConfig } from 'wagmi';
import { base } from 'wagmi/chains';
import { mock } from 'wagmi/connectors';
import WalletWrapper from './WalletWrapper';

const config = createConfig({
chains: [base],
connectors: [
mock({
accounts: [
'0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266',
'0x70997970c51812dc3a010c7d01b50e0d17dc79c8',
'0x3C44CdDdB6a900fa2b585dd299e03d12FA4293BC',
],
}),
],
transports: {
[base.id]: http(),
},
});
const queryClient = new QueryClient();

const renderWithProviders = (Component: React.ComponentType) => {
return render(
<WagmiProvider config={config}>
<QueryClientProvider client={queryClient}>
<Component />
</QueryClientProvider>
</WagmiProvider>,
);
};

describe('WalletWrapper', () => {
it('should renders', () => {
render(<WalletWrapper />);
expect(true).toBeTruthy();
renderWithProviders(WalletWrapper);
const wallet = screen.getByTestId('ockConnectWallet_Container');

This comment has been minimized.

Copy link
@Themoor1

Themoor1 Nov 27, 2024

304402206883f9de55547576ffa1af1e87d20b8c94d073a8c45be6082996b8faa7e2ce4102207dc3193f1bba20d929a20cc77df3269e1cc60e1fab36a705ba0866cb27d99cb801

This comment has been minimized.

Copy link
@Themoor1

Themoor1 Nov 27, 2024

See https://portal.cdp.coinbase.com/products/onchainkit

NEXT_PUBLIC_CDP_API_KEY="GET_FROM_COINBASE_DEVELOPER_PLATFORM"

See https://cloud.walletconnect.com

NEXT_PUBLIC_WC_PROJECT_ID="GET_FROM_WALLET_CONNECT"

expect(wallet).toBeInTheDocument();
});
});
2 changes: 1 addition & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
"moduleResolution": "bundler",
"resolveJsonModule": true,
"isolatedModules": true,
"jsx": "preserve",
"jsx": "react-jsx",
"incremental": true,
"plugins": [
{
Expand Down

0 comments on commit fd8a462

Please sign in to comment.