Skip to content

Commit

Permalink
fix: unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
darrenvechain committed Dec 4, 2023
1 parent ff5cb21 commit a7d2639
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 17 deletions.
12 changes: 5 additions & 7 deletions packages/dapp-kit-react/src/provider/ThemeProvider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ interface Theme {
mode: ThemeMode;
}

interface ContextProperties {
interface ThemeContextProperties {
theme: Theme;
toggleTheme: () => void;
}
Expand All @@ -18,11 +18,9 @@ const defaultTheme: Theme = {
mode: 'LIGHT',
};

const ThemeContext = createContext<ContextProperties>({
theme: defaultTheme,
// eslint-disable-next-line @typescript-eslint/no-empty-function
toggleTheme: () => {},
});
const ThemeContext = createContext<ThemeContextProperties | undefined>(
undefined,
);

const ThemeProvider = ({ children }: { children: ReactNode }) => {
const [currentTheme, setCurrentTheme] = useState(defaultTheme);
Expand All @@ -46,4 +44,4 @@ const ThemeProvider = ({ children }: { children: ReactNode }) => {
);
};

export { ThemeProvider, ThemeContext };
export { ThemeProvider, ThemeContext, type ThemeContextProperties };
11 changes: 7 additions & 4 deletions packages/dapp-kit-react/test/helpers/react-test-helpers.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,15 @@ import {
DAppKitProvider,
SelectWalletModal,
} from '../../src';
import { ThemeProvider } from '../../src/provider/ThemeProvider';

export const wrapper = ({ children }: { children?: React.ReactNode }) => (
<DAppKitProvider nodeUrl="https://testnet.vechain.org">
{children}
<ConnectWalletButtonWithModal />
<SelectWalletModal isOpen={false} />
<ConnectWalletModal isOpen={false} />
<ThemeProvider>
{children}
<ConnectWalletButtonWithModal />
<SelectWalletModal isOpen={false} />
<ConnectWalletModal isOpen={false} />
</ThemeProvider>
</DAppKitProvider>
);
13 changes: 8 additions & 5 deletions packages/dapp-kit-react/test/provider/ThemeProvider.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,15 @@ describe('useThemeContext', () => {

expect(result.current).toBeDefined();

expect(result.current.theme).toEqual({ mode: 'LIGHT' });
expect(result.current?.theme).toEqual({ mode: 'LIGHT' });

result.current.toggleTheme();
result.current?.toggleTheme();

await waitFor(() => {
expect(result.current.theme).toEqual({ mode: 'DARK' });
});
await waitFor(
() => {
expect(result.current?.theme).toEqual({ mode: 'DARK' });
},
{ timeout: 3000 },
);
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ export class ConnectButtonWithModal extends LitElement {
}

private handleOpen = (): void => {
this.open = false;
this.open = true;
DAppKitUI.wallet.disconnect();
this.requestUpdate();
};
Expand Down

0 comments on commit a7d2639

Please sign in to comment.