Skip to content

Commit c6e85d2

Browse files
feat(manager-wiki): update how to add component
ref: #MANAGER-18608 Signed-off-by: Alex Boungnaseng <[email protected]>
1 parent 1c61e2e commit c6e85d2

File tree

1 file changed

+82
-1
lines changed

1 file changed

+82
-1
lines changed

packages/manager-wiki/stories/guidelines/adding-new-component.mdx

Lines changed: 82 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,13 @@ src/
4343
your-component/
4444
__tests__
4545
your-component.test.tsx
46+
your-component.snapshot.test.tsx
47+
__snapshots__
4648
your-component.component.tsx
49+
your-component.constants.ts
50+
your-component.props.ts
4751
your-component.types.ts
52+
your-component.scss
4853
index.ts
4954
```
5055

@@ -61,6 +66,11 @@ src/
6166
index.ts
6267
```
6368

69+
### name convention:
70+
- Package should be `kebab-case`
71+
- React component, hooks `UpperCamelCase`
72+
- Test name, file name `UpperCamelCase`
73+
6474
Adding story to manager-wiki
6575

6676
```
@@ -153,7 +163,74 @@ describe('YourComponent', () => {
153163
});
154164
```
155165

156-
### 6. 📤 Export Component
166+
Create snaphot
167+
168+
> Info : Components in MRC must have a minimum of 90% coverage. More to follow with respect to Accessibility, visual regression testings.
169+
170+
### 7. 📸 Create Snapshot Tests
171+
172+
Create snapshot tests in `your-component.snapshot.test.tsx`:
173+
174+
```tsx
175+
import { render } from '@testing-library/react';
176+
import { YourComponent } from './your-component.component';
177+
178+
describe('YourComponent Snapshot Tests', () => {
179+
it('should match snapshot with default props', () => {
180+
const { container } = render(<YourComponent prop1="default" prop2={0} />);
181+
expect(container.firstChild).toMatchSnapshot();
182+
});
183+
184+
it('should match snapshot with all props', () => {
185+
const { container } = render(
186+
<YourComponent
187+
prop1="test value"
188+
prop2={42}
189+
optionalProp={true}
190+
/>
191+
);
192+
expect(container.firstChild).toMatchSnapshot();
193+
});
194+
195+
it('should match snapshot with different prop combinations', () => {
196+
const { container: container1 } = render(
197+
<YourComponent prop1="value1" prop2={10} />
198+
);
199+
expect(container1.firstChild).toMatchSnapshot('with value1 and 10');
200+
201+
const { container: container2 } = render(
202+
<YourComponent prop1="value2" prop2={20} optionalProp={false} />
203+
);
204+
expect(container2.firstChild).toMatchSnapshot('with value2, 20, and optionalProp false');
205+
});
206+
});
207+
```
208+
209+
**Snapshot Testing Best Practices:**
210+
211+
- 📸 **Multiple scenarios**: Test different prop combinations to catch visual regressions
212+
- 🏷️ **Descriptive names**: Use descriptive snapshot names to identify what each snapshot represents
213+
- 🔄 **Regular updates**: Review and update snapshots when making intentional changes
214+
- 🎯 **Focused testing**: Test the component's visual output, not implementation details
215+
- 📁 **Organized structure**: Keep snapshot files in `__tests__/_snapshots_/` directory
216+
217+
**When to update snapshots:**
218+
- After intentional UI changes
219+
- When fixing bugs that affect rendering
220+
- When adding new features that change the component's appearance
221+
222+
**Running snapshot tests:**
223+
```bash
224+
# Run all snapshot tests
225+
npm test -- --testNamePattern="snapshot"
226+
227+
# Update snapshots after intentional changes
228+
npm test -- --testNamePattern="snapshot" --updateSnapshot
229+
```
230+
231+
> ⚠️ **Important**: Always review snapshot diffs before accepting changes. Snapshots should reflect intentional UI updates, not accidental regressions.
232+
233+
### 8. Export Component
157234

158235
Add exports in `index.ts`:
159236

@@ -164,6 +241,10 @@ export type { nameExportType } from './your-component.types';
164241

165242
> ❌ Do not export with `*`, it can cause issues during the library build
166243
244+
### 8. Storybook Update
245+
246+
Add a documentation for the component in Manager WIKI
247+
167248
## 🎨 Best Practices
168249

169250
### Component Design

0 commit comments

Comments
 (0)