Skip to content

Commit 2008b09

Browse files
authored
Merge pull request meshtastic#494 from danditomaso/issue-486-are-you-sure-dialog
Issue 486 are you sure dialog
2 parents 0296b24 + 491f72b commit 2008b09

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

47 files changed

+1294
-282
lines changed

deno.lock

+2-111
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/__mocks__/README.md

+43
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
# Mocks Directory
2+
3+
This directory contains mock implementations used by Vitest for testing.
4+
5+
## Structure
6+
7+
The directory structure mirrors the actual project structure to make mocking
8+
more intuitive:
9+
10+
```
11+
__mocks__/
12+
├── components/
13+
│ └── UI/
14+
│ ├── Dialog.tsx
15+
│ ├── Button.tsx
16+
│ ├── Checkbox.tsx
17+
│ └── ...
18+
├── core/
19+
│ └── ...
20+
└── ...
21+
```
22+
23+
## Auto-mocking
24+
25+
Vitest will automatically use the mock files in this directory when the
26+
corresponding module is imported in tests. For example, when a test imports
27+
`@components/UI/Dialog.tsx`, Vitest will use
28+
`__mocks__/components/UI/Dialog.tsx` instead.
29+
30+
## Creating New Mocks
31+
32+
To create a new mock:
33+
34+
1. Create a file in the same relative path as the original module
35+
2. Export the mocked functionality with the same names as the original
36+
3. Add a `vi.mock()` statement to `vitest.setup.ts` if needed
37+
38+
## Mock Guidelines
39+
40+
- Keep mocks as simple as possible
41+
- Use `data-testid` attributes for easy querying in tests
42+
- Implement just enough functionality to test the component
43+
- Use TypeScript types to ensure compatibility with the original module
+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import { vi } from 'vitest'
2+
3+
vi.mock('@components/UI/Button.tsx', () => ({
4+
Button: ({ children, name, disabled, onClick }: {
5+
children: React.ReactNode,
6+
variant: string,
7+
name: string,
8+
disabled?: boolean,
9+
onClick: () => void
10+
}) =>
11+
<button
12+
type="button"
13+
name={name}
14+
data-testid={`button-${name}`}
15+
disabled={disabled}
16+
onClick={onClick}
17+
>
18+
{children}
19+
</button>
20+
}));
+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
import { vi } from 'vitest'
2+
3+
vi.mock('@components/UI/Checkbox.tsx', () => ({
4+
Checkbox: ({ id, checked, onChange }: { id: string, checked: boolean, onChange: () => void }) =>
5+
<input data-testid="checkbox" type="checkbox" id={id} checked={checked} onChange={onChange} />
6+
}));
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
import React from 'react';
2+
3+
export const Dialog = ({ children, open }: {
4+
children: React.ReactNode,
5+
open: boolean,
6+
onOpenChange?: (open: boolean) => void
7+
}) => open ? <div data-testid="dialog">{children}</div> : null;
8+
9+
export const DialogContent = ({
10+
children,
11+
className
12+
}: {
13+
children: React.ReactNode,
14+
className?: string
15+
}) => <div data-testid="dialog-content" className={className}>{children}</div>;
16+
17+
export const DialogHeader = ({
18+
children
19+
}: {
20+
children: React.ReactNode
21+
}) => <div data-testid="dialog-header">{children}</div>;
22+
23+
export const DialogTitle = ({
24+
children
25+
}: {
26+
children: React.ReactNode
27+
}) => <div data-testid="dialog-title">{children}</div>;
28+
29+
export const DialogDescription = ({
30+
children,
31+
className
32+
}: {
33+
children: React.ReactNode,
34+
className?: string
35+
}) => <div data-testid="dialog-description" className={className}>{children}</div>;
36+
37+
export const DialogFooter = ({
38+
children,
39+
className
40+
}: {
41+
children: React.ReactNode,
42+
className?: string
43+
}) => <div data-testid="dialog-footer" className={className}>{children}</div>;

src/__mocks__/components/UI/Label.tsx

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
import { vi } from 'vitest'
2+
3+
vi.mock('@components/UI/Label.tsx', () => ({
4+
Label: ({ children, htmlFor, className }: { children: React.ReactNode, htmlFor: string, className?: string }) =>
5+
<label data-testid="label" htmlFor={htmlFor} className={className}>{children}</label>
6+
}));

src/__mocks__/components/UI/Link.tsx

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import { vi } from "vitest";
2+
3+
vi.mock('@components/UI/Typography/Link.tsx', () => ({
4+
Link: ({ children, href, className }: { children: React.ReactNode, href: string, className?: string }) =>
5+
<a data-testid="link" href={href} className={className}>{children}</a>
6+
}));
7+

src/components/Dialog/DeviceNameDialog.tsx

+2
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { create } from "@bufbuild/protobuf";
33
import { Button } from "@components/UI/Button.tsx";
44
import {
55
Dialog,
6+
DialogClose,
67
DialogContent,
78
DialogDescription,
89
DialogFooter,
@@ -52,6 +53,7 @@ export const DeviceNameDialog = ({
5253
return (
5354
<Dialog open={open} onOpenChange={onOpenChange}>
5455
<DialogContent>
56+
<DialogClose />
5557
<DialogHeader>
5658
<DialogTitle>Change Device Name</DialogTitle>
5759
<DialogDescription>

0 commit comments

Comments
 (0)