codeant-ai-for-open-source[bot] commented on code in PR #44843:
URL: https://github.com/apache/superset/pull/44843#discussion_r4167687423
##########
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:
✅ **Customized review instruction saved!**
**Instruction:**
> Do not require truly concurrent edit tests for this control; only one
popover can be open at a time, so cover sequential edits and delete-then-edit
behavior instead.
**Applied to:**
- `**/ConditionalFormattingControl.test.tsx`
---
💡 *To manage or update this instruction, visit: [CodeAnt AI
Settings](https://app.codeant.ai/org/settings/learnings)*
--
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]