gabotorresruiz commented on code in PR #35254:
URL: https://github.com/apache/superset/pull/35254#discussion_r2395610534
##########
superset-frontend/src/features/themes/ThemeModal.test.tsx:
##########
@@ -87,200 +57,385 @@ const mockTheme: ThemeObject = {
},
};
-// Mock theme API endpoints
-fetchMock.get('glob:*/api/v1/theme/1', {
- result: mockTheme,
-});
-
-fetchMock.post('glob:*/api/v1/theme/', {
- result: { ...mockTheme, id: 2 },
-});
+const mockSystemTheme: ThemeObject = {
+ ...mockTheme,
+ id: 2,
+ theme_name: 'System Theme',
+ is_system: true,
+};
-fetchMock.put('glob:*/api/v1/theme/1', {
- result: mockTheme,
-});
+const defaultProps = {
+ addDangerToast: jest.fn(),
+ addSuccessToast: jest.fn(),
+ onThemeAdd: jest.fn(),
+ onHide: jest.fn(),
+ show: true,
+ canDevelop: false,
+};
-// These are defined but not used in the simplified tests
-// const mockUser = {
-// userId: 1,
-// firstName: 'Admin',
-// lastName: 'User',
-// roles: { Admin: [['can_write', 'Dashboard']] },
-// permissions: {},
-// isActive: true,
-// isAnonymous: false,
-// username: 'admin',
-// email: '[email protected]',
-// user_id: 1,
-// first_name: 'Admin',
-// last_name: 'User',
-// };
-
-// const defaultProps = {
-// addDangerToast: jest.fn(),
-// addSuccessToast: jest.fn(),
-// onThemeAdd: jest.fn(),
-// onHide: jest.fn(),
-// show: true,
-// };
+const setup = (props = {}) => {
+ const utils = render(<ThemeModal {...defaultProps} {...props} />, {
+ useRedux: true,
+ useRouter: true,
+ });
+ return {
+ ...utils,
+ mockProps: { ...defaultProps, ...props },
+ };
+};
describe('ThemeModal', () => {
beforeEach(() => {
- fetchMock.resetHistory();
+ fetchMock.reset();
+ fetchMock.get('glob:*/api/v1/theme/1', { result: mockTheme });
+ fetchMock.get('glob:*/api/v1/theme/2', { result: mockSystemTheme });
+ fetchMock.get('glob:*/api/v1/theme/*', { result: mockTheme });
+ fetchMock.post('glob:*/api/v1/theme/', { result: { ...mockTheme, id: 3 }
});
+ fetchMock.put('glob:*/api/v1/theme/*', { result: mockTheme });
jest.clearAllMocks();
});
afterEach(() => {
fetchMock.restore();
});
- test('should export ThemeModal component', () => {
- const ThemeModalModule = jest.requireActual('./ThemeModal');
- expect(ThemeModalModule.default).toBeDefined();
- expect(typeof ThemeModalModule.default).toBe('object'); // HOC wrapped
component
- });
+ describe('Component Rendering', () => {
+ test('should render modal when show is true', () => {
+ setup();
+ expect(screen.getByRole('dialog')).toBeInTheDocument();
+ expect(screen.getByText('Add theme')).toBeInTheDocument();
+ });
- test('should have correct type definitions', () => {
- expect(mockTheme).toMatchObject({
- id: expect.any(Number),
- theme_name: expect.any(String),
- json_data: expect.any(String),
- changed_on_delta_humanized: expect.any(String),
- changed_by: expect.objectContaining({
- first_name: expect.any(String),
- last_name: expect.any(String),
- }),
+ test('should not render modal when show is false', () => {
+ const { container } = setup({ show: false });
+ expect(container.querySelector('.ant-modal')).not.toBeInTheDocument();
});
- });
- test('should validate JSON data structure', () => {
- const isValidJson = (str: string) => {
- try {
- JSON.parse(str);
- return true;
- } catch (e) {
- return false;
- }
- };
-
- expect(isValidJson(mockTheme.json_data || '')).toBe(true);
- expect(isValidJson('invalid json')).toBe(false);
- expect(isValidJson('{"valid": "json"}')).toBe(true);
- });
+ test('should render with edit mode title when theme is provided', async ()
=> {
+ setup({ theme: mockTheme });
+ await waitFor(() => {
Review Comment:
Done!
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]