codeant-ai-for-open-source[bot] commented on code in PR #44843:
URL: https://github.com/apache/superset/pull/44843#discussion_r4150582465


##########
superset-frontend/src/explore/components/controls/ConditionalFormattingControl/ConditionalFormattingControl.test.tsx:
##########
@@ -101,3 +108,210 @@ test('renders verbose column name when available', () => {
   );
   expect(screen.getByText('My Column is false')).toBeInTheDocument();
 });
+
+const numericColumns = [
+  { label: 'Column A', value: 'col_a', dataType: GenericDataType.Numeric },
+  { label: 'Column B', value: 'col_b', dataType: GenericDataType.Numeric },
+];
+
+const greaterThanA: ConditionalFormattingConfig = {
+  column: 'col_a',
+  operator: Comparator.GreaterThan,
+  targetValue: 1,
+  colorScheme: 'colorSuccess',
+};
+
+const lessThanB: ConditionalFormattingConfig = {
+  column: 'col_b',
+  operator: Comparator.LessThan,
+  targetValue: 2,
+  colorScheme: 'colorSuccess',
+};
+
+const renderCrud = (
+  props: Partial<ComponentProps<typeof ConditionalFormattingControl>> = {},
+) => {
+  const onChange = jest.fn();
+  const utils = render(
+    <ConditionalFormattingControl
+      {...defaultProps}
+      columnOptions={numericColumns}
+      onChange={onChange}
+      {...props}
+    />,
+  );
+  return { onChange, ...utils };
+};
+
+const lastChange = (onChange: jest.Mock) =>
+  onChange.mock.calls[onChange.mock.calls.length - 1][0];
+
+// The popover Selects render their options inline next to the trigger, so
+// scope the option lookup to the Select that was opened.
+const pickColumn = async (optionLabel: string) => {
+  const trigger = await screen.findByRole('combobox', {
+    name: 'Select column',
+  });
+  const container = trigger.closest('.ant-select')!
+    .parentElement as HTMLElement;
+  await userEvent.click(trigger);
+  await userEvent.click(await within(container).findByText(optionLabel));
+};
+
+test('opens the add formatter popover from the add label', async () => {
+  renderCrud();
+  expect(screen.queryByText('Add new formatter')).not.toBeInTheDocument();
+
+  await userEvent.click(screen.getByText('Add new color formatter'));
+
+  expect(await screen.findByText('Add new formatter')).toBeInTheDocument();
+  expect(screen.getByText('Apply')).toBeInTheDocument();
+});
+
+test('adds a formatter and reports it through onChange when the popover is 
applied', async () => {
+  const { onChange } = renderCrud();
+
+  await userEvent.click(screen.getByText('Add new color formatter'));
+  await pickColumn('Column B');
+  await userEvent.click(await screen.findByText('Apply'));
+
+  await waitFor(() =>
+    expect(lastChange(onChange)).toEqual([
+      expect.objectContaining({ column: 'col_b' }),
+    ]),
+  );
+  expect(screen.getByText('col_b')).toBeInTheDocument();
+  await waitFor(() =>
+    expect(screen.queryByText('Add new formatter')).not.toBeInTheDocument(),
+  );
+});
+
+test('appends a new formatter after the existing ones', async () => {
+  const { onChange } = renderCrud({ value: [greaterThanA] });
+
+  await userEvent.click(screen.getByText('Add new color formatter'));
+  await pickColumn('Column B');
+  await userEvent.click(await screen.findByText('Apply'));
+
+  await waitFor(() => expect(lastChange(onChange)).toHaveLength(2));
+  expect(lastChange(onChange)[0]).toEqual(greaterThanA);
+  expect(lastChange(onChange)[1]).toEqual(
+    expect.objectContaining({ column: 'col_b' }),
+  );
+});
+
+test('opens the edit popover prefilled from the clicked formatter', async () 
=> {
+  renderCrud({ value: [greaterThanA, lessThanB] });
+
+  await userEvent.click(screen.getByText('col_b < 2'));
+
+  expect(await screen.findByText('Edit formatter')).toBeInTheDocument();
+  expect(screen.getByLabelText('Target value')).toHaveValue('2');
+});
+
+test('replaces the edited formatter at its index and keeps the others', async 
() => {
+  const { onChange } = renderCrud({ value: [greaterThanA, lessThanB] });
+
+  await userEvent.click(screen.getByText('col_b < 2'));
+  await screen.findByText('Edit formatter');
+  const targetValue = screen.getByLabelText('Target value');
+  await userEvent.clear(targetValue);
+  await userEvent.type(targetValue, '7');
+  await userEvent.click(screen.getByText('Apply'));
+
+  await waitFor(() =>
+    expect(lastChange(onChange)).toEqual([
+      greaterThanA,
+      expect.objectContaining({
+        column: 'col_b',
+        operator: Comparator.LessThan,
+        targetValue: 7,
+      }),
+    ]),
+  );
+  expect(screen.getByText('col_b < 7')).toBeInTheDocument();
+  expect(screen.queryByText('col_b < 2')).not.toBeInTheDocument();

Review Comment:
   **Suggestion:** These edit tests serialize updates, so they do not detect 
stale render-state updates that lose another formatter during overlapping edits 
or delete-then-edit operations.
   
   **Assessment:** ๐ŸŸ  `Major` ยท ๐Ÿ” `Occurrence: Rarely` ยท ๐Ÿท๏ธ `Race condition`
   
   [![Use CodeAnt 
Skill](https://new-codeant-butcket.s3.us-west-1.amazonaws.com/badges/use-codeant-skill-flat-v2.svg)](https://docs.codeant.ai/cli/resolve-pr-comments-skill)
 [![Fix in 
Cursor](https://new-codeant-butcket.s3.us-west-1.amazonaws.com/badges/fix-in-cursor-flat.svg)](https://app.codeant.ai/fix-in-ide?tool=cursor&prompt_id=0711d0ffa57d44828a4c517c37f52ad6&service=github&base_url=https%3A%2F%2Fgithub.com&org=apache&repo=apache%2Fsuperset)
 [![Fix in VSCode 
Claude](https://new-codeant-butcket.s3.us-west-1.amazonaws.com/badges/fix-in-vscode-claude-flat.svg)](https://app.codeant.ai/fix-in-ide?tool=vscode-claude&prompt_id=0711d0ffa57d44828a4c517c37f52ad6&service=github&base_url=https%3A%2F%2Fgithub.com&org=apache&repo=apache%2Fsuperset)
   <details>
   <summary><b>Prompt for AI Agent ๐Ÿค– </b></summary>
   
   ```mdx
   This is a comment left during a code review.
   
   **Path:** 
superset-frontend/src/explore/components/controls/ConditionalFormattingControl/ConditionalFormattingControl.test.tsx
   **Line:** 213:233
   **Comment:**
        *Race Condition: These edit tests serialize updates, so they do not 
detect stale render-state updates that lose another formatter during 
overlapping edits or delete-then-edit operations.
   
   Validate the correctness of the flagged issue. If correct, How can I resolve 
this? If you propose a fix, implement it and please make it concise.
   Once fix is implemented, also check other comments on the same PR, and ask 
user if the user wants to fix the rest of the comments as well. if said yes, 
then fetch all the comments validate the correctness and implement a minimal fix
   ```
   </details>
   <a 
href='https://app.codeant.ai/feedback?pr_url=https%3A%2F%2Fgithub.com%2Fapache%2Fsuperset%2Fpull%2F44843&comment_hash=fef235cdb306d1b92a8bfd932e1c9fa037b3255c2e5b03dada5cccc301b1e571&reaction=like'>๐Ÿ‘</a>
 | <a 
href='https://app.codeant.ai/feedback?pr_url=https%3A%2F%2Fgithub.com%2Fapache%2Fsuperset%2Fpull%2F44843&comment_hash=fef235cdb306d1b92a8bfd932e1c9fa037b3255c2e5b03dada5cccc301b1e571&reaction=dislike'>๐Ÿ‘Ž</a>



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