Skip to content

Commit 0db1c92

Browse files
committed
fix test
1 parent 619651f commit 0db1c92

2 files changed

Lines changed: 52 additions & 53 deletions

File tree

superset-frontend/src/explore/components/controls/ColorPickerControl.test.tsx

Lines changed: 49 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -33,69 +33,66 @@ const defaultProps = {
3333
onChange: jest.fn(),
3434
};
3535

36-
// eslint-disable-next-line no-restricted-globals -- TODO: Migrate from describe blocks
37-
describe('ColorPickerControl', () => {
38-
beforeAll(() => {
39-
getCategoricalSchemeRegistry()
40-
.registerValue(
41-
'test',
42-
new CategoricalScheme({
43-
id: 'test',
44-
colors: ['#ff0000', '#00ff00', '#0000ff'],
45-
}),
46-
)
47-
.setDefaultKey('test');
48-
});
36+
beforeAll(() => {
37+
getCategoricalSchemeRegistry()
38+
.registerValue(
39+
'test',
40+
new CategoricalScheme({
41+
id: 'test',
42+
colors: ['#ff0000', '#00ff00', '#0000ff'],
43+
}),
44+
)
45+
.setDefaultKey('test');
46+
});
4947

50-
beforeEach(() => {
51-
jest.clearAllMocks();
52-
});
48+
beforeEach(() => {
49+
jest.clearAllMocks();
50+
});
5351

54-
test('renders a ColorPicker component', () => {
55-
render(<ColorPickerControl {...defaultProps} />);
52+
test('renders a ColorPicker component', () => {
53+
render(<ColorPickerControl {...defaultProps} />);
5654

57-
// AntD ColorPicker renders a trigger element with class
58-
const colorPickerTrigger = document.querySelector(
59-
'.ant-color-picker-trigger',
60-
);
61-
expect(colorPickerTrigger).toBeInTheDocument();
62-
});
55+
// AntD ColorPicker renders a trigger element with class
56+
const colorPickerTrigger = document.querySelector(
57+
'.ant-color-picker-trigger',
58+
);
59+
expect(colorPickerTrigger).toBeInTheDocument();
60+
});
6361

64-
test('displays the correct color value', () => {
65-
render(<ColorPickerControl {...defaultProps} />);
62+
test('displays the correct color value', () => {
63+
render(<ColorPickerControl {...defaultProps} />);
6664

67-
// The color should be displayed as hex #007A87 (uppercase in AntD)
68-
expect(screen.getByText('#007A87')).toBeInTheDocument();
69-
});
65+
// The color should be displayed as hex #007A87 (uppercase in AntD)
66+
expect(screen.getByText('#007A87')).toBeInTheDocument();
67+
});
7068

71-
test('calls onChange with RGB values when color changes', async () => {
72-
const onChange = jest.fn();
73-
render(<ColorPickerControl {...defaultProps} onChange={onChange} />);
69+
test('calls onChange with RGB values when color changes', async () => {
70+
const onChange = jest.fn();
71+
render(<ColorPickerControl {...defaultProps} onChange={onChange} />);
7472

75-
// Open the color picker
76-
const colorPickerTrigger = document.querySelector(
77-
'.ant-color-picker-trigger',
78-
);
79-
expect(colorPickerTrigger).toBeInTheDocument();
73+
// Open the color picker
74+
const colorPickerTrigger = document.querySelector(
75+
'.ant-color-picker-trigger',
76+
);
77+
expect(colorPickerTrigger).toBeInTheDocument();
8078

81-
if (colorPickerTrigger) {
82-
await userEvent.click(colorPickerTrigger);
83-
}
79+
if (colorPickerTrigger) {
80+
await userEvent.click(colorPickerTrigger);
81+
}
8482

85-
// Note: Testing actual color selection in AntD ColorPicker would require more complex mocking
86-
// as it uses complex internal components. The main functionality is covered by the component itself.
87-
});
83+
// Note: Testing actual color selection in AntD ColorPicker would require more complex mocking
84+
// as it uses complex internal components. The main functionality is covered by the component itself.
85+
});
8886

89-
test('includes preset colors from the categorical scheme', () => {
90-
render(<ColorPickerControl {...defaultProps} />);
87+
test('includes preset colors from the categorical scheme', () => {
88+
render(<ColorPickerControl {...defaultProps} />);
9189

92-
// The component should have access to the preset colors from the registry
93-
// This is tested by ensuring the component renders without errors with the presets
94-
const colorPickerTrigger = document.querySelector(
95-
'.ant-color-picker-trigger',
96-
);
97-
expect(colorPickerTrigger).toBeInTheDocument();
98-
});
90+
// The component should have access to the preset colors from the registry
91+
// This is tested by ensuring the component renders without errors with the presets
92+
const colorPickerTrigger = document.querySelector(
93+
'.ant-color-picker-trigger',
94+
);
95+
expect(colorPickerTrigger).toBeInTheDocument();
9996
});
10097

10198
test('calls onChange with string key "Green" when resolveThemeTokens is true', async () => {

superset-frontend/src/explore/components/controls/ConditionalFormattingControl/FormattingPopoverContent.test.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,9 @@ test('renders None for operator when Green for increase is selected', async () =
137137
const presets = document.querySelectorAll('.ant-color-picker-presets-color');
138138
const greenPreset = Array.from(presets).find(preset => {
139139
const inner = preset.querySelector('.ant-color-picker-color-block-inner');
140-
return inner && inner.getAttribute('style')?.includes('0, 150, 0');
140+
return (
141+
inner && inner.getAttribute('style')?.includes('rgba(0, 150, 0, 0.2)')
142+
);
141143
});
142144

143145
expect(greenPreset).toBeDefined();

0 commit comments

Comments
 (0)