Skip to content
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

Add test workflow #10

Merged
merged 6 commits into from
Aug 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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');
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