Skip to content

Commit abd620d

Browse files
committed
feat(core): upgrades MUI to v6
BREAKING CHANGE: Upgrades MUI version to v6
1 parent 5987b3b commit abd620d

File tree

8 files changed

+363
-0
lines changed

8 files changed

+363
-0
lines changed
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
import { fireEvent, render, screen } from '@testing-library/react';
2+
import { DeleteButton } from '../../lib/components/buttons/DeleteButton';
3+
import '@testing-library/jest-dom';
4+
import jest from 'jest-mock';
5+
6+
test('renders DeleteButton component', () => {
7+
render(
8+
<DeleteButton
9+
loading={false}
10+
onClick={() => {
11+
console.log('Clicked Delete Button');
12+
}}
13+
/>
14+
);
15+
16+
const deleteButton = screen.getByRole('button', { name: 'Delete' });
17+
expect(deleteButton).toBeInTheDocument();
18+
});
19+
20+
test('renders DeleteButton with custom label', () => {
21+
render(
22+
<DeleteButton
23+
loading={false}
24+
label="Remove"
25+
onClick={() => {
26+
console.log('Clicked Delete Button');
27+
}}
28+
/>
29+
);
30+
31+
const deleteButton = screen.getByRole('button', { name: 'Remove' });
32+
expect(deleteButton).toBeInTheDocument();
33+
});
34+
35+
test('renders with custom data-cy attribute', () => {
36+
render(<DeleteButton loading={false} name="Delete" dataCy="custom-delete-button" onClick={() => {}} />);
37+
38+
const deleteButton = screen.getByRole('button', { name: 'Delete' });
39+
expect(deleteButton).toHaveAttribute('data-cy', 'custom-delete-button');
40+
});
41+
42+
test('renders with custom startIcon', () => {
43+
render(<DeleteButton loading={false} name="Delete" startIcon={<span data-testid="custom-icon" />} onClick={() => {}} />);
44+
45+
const customIcon = screen.getByTestId('custom-icon');
46+
expect(customIcon).toBeInTheDocument();
47+
});
48+
49+
test('renders with custom type', () => {
50+
render(<DeleteButton loading={false} name="Delete" type="submit" onClick={() => {}} />);
51+
52+
const deleteButton = screen.getByRole('button', { name: 'Delete' });
53+
expect(deleteButton).toHaveAttribute('type', 'submit');
54+
});
55+
56+
test('calls onClick when clicked', () => {
57+
const handleClick = jest.fn();
58+
render(<DeleteButton loading={false} name="Delete" onClick={handleClick} />);
59+
60+
const deleteButton = screen.getByRole('button', { name: 'Delete' });
61+
fireEvent.click(deleteButton);
62+
expect(handleClick).toHaveBeenCalledTimes(1);
63+
});
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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+
});
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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+
});
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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+
});
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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+
});
Lines changed: 131 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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+
});
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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+
});
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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 commit comments

Comments
 (0)