Skip to content

Commit 1077bcb

Browse files
Merge pull request #30 from internxt/feat/PB-3429-Update-tests
[PB-3429]:feat/Update test and organize structure
2 parents d6c76a4 + c72bc7a commit 1077bcb

File tree

104 files changed

+1416
-584
lines changed

Some content is hidden

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

104 files changed

+1416
-584
lines changed

package.json

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,14 +38,14 @@
3838
"@storybook/test": "^8.0.4",
3939
"@testing-library/dom": "^10.4.0",
4040
"@testing-library/jest-dom": "^6.4.2",
41-
"@testing-library/react": "^14.2.2",
41+
"@testing-library/react": "^16.0.1",
4242
"@testing-library/user-event": "^14.5.2",
4343
"@types/react": "^18.2.67",
4444
"@types/react-dom": "^18.3.0",
4545
"@typescript-eslint/eslint-plugin": "^7.3.1",
4646
"@typescript-eslint/parser": "^7.3.1",
4747
"@vitest/coverage-istanbul": "^2.1.5",
48-
"@vitest/ui": "^2.1.5",
48+
"@vitest/ui": "^2.1.8",
4949
"eslint": "^8.57.0",
5050
"eslint-config-prettier": "^9.1.0",
5151
"eslint-plugin-prettier": "^5.1.3",
@@ -67,7 +67,8 @@
6767
"vite-plugin-css-injected-by-js": "^3.5.2",
6868
"vite-plugin-dts": "^3.7.3",
6969
"vite-plugin-svgr": "^4.2.0",
70-
"vitest": "^2.1.5"
70+
"vite-tsconfig-paths": "^5.1.3",
71+
"vitest": "^2.1.8"
7172
},
7273
"scripts": {
7374
"build:tsc": "tsc",

src/components/avatar/Avatar.tsx

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,8 @@ const SIZES: Record<SIZE_KEYS, number> = {
3131
* @param {Object} [props.style={}] - Additional inline styles to apply to the avatar component.
3232
* @returns {JSX.Element} The rendered avatar component.
3333
*/
34-
export const Avatar = ({
34+
35+
const Avatar = ({
3536
src,
3637
diameter = 80,
3738
size,
@@ -54,3 +55,5 @@ export const Avatar = ({
5455
<DefaultAvatar diameter={diameterValue} className={className} fullName={fullName} />
5556
);
5657
};
58+
59+
export default Avatar;

src/components/avatar/__test__/Avatar.test.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1+
import React from 'react';
12
import { describe, expect, it } from 'vitest';
23
import { render } from '@testing-library/react';
3-
import { Avatar } from '../Avatar';
4+
import { Avatar } from '../';
45

56
const FULL_NAME = 'My Internxt';
67
const IMAGE_SRC = 'https://internxt.com/favicon.ico';

src/components/avatar/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export { default as Avatar } from './Avatar';

src/components/baseDialog/__test__/BaseDialog.test.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import React from 'react';
22
import { render, fireEvent } from '@testing-library/react';
33
import { afterEach, describe, expect, it, vi } from 'vitest';
4-
import BaseDialog from '../BaseDialog';
4+
import { BaseDialog } from '../';
55

66
describe('BaseDialog', () => {
77
const onCloseMock = vi.fn();

src/components/baseDialog/index.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
export { default as BaseDialog } from './BaseDialog';
2+
export type { BaseDialogProps } from './BaseDialog';

src/components/breadcrumbs/__test__/Breadcrumbs.test.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import React, { act } from 'react';
22
import { describe, it, expect, vi, afterEach } from 'vitest';
33
import { render } from '@testing-library/react';
44
import userEvent from '@testing-library/user-event';
5-
import Breadcrumbs, { BreadcrumbsProps } from '../Breadcrumbs';
5+
import { Breadcrumbs, BreadcrumbsProps } from '../';
66
import { Dispatch, AnyAction } from 'redux';
77
import { DndProvider } from 'react-dnd';
88
import { HTML5Backend } from 'react-dnd-html5-backend';
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
export { default as Breadcrumbs } from './Breadcrumbs';
2+
export type { BreadcrumbsProps } from './Breadcrumbs';

src/components/button/Button.tsx

Lines changed: 60 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { ReactNode } from 'react';
22
import Loader from '../loader/Loader';
33

4-
interface ButtonProps {
4+
export interface ButtonProps {
55
id?: string;
66
variant?: 'primary' | 'secondary' | 'ghost' | 'destructive';
77
type?: 'button' | 'submit';
@@ -18,7 +18,63 @@ interface ButtonProps {
1818
buttonChildrenDataCy?: string;
1919
}
2020

21-
export const Button = ({
21+
/**
22+
* Button component
23+
*
24+
* @property {string} [id]
25+
* - Optional ID for the button element, useful for accessibility and styling.
26+
*
27+
* @property {'primary' | 'secondary' | 'ghost' | 'destructive'} [variant]
28+
* - Defines the button's style variant. Options are:
29+
* - 'primary': Standard button style with primary color.
30+
* - 'secondary': Button with border and subtle background color.
31+
* - 'ghost': Button with transparent background, suitable for icons or light use.
32+
* - 'destructive': Button for destructive actions.
33+
*
34+
* @property {'button' | 'submit'} [type]
35+
* - Specifies the type of the button. Defaults to 'button'.
36+
* - 'button': Standard button behavior.
37+
* - 'submit': Button submits a form when used inside a form element.
38+
*
39+
* @property {ReactNode} [children]
40+
* - The content inside the button, such as text or icons.
41+
* - Can be a single element or an array of elements.
42+
*
43+
* @property {string} [className]
44+
* - Custom CSS classes for additional styling of the button.
45+
*
46+
* @property {boolean} [disabled]
47+
* - Disables the button, preventing user interaction and applying a disabled style.
48+
* - Defaults to false.
49+
*
50+
* @property {(e?: unknown) => void} [onClick]
51+
* - Function called when the button is clicked. Accepts an optional event object.
52+
*
53+
* @property {(e?: unknown) => void} [onKeyDown]
54+
* - Function called when a key is pressed while the button is focused. Accepts an optional event object.
55+
*
56+
* @property {'medium' | 'default'} [size]
57+
* - Specifies the button size. Options are:
58+
* - 'default': Standard size.
59+
* - 'medium': Slightly smaller size for compact use.
60+
*
61+
* @property {boolean} [loading]
62+
* - If true, shows a loading spinner inside the button.
63+
*
64+
* @property {string} [dataTest]
65+
* - Custom data attribute used for test automation or tracking purposes.
66+
*
67+
* @property {boolean} [autofocus]
68+
* - If true, the button will be focused automatically when the page loads.
69+
*
70+
* @property {string} [buttonDataCy]
71+
* - Custom data attribute for the button element.
72+
*
73+
* @property {string} [buttonChildrenDataCy]
74+
* - Custom data attribute for the children of the button.
75+
*/
76+
77+
const Button = ({
2278
variant = 'primary',
2379
type = 'button',
2480
id,
@@ -80,3 +136,5 @@ export const Button = ({
80136
</button>
81137
);
82138
};
139+
140+
export default Button;

src/components/button/__test__/Button.test.tsx

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import React from 'react';
22
import { describe, expect, it, vi } from 'vitest';
3-
import { render, screen } from '@testing-library/react';
4-
import { Button } from '../Button';
3+
import { fireEvent, render, screen } from '@testing-library/react';
4+
import { Button } from '../';
55

66
describe('Button component', () => {
77
it('Button onClick should be called correctly', () => {
@@ -12,6 +12,14 @@ describe('Button component', () => {
1212
expect(buttonClick).toHaveBeenCalledOnce();
1313
});
1414

15+
it('Button onKeyDown should be called correctly', () => {
16+
const keydown = vi.fn();
17+
render(<Button variant="primary" onKeyDown={keydown} />);
18+
const button = screen.getByRole('button');
19+
fireEvent.keyDown(button, { key: 'Enter', code: 'Enter' });
20+
expect(keydown).toHaveBeenCalledOnce();
21+
});
22+
1523
it('Primary button should render correctly', () => {
1624
const button = render(<Button variant="primary">Primary</Button>);
1725
expect(button).toMatchSnapshot();

0 commit comments

Comments
 (0)