@js-smart/react-kit 5.10.0 → 5.12.0-beta.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.editorconfig +13 -0
- package/.eslintignore +1 -0
- package/.eslintrc.json +41 -0
- package/.github/copilot-instructions.md +11 -0
- package/.github/workflows/build.yml +45 -0
- package/.github/workflows/release.yml +65 -0
- package/.prettierignore +5 -0
- package/.prettierrc +9 -0
- package/.vscode/extensions.json +7 -0
- package/CHANGELOG.md +24 -0
- package/CODE_OF_CONDUCT.md +128 -0
- package/FUNDING.yml +1 -0
- package/LICENSE +21 -0
- package/README.md +1 -0
- package/apps/react-kit-demo/.eslintrc.json +22 -0
- package/apps/react-kit-demo/index.html +16 -0
- package/apps/react-kit-demo/project.json +9 -0
- package/apps/react-kit-demo/public/favicon.ico +0 -0
- package/apps/react-kit-demo/src/app/Home.tsx +17 -0
- package/apps/react-kit-demo/src/app/all-books/AllBooks.tsx +68 -0
- package/apps/react-kit-demo/src/app/app.module.scss +1 -0
- package/apps/react-kit-demo/src/app/app.tsx +29 -0
- package/apps/react-kit-demo/src/app/buttons/ButtonsDemo.tsx +58 -0
- package/apps/react-kit-demo/src/app/dialog/DialogDemo.tsx +23 -0
- package/apps/react-kit-demo/src/app/links/LinksDemo.tsx +20 -0
- package/apps/react-kit-demo/src/app/progress-bar/CenterCircularProgressDemo.tsx +10 -0
- package/apps/react-kit-demo/src/app/react-if/ReactIfDemo.tsx +44 -0
- package/apps/react-kit-demo/src/app/snack-bar/SnackBarDemo.tsx +35 -0
- package/apps/react-kit-demo/src/assets/.gitkeep +0 -0
- package/apps/react-kit-demo/src/constants/ApiConstants.ts +7 -0
- package/apps/react-kit-demo/src/constants/DialogMode.ts +2 -0
- package/apps/react-kit-demo/src/constants/HttpConstants.ts +18 -0
- package/apps/react-kit-demo/src/constants/StateConstants.ts +2 -0
- package/apps/react-kit-demo/src/main.tsx +17 -0
- package/apps/react-kit-demo/src/routes/Routes.tsx +55 -0
- package/apps/react-kit-demo/src/services/BookService.ts +21 -0
- package/apps/react-kit-demo/src/styles.scss +36 -0
- package/apps/react-kit-demo/src/theme.ts +46 -0
- package/apps/react-kit-demo/src/types/Book.ts +8 -0
- package/{lib/utils/CssUtils.d.ts → apps/react-kit-demo/src/utils/CssUtils.ts} +3 -1
- package/apps/react-kit-demo/tsconfig.app.json +18 -0
- package/apps/react-kit-demo/tsconfig.json +21 -0
- package/apps/react-kit-demo/tsconfig.spec.json +28 -0
- package/apps/react-kit-demo/vite.config.ts +50 -0
- package/nx.json +52 -0
- package/package.json +99 -44
- package/react-kit/.babelrc +12 -0
- package/react-kit/.eslintrc.json +18 -0
- package/react-kit/README.md +7 -0
- package/react-kit/package-lock.json +1330 -0
- package/react-kit/package.json +45 -0
- package/react-kit/project.json +10 -0
- package/{index.d.ts → react-kit/src/index.ts} +9 -0
- package/react-kit/src/lib/components/CenteredCircularProgress.tsx +15 -0
- package/react-kit/src/lib/components/ConfirmationDialog.tsx +28 -0
- package/react-kit/src/lib/components/DismissibleAlert.tsx +60 -0
- package/react-kit/src/lib/components/NextLink.tsx +26 -0
- package/react-kit/src/lib/components/OpenInNewIconLink.tsx +42 -0
- package/react-kit/src/lib/components/ReactIf.tsx +53 -0
- package/react-kit/src/lib/components/buttons/CancelButton.tsx +45 -0
- package/react-kit/src/lib/components/buttons/DeleteButton.tsx +35 -0
- package/react-kit/src/lib/components/buttons/EditIconButton.tsx +23 -0
- package/react-kit/src/lib/components/buttons/ExcelButton.tsx +43 -0
- package/react-kit/src/lib/components/buttons/GoBackButton.tsx +22 -0
- package/react-kit/src/lib/components/buttons/HistoryButton.tsx +45 -0
- package/react-kit/src/lib/components/buttons/LoadingSuccessButton.tsx +53 -0
- package/react-kit/src/lib/components/buttons/ManageButton.tsx +31 -0
- package/react-kit/src/lib/components/buttons/SuccessButton.tsx +44 -0
- package/react-kit/src/lib/components/snack-bar/AppSnackBar.tsx +46 -0
- package/react-kit/src/lib/components/snack-bar/QuerySnackBar.tsx +62 -0
- package/react-kit/src/lib/components/table/TablePaginationActions.tsx +58 -0
- package/react-kit/src/lib/components/tabs/TabPanel.tsx +26 -0
- package/react-kit/src/lib/constants/AppConstants.ts +17 -0
- package/react-kit/src/lib/types/ProgressState.ts +7 -0
- package/react-kit/src/lib/utils/BooleanUtils.ts +13 -0
- package/react-kit/src/lib/utils/CssUtils.ts +13 -0
- package/react-kit/src/lib/utils/DateUtils.ts +43 -0
- package/react-kit/src/lib/utils/NumberUtils.ts +12 -0
- package/react-kit/src/lib/utils/ProgressStateUtils.ts +68 -0
- package/react-kit/src/lib/utils/StringUtils.ts +14 -0
- package/react-kit/src/lib/utils/UrlUtils.ts +19 -0
- package/react-kit/src/lib/utils/fetchClient.ts +64 -0
- package/react-kit/src/tests/buttons/CancelButton.test.tsx +69 -0
- package/react-kit/src/tests/buttons/DeleteButton.test.tsx +63 -0
- package/react-kit/src/tests/buttons/EditIconButton.test.tsx +34 -0
- package/react-kit/src/tests/buttons/HistoryButton.test.tsx +46 -0
- package/react-kit/src/tests/buttons/LoadingSuccessButton.test.tsx +53 -0
- package/react-kit/src/tests/buttons/ManageButton.test.tsx +49 -0
- package/react-kit/src/tests/buttons/SuccessButton.test.tsx +46 -0
- package/react-kit/src/tests/snack-bar/AppSnackBar.test.tsx +54 -0
- package/react-kit/src/tests/utils/BooleanUtils.test.ts +35 -0
- package/react-kit/src/tests/utils/CssUtils.test.ts +17 -0
- package/react-kit/src/tests/utils/DateUtils.test.ts +46 -0
- package/react-kit/src/tests/utils/NumberUtils.test.ts +19 -0
- package/react-kit/src/tests/utils/ProgressStateUtils.test.ts +131 -0
- package/react-kit/src/tests/utils/StringUtils.test.ts +33 -0
- package/react-kit/src/tests/utils/UrlUtils.test.ts +19 -0
- package/react-kit/tsconfig.json +22 -0
- package/react-kit/tsconfig.lib.json +24 -0
- package/react-kit/tsconfig.spec.json +27 -0
- package/react-kit/vite.config.ts +72 -0
- package/release.sh +28 -0
- package/tsconfig.base.json +22 -0
- package/vitest.workspace.js +3 -0
- package/vitest.workspace.ts +1 -0
- package/index.cjs +0 -74
- package/index.js +0 -4120
- package/index.mjs +0 -4108
- package/lib/components/CenteredCircularProgress.d.ts +0 -7
- package/lib/components/ConfirmationDialog.d.ts +0 -11
- package/lib/components/DismissibleAlert.d.ts +0 -17
- package/lib/components/NextLink.d.ts +0 -17
- package/lib/components/OpenInNewIconLink.d.ts +0 -17
- package/lib/components/ReactIf.d.ts +0 -36
- package/lib/components/buttons/CancelButton.d.ts +0 -28
- package/lib/components/buttons/DeleteButton.d.ts +0 -16
- package/lib/components/buttons/EditIconButton.d.ts +0 -8
- package/lib/components/buttons/ExcelButton.d.ts +0 -26
- package/lib/components/buttons/GoBackButton.d.ts +0 -10
- package/lib/components/buttons/HistoryButton.d.ts +0 -28
- package/lib/components/buttons/LoadingSuccessButton.d.ts +0 -28
- package/lib/components/buttons/ManageButton.d.ts +0 -14
- package/lib/components/buttons/SuccessButton.d.ts +0 -28
- package/lib/components/snack-bar/AppSnackBar.d.ts +0 -6
- package/lib/components/snack-bar/QuerySnackBar.d.ts +0 -18
- package/lib/components/table/TablePaginationActions.d.ts +0 -9
- package/lib/components/tabs/TabPanel.d.ts +0 -12
- package/lib/constants/AppConstants.d.ts +0 -15
- package/lib/types/ProgressState.d.ts +0 -7
- package/lib/utils/BooleanUtils.d.ts +0 -7
- package/lib/utils/DateUtils.d.ts +0 -22
- package/lib/utils/NumberUtils.d.ts +0 -7
- package/lib/utils/ProgressStateUtils.d.ts +0 -38
- package/lib/utils/StringUtils.d.ts +0 -7
- package/lib/utils/UrlUtils.d.ts +0 -11
- package/lib/utils/fetchClient.d.ts +0 -12
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { fireEvent, render, screen } from '@testing-library/react';
|
|
3
|
+
import '@testing-library/jest-dom';
|
|
4
|
+
import { HistoryButton } from '../../lib/components/buttons/HistoryButton';
|
|
5
|
+
import jest from 'jest-mock';
|
|
6
|
+
|
|
7
|
+
describe('HistoryButton', () => {
|
|
8
|
+
const mockOnClick = jest.fn();
|
|
9
|
+
|
|
10
|
+
beforeEach(() => {
|
|
11
|
+
mockOnClick.mockClear();
|
|
12
|
+
});
|
|
13
|
+
|
|
14
|
+
it('renders with the correct default properties', () => {
|
|
15
|
+
render(<HistoryButton onClick={mockOnClick} name={'History'} />);
|
|
16
|
+
const button = screen.getByRole('button', { name: 'History' });
|
|
17
|
+
expect(button).toBeInTheDocument();
|
|
18
|
+
expect(button).toHaveClass('MuiButton-containedPrimary');
|
|
19
|
+
});
|
|
20
|
+
|
|
21
|
+
it('calls onClick when clicked', () => {
|
|
22
|
+
render(<HistoryButton onClick={mockOnClick} name={'History'} />);
|
|
23
|
+
fireEvent.click(screen.getByRole('button', { name: 'History' }));
|
|
24
|
+
expect(mockOnClick).toHaveBeenCalledTimes(1);
|
|
25
|
+
});
|
|
26
|
+
|
|
27
|
+
it('renders with custom properties', () => {
|
|
28
|
+
render(
|
|
29
|
+
<HistoryButton
|
|
30
|
+
onClick={mockOnClick}
|
|
31
|
+
name="custom-name"
|
|
32
|
+
dataCy="custom-data-cy"
|
|
33
|
+
variant="outlined"
|
|
34
|
+
color="secondary"
|
|
35
|
+
startIcon={<span data-testid="custom-icon" />}>
|
|
36
|
+
Custom History
|
|
37
|
+
</HistoryButton>
|
|
38
|
+
);
|
|
39
|
+
const button = screen.getByRole('button', { name: 'Custom History' });
|
|
40
|
+
expect(button).toBeInTheDocument();
|
|
41
|
+
expect(button).toHaveClass('MuiButton-outlinedSecondary');
|
|
42
|
+
expect(button).toHaveAttribute('name', 'custom-name');
|
|
43
|
+
expect(button).toHaveAttribute('data-cy', 'custom-data-cy');
|
|
44
|
+
expect(screen.getByTestId('custom-icon')).toBeInTheDocument();
|
|
45
|
+
});
|
|
46
|
+
});
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { fireEvent, render, screen } from '@testing-library/react';
|
|
3
|
+
import '@testing-library/jest-dom';
|
|
4
|
+
import { LoadingSuccessButton } from '../../lib/components/buttons/LoadingSuccessButton';
|
|
5
|
+
import jest from 'jest-mock';
|
|
6
|
+
|
|
7
|
+
describe('LoadingSuccessButton', () => {
|
|
8
|
+
const mockOnClick = jest.fn();
|
|
9
|
+
|
|
10
|
+
beforeEach(() => {
|
|
11
|
+
mockOnClick.mockClear();
|
|
12
|
+
});
|
|
13
|
+
|
|
14
|
+
it('renders with the correct default properties', () => {
|
|
15
|
+
render(
|
|
16
|
+
<LoadingSuccessButton onClick={mockOnClick} loading={false}>
|
|
17
|
+
Save
|
|
18
|
+
</LoadingSuccessButton>
|
|
19
|
+
);
|
|
20
|
+
const button = screen.getByRole('button', { name: 'Save' });
|
|
21
|
+
expect(button).toBeInTheDocument();
|
|
22
|
+
});
|
|
23
|
+
|
|
24
|
+
it('calls onClick when clicked', () => {
|
|
25
|
+
render(
|
|
26
|
+
<LoadingSuccessButton onClick={mockOnClick} loading={false}>
|
|
27
|
+
Save
|
|
28
|
+
</LoadingSuccessButton>
|
|
29
|
+
);
|
|
30
|
+
fireEvent.click(screen.getByRole('button', { name: 'Save' }));
|
|
31
|
+
expect(mockOnClick).toHaveBeenCalledTimes(1);
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
it('renders with custom properties', () => {
|
|
35
|
+
render(
|
|
36
|
+
<LoadingSuccessButton
|
|
37
|
+
onClick={mockOnClick}
|
|
38
|
+
name="custom-name"
|
|
39
|
+
dataCy="custom-data-cy"
|
|
40
|
+
variant="outlined"
|
|
41
|
+
color="secondary"
|
|
42
|
+
loading={false}
|
|
43
|
+
startIcon={<span data-testid="custom-icon" />}>
|
|
44
|
+
Custom Success
|
|
45
|
+
</LoadingSuccessButton>
|
|
46
|
+
);
|
|
47
|
+
const button = screen.getByRole('button', { name: 'Custom Success' });
|
|
48
|
+
expect(button).toBeInTheDocument();
|
|
49
|
+
expect(button).toHaveAttribute('name', 'custom-name');
|
|
50
|
+
expect(button).toHaveAttribute('data-cy', 'custom-data-cy');
|
|
51
|
+
expect(screen.getByTestId('custom-icon')).toBeInTheDocument();
|
|
52
|
+
});
|
|
53
|
+
});
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { fireEvent, render, screen } from '@testing-library/react';
|
|
3
|
+
import '@testing-library/jest-dom';
|
|
4
|
+
import { ManageButton } from '../../lib/components/buttons/ManageButton';
|
|
5
|
+
import jest from 'jest-mock';
|
|
6
|
+
|
|
7
|
+
describe('ManageButton', () => {
|
|
8
|
+
const mockOnClick = jest.fn();
|
|
9
|
+
|
|
10
|
+
beforeEach(() => {
|
|
11
|
+
mockOnClick.mockClear();
|
|
12
|
+
});
|
|
13
|
+
|
|
14
|
+
it('renders with the correct default properties', () => {
|
|
15
|
+
render(<ManageButton onClick={mockOnClick} />);
|
|
16
|
+
const button = screen.getByRole('button', { name: 'Manage' });
|
|
17
|
+
expect(button).toBeInTheDocument();
|
|
18
|
+
expect(button).toHaveClass('MuiButton-containedPrimary');
|
|
19
|
+
expect(button).toHaveClass('MuiButton-sizeLarge');
|
|
20
|
+
});
|
|
21
|
+
|
|
22
|
+
it('calls onClick when clicked', () => {
|
|
23
|
+
render(<ManageButton onClick={mockOnClick} />);
|
|
24
|
+
fireEvent.click(screen.getByRole('button', { name: 'Manage' }));
|
|
25
|
+
expect(mockOnClick).toHaveBeenCalledTimes(1);
|
|
26
|
+
});
|
|
27
|
+
|
|
28
|
+
it('renders with custom properties', () => {
|
|
29
|
+
render(
|
|
30
|
+
<ManageButton
|
|
31
|
+
onClick={mockOnClick}
|
|
32
|
+
name="custom-name"
|
|
33
|
+
dataCy="custom-data-cy"
|
|
34
|
+
variant="outlined"
|
|
35
|
+
color="secondary"
|
|
36
|
+
size="small"
|
|
37
|
+
startIcon={<span data-testid="custom-icon" />}>
|
|
38
|
+
Custom Manage
|
|
39
|
+
</ManageButton>
|
|
40
|
+
);
|
|
41
|
+
const button = screen.getByRole('button', { name: 'Custom Manage' });
|
|
42
|
+
expect(button).toBeInTheDocument();
|
|
43
|
+
expect(button).toHaveClass('MuiButton-outlinedSecondary');
|
|
44
|
+
expect(button).toHaveClass('MuiButton-sizeSmall');
|
|
45
|
+
expect(button).toHaveAttribute('name', 'custom-name');
|
|
46
|
+
expect(button).toHaveAttribute('data-cy', 'custom-data-cy');
|
|
47
|
+
expect(screen.getByTestId('custom-icon')).toBeInTheDocument();
|
|
48
|
+
});
|
|
49
|
+
});
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { fireEvent, render, screen } from '@testing-library/react';
|
|
3
|
+
import '@testing-library/jest-dom';
|
|
4
|
+
import { SuccessButton } from '../../lib/components/buttons/SuccessButton';
|
|
5
|
+
import jest from 'jest-mock';
|
|
6
|
+
|
|
7
|
+
describe('SuccessButton', () => {
|
|
8
|
+
const mockOnClick = jest.fn();
|
|
9
|
+
|
|
10
|
+
beforeEach(() => {
|
|
11
|
+
mockOnClick.mockClear();
|
|
12
|
+
});
|
|
13
|
+
|
|
14
|
+
it('renders with the correct default properties', () => {
|
|
15
|
+
render(<SuccessButton onClick={mockOnClick}>Success</SuccessButton>);
|
|
16
|
+
const button = screen.getByRole('button', { name: 'Success' });
|
|
17
|
+
expect(button).toBeInTheDocument();
|
|
18
|
+
expect(button).toHaveClass('MuiButton-containedSuccess');
|
|
19
|
+
});
|
|
20
|
+
|
|
21
|
+
it('calls onClick when clicked', () => {
|
|
22
|
+
render(<SuccessButton onClick={mockOnClick}>Success</SuccessButton>);
|
|
23
|
+
fireEvent.click(screen.getByRole('button', { name: 'Success' }));
|
|
24
|
+
expect(mockOnClick).toHaveBeenCalledTimes(1);
|
|
25
|
+
});
|
|
26
|
+
|
|
27
|
+
it('renders with custom properties', () => {
|
|
28
|
+
render(
|
|
29
|
+
<SuccessButton
|
|
30
|
+
onClick={mockOnClick}
|
|
31
|
+
name="custom-name"
|
|
32
|
+
dataCy="custom-data-cy"
|
|
33
|
+
variant="outlined"
|
|
34
|
+
color="secondary"
|
|
35
|
+
startIcon={<span data-testid="custom-icon" />}>
|
|
36
|
+
Custom Success
|
|
37
|
+
</SuccessButton>
|
|
38
|
+
);
|
|
39
|
+
const button = screen.getByRole('button', { name: 'Custom Success' });
|
|
40
|
+
expect(button).toBeInTheDocument();
|
|
41
|
+
expect(button).toHaveClass('MuiButton-outlinedSecondary');
|
|
42
|
+
expect(button).toHaveAttribute('name', 'custom-name');
|
|
43
|
+
expect(button).toHaveAttribute('data-cy', 'custom-data-cy');
|
|
44
|
+
expect(screen.getByTestId('custom-icon')).toBeInTheDocument();
|
|
45
|
+
});
|
|
46
|
+
});
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { render, screen } from '@testing-library/react';
|
|
3
|
+
import '@testing-library/jest-dom';
|
|
4
|
+
import { AppSnackBar } from '../../lib/components/snack-bar/AppSnackBar';
|
|
5
|
+
import { ProgressState } from '../../lib/types/ProgressState';
|
|
6
|
+
|
|
7
|
+
describe('AppSnackBar', () => {
|
|
8
|
+
const successState: ProgressState = {
|
|
9
|
+
isSuccess: true,
|
|
10
|
+
isError: false,
|
|
11
|
+
message: 'Success!',
|
|
12
|
+
isLoading: false,
|
|
13
|
+
isComplete: false,
|
|
14
|
+
};
|
|
15
|
+
const errorState: ProgressState = {
|
|
16
|
+
isSuccess: false,
|
|
17
|
+
isError: true,
|
|
18
|
+
message: 'Error!',
|
|
19
|
+
isLoading: false,
|
|
20
|
+
isComplete: false,
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
it('renders success alert when progressState is success', () => {
|
|
24
|
+
render(<AppSnackBar open={true} progressState={successState} />);
|
|
25
|
+
const alert = screen.getByRole('alert');
|
|
26
|
+
expect(alert).toBeInTheDocument();
|
|
27
|
+
expect(alert).toHaveTextContent('Success!');
|
|
28
|
+
expect(alert).toHaveClass('MuiAlert-filledSuccess');
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
it('renders error alert when progressState is error', () => {
|
|
32
|
+
render(<AppSnackBar open={true} progressState={errorState} />);
|
|
33
|
+
const alert = screen.getByRole('alert');
|
|
34
|
+
expect(alert).toBeInTheDocument();
|
|
35
|
+
expect(alert).toHaveTextContent('Error!');
|
|
36
|
+
expect(alert).toHaveClass('MuiAlert-filledError');
|
|
37
|
+
});
|
|
38
|
+
/*
|
|
39
|
+
it('closes the snackbar when the close button is clicked', () => {
|
|
40
|
+
render(<AppSnackBar open={true} progressState={successState} />);
|
|
41
|
+
const closeButton = screen.getByRole('button', { name: /close/i });
|
|
42
|
+
fireEvent.click(closeButton);
|
|
43
|
+
expect(screen.queryByRole('alert')).not.toBeInTheDocument();
|
|
44
|
+
});
|
|
45
|
+
|
|
46
|
+
it('auto hides the snackbar after the specified duration', () => {
|
|
47
|
+
jest.useFakeTimers();
|
|
48
|
+
render(<AppSnackBar open={true} progressState={successState} autoHideDuration={1000} />);
|
|
49
|
+
expect(screen.getByRole('alert')).toBeInTheDocument();
|
|
50
|
+
jest.advanceTimersByTime(1000);
|
|
51
|
+
expect(screen.queryByRole('alert')).not.toBeInTheDocument();
|
|
52
|
+
jest.useRealTimers();
|
|
53
|
+
});*/
|
|
54
|
+
});
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { parseBoolean } from '../../lib/utils/BooleanUtils';
|
|
2
|
+
|
|
3
|
+
describe('parseBoolean', () => {
|
|
4
|
+
it('should return true for boolean true', () => {
|
|
5
|
+
expect(parseBoolean(true)).toBe(true);
|
|
6
|
+
});
|
|
7
|
+
|
|
8
|
+
it('should return false for boolean false', () => {
|
|
9
|
+
expect(parseBoolean(false)).toBe(false);
|
|
10
|
+
});
|
|
11
|
+
|
|
12
|
+
it('should return true for string "true"', () => {
|
|
13
|
+
expect(parseBoolean('true')).toBe(true);
|
|
14
|
+
});
|
|
15
|
+
|
|
16
|
+
it('should return false for string "false"', () => {
|
|
17
|
+
expect(parseBoolean('false')).toBe(false);
|
|
18
|
+
});
|
|
19
|
+
|
|
20
|
+
it('should return false for null', () => {
|
|
21
|
+
expect(parseBoolean(null)).toBe(false);
|
|
22
|
+
});
|
|
23
|
+
|
|
24
|
+
it('should return false for undefined', () => {
|
|
25
|
+
expect(parseBoolean(undefined)).toBe(false);
|
|
26
|
+
});
|
|
27
|
+
|
|
28
|
+
it('should return false for an empty string', () => {
|
|
29
|
+
expect(parseBoolean('')).toBe(false);
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
it('should return false for any other string', () => {
|
|
33
|
+
expect(parseBoolean('random')).toBe(false);
|
|
34
|
+
});
|
|
35
|
+
});
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { getCssVariable } from '../../lib/utils/CssUtils';
|
|
2
|
+
|
|
3
|
+
describe('getCssVariable', () => {
|
|
4
|
+
beforeAll(() => {
|
|
5
|
+
document.documentElement.style.setProperty('--test-variable', 'test-value');
|
|
6
|
+
});
|
|
7
|
+
|
|
8
|
+
it('should return the value of the CSS variable', () => {
|
|
9
|
+
const value = getCssVariable('--test-variable');
|
|
10
|
+
expect(value).toBe('test-value');
|
|
11
|
+
});
|
|
12
|
+
|
|
13
|
+
it('should return an empty string for a non-existent variable', () => {
|
|
14
|
+
const value = getCssVariable('--non-existent-variable');
|
|
15
|
+
expect(value).toBe('');
|
|
16
|
+
});
|
|
17
|
+
});
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { convertToIsoDate, formatDate, setCookieExpirationDate } from '../../lib/utils/DateUtils';
|
|
2
|
+
import { format, parseISO } from 'date-fns';
|
|
3
|
+
import { SystemConfig } from '../../lib/constants/AppConstants';
|
|
4
|
+
import '@testing-library/jest-dom';
|
|
5
|
+
|
|
6
|
+
describe('DateUtils', () => {
|
|
7
|
+
describe('setCookieExpirationDate', () => {
|
|
8
|
+
it('should set cookie expiration date to 24 hours from now', () => {
|
|
9
|
+
const now = new Date();
|
|
10
|
+
const expectedDate = new Date(now.getTime() + SystemConfig.SYSTEM_COOKIE_TIMEOUT_MILLI_SECONDS);
|
|
11
|
+
|
|
12
|
+
const result = setCookieExpirationDate();
|
|
13
|
+
|
|
14
|
+
expect(result).toEqual(expectedDate);
|
|
15
|
+
});
|
|
16
|
+
});
|
|
17
|
+
|
|
18
|
+
describe('convertToIsoDate', () => {
|
|
19
|
+
it('should convert current date time to ISO date format', () => {
|
|
20
|
+
const currentDateTime = '2023-10-01T12:00:00Z';
|
|
21
|
+
const formattedDate = format(new Date(currentDateTime), SystemConfig.ISO_DATE_FORMAT);
|
|
22
|
+
|
|
23
|
+
const result = convertToIsoDate(currentDateTime);
|
|
24
|
+
|
|
25
|
+
expect(result).toBe(formattedDate);
|
|
26
|
+
});
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
describe('formatDate', () => {
|
|
30
|
+
it('should return an empty string if date is undefined', () => {
|
|
31
|
+
const result = formatDate(undefined, 'yyyy-MM-dd');
|
|
32
|
+
expect(result).toBe('');
|
|
33
|
+
});
|
|
34
|
+
|
|
35
|
+
it('should format the date to the new format', () => {
|
|
36
|
+
const date = '2023-10-01T12:00:00Z';
|
|
37
|
+
const newFormat = 'yyyy-MM-dd';
|
|
38
|
+
const parsedDate = parseISO(date);
|
|
39
|
+
const formattedDate = format(parsedDate, newFormat);
|
|
40
|
+
|
|
41
|
+
const result = formatDate(date, newFormat);
|
|
42
|
+
|
|
43
|
+
expect(result).toBe(formattedDate);
|
|
44
|
+
});
|
|
45
|
+
});
|
|
46
|
+
});
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { parseNumber } from '../../lib/utils/NumberUtils';
|
|
2
|
+
|
|
3
|
+
describe('parseNumber', () => {
|
|
4
|
+
it('should return a number when a valid string is provided', () => {
|
|
5
|
+
expect(parseNumber('123')).toBe(123);
|
|
6
|
+
});
|
|
7
|
+
|
|
8
|
+
it('should return NaN when an invalid string is provided', () => {
|
|
9
|
+
expect(parseNumber('abc')).toBeNaN();
|
|
10
|
+
});
|
|
11
|
+
|
|
12
|
+
it('should return undefined when null is provided', () => {
|
|
13
|
+
expect(parseNumber(null)).toBeUndefined();
|
|
14
|
+
});
|
|
15
|
+
|
|
16
|
+
it('should return undefined when undefined is provided', () => {
|
|
17
|
+
expect(parseNumber(undefined)).toBeUndefined();
|
|
18
|
+
});
|
|
19
|
+
});
|
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
import { initializeState, markError, markLoading, markSuccess } from '../../lib/utils/ProgressStateUtils';
|
|
2
|
+
import { ProgressState } from '../../lib/types/ProgressState';
|
|
3
|
+
|
|
4
|
+
describe('ProgressStateUtils', () => {
|
|
5
|
+
describe('initializeState', () => {
|
|
6
|
+
it('should initialize the state correctly', () => {
|
|
7
|
+
const expectedState: ProgressState = {
|
|
8
|
+
isLoading: false,
|
|
9
|
+
isSuccess: false,
|
|
10
|
+
isError: false,
|
|
11
|
+
isComplete: false,
|
|
12
|
+
message: '',
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
const result = initializeState();
|
|
16
|
+
|
|
17
|
+
expect(result).toEqual(expectedState);
|
|
18
|
+
});
|
|
19
|
+
});
|
|
20
|
+
|
|
21
|
+
describe('markLoading', () => {
|
|
22
|
+
it('should update the state to loading', () => {
|
|
23
|
+
const initialState: ProgressState = {
|
|
24
|
+
isLoading: false,
|
|
25
|
+
isSuccess: false,
|
|
26
|
+
isError: false,
|
|
27
|
+
isComplete: false,
|
|
28
|
+
message: '',
|
|
29
|
+
};
|
|
30
|
+
|
|
31
|
+
const expectedState: ProgressState = {
|
|
32
|
+
...initialState,
|
|
33
|
+
isLoading: true,
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
const result = markLoading(initialState);
|
|
37
|
+
|
|
38
|
+
expect(result).toEqual(expectedState);
|
|
39
|
+
});
|
|
40
|
+
});
|
|
41
|
+
|
|
42
|
+
describe('markSuccess', () => {
|
|
43
|
+
it('should update the state to success with a message', () => {
|
|
44
|
+
const initialState: ProgressState = {
|
|
45
|
+
isLoading: false,
|
|
46
|
+
isSuccess: false,
|
|
47
|
+
isError: false,
|
|
48
|
+
isComplete: false,
|
|
49
|
+
message: '',
|
|
50
|
+
};
|
|
51
|
+
|
|
52
|
+
const message = 'Operation successful';
|
|
53
|
+
const expectedState: ProgressState = {
|
|
54
|
+
...initialState,
|
|
55
|
+
isSuccess: true,
|
|
56
|
+
isComplete: true,
|
|
57
|
+
message,
|
|
58
|
+
};
|
|
59
|
+
|
|
60
|
+
const result = markSuccess(initialState, message);
|
|
61
|
+
|
|
62
|
+
expect(result).toEqual(expectedState);
|
|
63
|
+
});
|
|
64
|
+
|
|
65
|
+
it('should update the state to success without a message', () => {
|
|
66
|
+
const initialState: ProgressState = {
|
|
67
|
+
isLoading: false,
|
|
68
|
+
isSuccess: false,
|
|
69
|
+
isError: false,
|
|
70
|
+
isComplete: false,
|
|
71
|
+
message: '',
|
|
72
|
+
};
|
|
73
|
+
|
|
74
|
+
const expectedState: ProgressState = {
|
|
75
|
+
...initialState,
|
|
76
|
+
isSuccess: true,
|
|
77
|
+
isComplete: true,
|
|
78
|
+
message: '',
|
|
79
|
+
};
|
|
80
|
+
|
|
81
|
+
const result = markSuccess(initialState);
|
|
82
|
+
|
|
83
|
+
expect(result).toEqual(expectedState);
|
|
84
|
+
});
|
|
85
|
+
});
|
|
86
|
+
|
|
87
|
+
describe('markError', () => {
|
|
88
|
+
it('should update the state to error with a message', () => {
|
|
89
|
+
const initialState: ProgressState = {
|
|
90
|
+
isLoading: false,
|
|
91
|
+
isSuccess: false,
|
|
92
|
+
isError: false,
|
|
93
|
+
isComplete: false,
|
|
94
|
+
message: '',
|
|
95
|
+
};
|
|
96
|
+
|
|
97
|
+
const message = 'Operation failed';
|
|
98
|
+
const expectedState: ProgressState = {
|
|
99
|
+
...initialState,
|
|
100
|
+
isError: true,
|
|
101
|
+
isComplete: true,
|
|
102
|
+
message,
|
|
103
|
+
};
|
|
104
|
+
|
|
105
|
+
const result = markError(initialState, message);
|
|
106
|
+
|
|
107
|
+
expect(result).toEqual(expectedState);
|
|
108
|
+
});
|
|
109
|
+
|
|
110
|
+
it('should update the state to error without a message', () => {
|
|
111
|
+
const initialState: ProgressState = {
|
|
112
|
+
isLoading: false,
|
|
113
|
+
isSuccess: false,
|
|
114
|
+
isError: false,
|
|
115
|
+
isComplete: false,
|
|
116
|
+
message: '',
|
|
117
|
+
};
|
|
118
|
+
|
|
119
|
+
const expectedState: ProgressState = {
|
|
120
|
+
...initialState,
|
|
121
|
+
isError: true,
|
|
122
|
+
isComplete: true,
|
|
123
|
+
message: '',
|
|
124
|
+
};
|
|
125
|
+
|
|
126
|
+
const result = markError(initialState);
|
|
127
|
+
|
|
128
|
+
expect(result).toEqual(expectedState);
|
|
129
|
+
});
|
|
130
|
+
});
|
|
131
|
+
});
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { isBlankOrEmpty } from '../../lib/utils/StringUtils';
|
|
2
|
+
|
|
3
|
+
describe('isBlankOrEmpty', () => {
|
|
4
|
+
it('should return true for null', () => {
|
|
5
|
+
expect(isBlankOrEmpty(null)).toBe(true);
|
|
6
|
+
});
|
|
7
|
+
|
|
8
|
+
it('should return true for undefined', () => {
|
|
9
|
+
expect(isBlankOrEmpty(undefined)).toBe(true);
|
|
10
|
+
});
|
|
11
|
+
|
|
12
|
+
it('should return true for an empty string', () => {
|
|
13
|
+
expect(isBlankOrEmpty('')).toBe(true);
|
|
14
|
+
});
|
|
15
|
+
|
|
16
|
+
it('should return true for a string with only spaces', () => {
|
|
17
|
+
expect(isBlankOrEmpty(' ')).toBe(true);
|
|
18
|
+
});
|
|
19
|
+
|
|
20
|
+
it('should return false for a non-empty string', () => {
|
|
21
|
+
expect(isBlankOrEmpty('hello')).toBe(false);
|
|
22
|
+
});
|
|
23
|
+
|
|
24
|
+
it('should return false for a string with non-space characters', () => {
|
|
25
|
+
expect(isBlankOrEmpty(' hello ')).toBe(false);
|
|
26
|
+
});
|
|
27
|
+
|
|
28
|
+
it('should return false for non-string values', () => {
|
|
29
|
+
expect(isBlankOrEmpty(123)).toBe(false);
|
|
30
|
+
expect(isBlankOrEmpty({})).toBe(false);
|
|
31
|
+
expect(isBlankOrEmpty([])).toBe(false);
|
|
32
|
+
});
|
|
33
|
+
});
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { isEncoded } from '../../lib/utils/UrlUtils';
|
|
2
|
+
|
|
3
|
+
describe('isEncoded', () => {
|
|
4
|
+
it('should return true for an encoded URL', () => {
|
|
5
|
+
expect(isEncoded('https%3A%2F%2Fexample.com')).toBe(true);
|
|
6
|
+
});
|
|
7
|
+
|
|
8
|
+
it('should return false for a non-encoded URL', () => {
|
|
9
|
+
expect(isEncoded('https://example.com')).toBe(false);
|
|
10
|
+
});
|
|
11
|
+
|
|
12
|
+
it('should return false for an improperly encoded URL', () => {
|
|
13
|
+
expect(isEncoded('%E0%A4%A')).toBe(false);
|
|
14
|
+
});
|
|
15
|
+
|
|
16
|
+
it('should return false for an empty string', () => {
|
|
17
|
+
expect(isEncoded('')).toBe(false);
|
|
18
|
+
});
|
|
19
|
+
});
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
{
|
|
2
|
+
"compilerOptions": {
|
|
3
|
+
"jsx": "react-jsx",
|
|
4
|
+
"allowJs": false,
|
|
5
|
+
"esModuleInterop": false,
|
|
6
|
+
"allowSyntheticDefaultImports": true,
|
|
7
|
+
"strict": true,
|
|
8
|
+
"types": ["vite/client", "vitest"],
|
|
9
|
+
"moduleResolution": "bundler"
|
|
10
|
+
},
|
|
11
|
+
"files": [],
|
|
12
|
+
"include": [],
|
|
13
|
+
"references": [
|
|
14
|
+
{
|
|
15
|
+
"path": "./tsconfig.lib.json"
|
|
16
|
+
},
|
|
17
|
+
{
|
|
18
|
+
"path": "./tsconfig.spec.json"
|
|
19
|
+
}
|
|
20
|
+
],
|
|
21
|
+
"extends": "../tsconfig.base.json"
|
|
22
|
+
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
{
|
|
2
|
+
"extends": "./tsconfig.json",
|
|
3
|
+
"compilerOptions": {
|
|
4
|
+
"outDir": "../dist/out-tsc",
|
|
5
|
+
"types": [
|
|
6
|
+
"node",
|
|
7
|
+
"@nx/react/typings/cssmodule.d.ts",
|
|
8
|
+
"@nx/react/typings/image.d.ts",
|
|
9
|
+
"vite/client"
|
|
10
|
+
],
|
|
11
|
+
"moduleResolution": "bundler"
|
|
12
|
+
},
|
|
13
|
+
"exclude": [
|
|
14
|
+
"**/*.spec.ts",
|
|
15
|
+
"**/*.test.ts",
|
|
16
|
+
"**/*.spec.tsx",
|
|
17
|
+
"**/*.test.tsx",
|
|
18
|
+
"**/*.spec.js",
|
|
19
|
+
"**/*.test.js",
|
|
20
|
+
"**/*.spec.jsx",
|
|
21
|
+
"**/*.test.jsx"
|
|
22
|
+
],
|
|
23
|
+
"include": ["src/**/*.js", "src/**/*.jsx", "src/**/*.ts", "src/**/*.tsx"]
|
|
24
|
+
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
{
|
|
2
|
+
"extends": "./tsconfig.json",
|
|
3
|
+
"compilerOptions": {
|
|
4
|
+
"outDir": "../dist/out-tsc",
|
|
5
|
+
"types": [
|
|
6
|
+
"vitest/globals",
|
|
7
|
+
"vitest/importMeta",
|
|
8
|
+
"vite/client",
|
|
9
|
+
"node",
|
|
10
|
+
"vitest",
|
|
11
|
+
"@testing-library/jest-dom"
|
|
12
|
+
]
|
|
13
|
+
},
|
|
14
|
+
"include": [
|
|
15
|
+
"vite.config.ts",
|
|
16
|
+
"vitest.config.ts",
|
|
17
|
+
"src/**/*.test.ts",
|
|
18
|
+
"src/**/*.spec.ts",
|
|
19
|
+
"src/**/*.test.tsx",
|
|
20
|
+
"src/**/*.spec.tsx",
|
|
21
|
+
"src/**/*.test.js",
|
|
22
|
+
"src/**/*.spec.js",
|
|
23
|
+
"src/**/*.test.jsx",
|
|
24
|
+
"src/**/*.spec.jsx",
|
|
25
|
+
"src/**/*.d.ts"
|
|
26
|
+
]
|
|
27
|
+
}
|