sadpandajoe commented on code in PR #38591:
URL: https://github.com/apache/superset/pull/38591#discussion_r3002714230
##########
superset-frontend/src/pages/AlertReportList/AlertReportList.test.tsx:
##########
@@ -17,270 +17,467 @@
* under the License.
*/
import fetchMock from 'fetch-mock';
-import configureStore from 'redux-mock-store';
-import thunk from 'redux-thunk';
import {
render,
screen,
fireEvent,
waitFor,
+ createStore,
} from 'spec/helpers/testing-library';
+import { Provider } from 'react-redux';
import { MemoryRouter } from 'react-router-dom';
import { QueryParamProvider } from 'use-query-params';
import { ReactRouter5Adapter } from 'use-query-params/adapters/react-router-5';
-import React from 'react';
import AlertListComponent from 'src/pages/AlertReportList';
-// Cast to accept partial mock props in tests
+jest.setTimeout(30000);
+
const AlertList = AlertListComponent as unknown as React.FC<
Record<string, any>
>;
Review Comment:
Fixed in eede7cc — added `import type React from 'react'`.
##########
superset-frontend/src/features/alerts/components/NumberInput.test.tsx:
##########
@@ -0,0 +1,67 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+import { render, screen, fireEvent } from 'spec/helpers/testing-library';
+import NumberInput from './NumberInput';
+
+const defaultProps = {
+ timeUnit: 'seconds',
+ min: 0,
+ name: 'timeout',
+ value: '30',
+ placeholder: 'Enter value',
+ onChange: jest.fn(),
+};
+
+test('renders value with timeUnit suffix when not focused', () => {
+ render(<NumberInput {...defaultProps} />);
+ const input = screen.getByPlaceholderText('Enter value');
+ expect(input).toHaveValue('30 seconds');
+});
+
+test('strips suffix on focus and restores on blur', () => {
+ render(<NumberInput {...defaultProps} />);
+ const input = screen.getByPlaceholderText('Enter value');
+
+ fireEvent.focus(input);
+ expect(input).toHaveValue('30');
+
+ fireEvent.blur(input);
+ expect(input).toHaveValue('30 seconds');
+});
+
+test('renders empty string when value is falsy', () => {
+ render(<NumberInput {...defaultProps} value="" />);
+ const input = screen.getByPlaceholderText('Enter value');
+ expect(input).toHaveValue('');
+});
+
+test('renders empty string when value is zero', () => {
+ render(<NumberInput {...defaultProps} value={0} />);
+ const input = screen.getByPlaceholderText('Enter value');
+ expect(input).toHaveValue('');
Review Comment:
The test documents the component's current behavior — `NumberInput` uses a
truthiness check (`value ? ...`) at line 47, so `0` renders as empty. Changing
this would be a production component fix, which is out of scope for this PR.
--
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]