reveha commented on code in PR #41338:
URL: https://github.com/apache/superset/pull/41338#discussion_r3459950307


##########
superset-frontend/src/features/alerts/components/NotificationMethod.test.tsx:
##########
@@ -34,6 +34,82 @@ import {
 import { NotificationMethod, mapSlackValues } from './NotificationMethod';
 import { NotificationMethodOption, NotificationSetting } from '../types';
 
+type MockAsyncSelectOption = {
+  label: string;
+  value: string;
+};
+
+type MockAsyncSelectProps = {
+  ariaLabel?: string;
+  'data-test'?: string;
+  name?: string;
+  onChange?: (value: MockAsyncSelectOption[]) => void;
+  options?: (
+    filterValue: string,
+    page: number,
+    pageSize: number,
+  ) => Promise<{ data: MockAsyncSelectOption[]; totalCount: number }>;
+  placeholder?: string;
+  value?: MockAsyncSelectOption[];
+};
+
+jest.mock('@superset-ui/core/components', () => {
+  const actual = jest.requireActual('@superset-ui/core/components');
+  const React = jest.requireActual('react');
+
+  return {
+    ...actual,
+    AsyncSelect: ({
+      ariaLabel,
+      'data-test': dataTest,
+      name,
+      onChange,
+      options,
+      placeholder,
+      value = [],
+    }: MockAsyncSelectProps) => {
+      const [loadedOptions, setLoadedOptions] = React.useState<
+        MockAsyncSelectOption[]
+      >([]);
+
+      return (
+        <>
+          <input
+            aria-label={ariaLabel ?? name}
+            data-test={dataTest}
+            placeholder={placeholder}
+            value={value.map(option => option.value).join(',')}
+            onChange={({ target: { value: inputValue } }) =>
+              onChange?.(
+                inputValue
+                  .split(',')
+                  .map(option => option.trim())
+                  .filter(Boolean)
+                  .map(option => ({ label: option, value: option })),
+              )
+            }
+          />
+          {options && dataTest && (
+            <button
+              data-test={`${dataTest}-load-options`}
+              type="button"
+              onClick={async () => {
+                const result = await options('user', 0, 25);

Review Comment:
   Thanks, fixed. The AsyncSelect test mock now matches the production 
comma/semicolon recipient parsing, uses mockResolvedValueOnce to avoid leaking 
SupersetClient.get behavior across tests, and passes the typed search value 
into the options loader instead of using a hardcoded filter. Also verified the 
targeted NotificationMethod test file passes locally.



##########
superset-frontend/src/features/alerts/components/NotificationMethod.test.tsx:
##########
@@ -34,6 +34,82 @@ import {
 import { NotificationMethod, mapSlackValues } from './NotificationMethod';
 import { NotificationMethodOption, NotificationSetting } from '../types';
 
+type MockAsyncSelectOption = {
+  label: string;
+  value: string;
+};
+
+type MockAsyncSelectProps = {
+  ariaLabel?: string;
+  'data-test'?: string;
+  name?: string;
+  onChange?: (value: MockAsyncSelectOption[]) => void;
+  options?: (
+    filterValue: string,
+    page: number,
+    pageSize: number,
+  ) => Promise<{ data: MockAsyncSelectOption[]; totalCount: number }>;
+  placeholder?: string;
+  value?: MockAsyncSelectOption[];
+};
+
+jest.mock('@superset-ui/core/components', () => {
+  const actual = jest.requireActual('@superset-ui/core/components');
+  const React = jest.requireActual('react');
+
+  return {
+    ...actual,
+    AsyncSelect: ({
+      ariaLabel,
+      'data-test': dataTest,
+      name,
+      onChange,
+      options,
+      placeholder,
+      value = [],
+    }: MockAsyncSelectProps) => {
+      const [loadedOptions, setLoadedOptions] = React.useState<
+        MockAsyncSelectOption[]
+      >([]);
+
+      return (
+        <>
+          <input
+            aria-label={ariaLabel ?? name}
+            data-test={dataTest}
+            placeholder={placeholder}
+            value={value.map(option => option.value).join(',')}
+            onChange={({ target: { value: inputValue } }) =>
+              onChange?.(
+                inputValue
+                  .split(',')
+                  .map(option => option.trim())
+                  .filter(Boolean)
+                  .map(option => ({ label: option, value: option })),

Review Comment:
   Thanks, fixed. The AsyncSelect test mock now matches the production 
comma/semicolon recipient parsing, uses mockResolvedValueOnce to avoid leaking 
SupersetClient.get behavior across tests, and passes the typed search value 
into the options loader instead of using a hardcoded filter. Also verified the 
targeted NotificationMethod test file passes locally.



-- 
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]

Reply via email to