sfirke commented on code in PR #45591:
URL: https://github.com/apache/superset/pull/45591#discussion_r4392634755
##########
superset-frontend/packages/superset-ui-core/src/components/Select/AsyncSelect.test.tsx:
##########
@@ -1681,6 +1745,135 @@ test('onChange is called with the value property when
pasting an option that was
);
});
+test('pasting matches the title of options with a React label', async () => {
+ const onChange = jest.fn();
+ const options = jest.fn(async () => ({
+ data: [
+ { label: <span>Jane Smith</span>, title: 'Jane Smith', value: 1 },
+ { label: <span>Bob Jones</span>, title: 'Bob Jones', value: 2 },
+ ],
+ totalCount: 2,
+ }));
+ render(
+ <AsyncSelect
+ {...defaultProps}
+ options={options}
+ mode="multiple"
+ onChange={onChange}
+ />,
+ );
+ await open();
+ const input = getElementByClassName('.ant-select-input');
+ const paste = createEvent.paste(input, {
+ clipboardData: {
+ getData: () => 'Jane Smith,Bob Jones',
+ },
+ });
+ fireEvent(input, paste);
+ await waitFor(() =>
+ expect(onChange).toHaveBeenCalledWith(
+ [
+ expect.objectContaining({ value: 1 }),
+ expect.objectContaining({ value: 2 }),
+ ],
+ expect.anything(),
+ ),
+ );
+});
+
+test('pasting matches the title of a React-label option that was not loaded
yet', async () => {
+ const onChange = jest.fn();
+ const jane = {
+ label: <span>Jane Smith</span>,
+ title: 'Jane Smith',
+ value: 1,
+ };
+ const bob = { label: <span>Bob Jones</span>, title: 'Bob Jones', value: 2 };
+ const options = jest.fn(async (search: string) => ({
+ data: search === 'Bob Jones' ? [bob] : [jane],
+ totalCount: 2,
+ }));
+ render(
+ <AsyncSelect {...defaultProps} options={options} onChange={onChange} />,
+ );
+ await open();
+ const input = getElementByClassName('.ant-select-input');
+ const paste = createEvent.paste(input, {
+ clipboardData: {
+ getData: () => 'Bob Jones',
+ },
+ });
+ fireEvent(input, paste);
+ await waitFor(() =>
+ expect(onChange).toHaveBeenCalledWith(
+ expect.objectContaining({ value: 2 }),
+ expect.anything(),
+ ),
+ );
+ expect(options).toHaveBeenCalledWith('Bob Jones', 0, expect.any(Number));
+});
+
+test('keeps the extra props of a pasted option that is not on the loaded
page', async () => {
Review Comment:
Good point. The picked-from-search test now pins them. Amy has a `title` of
"Amy Adams" and an `email` filter prop. After the search clears, the test types
`Adams` (only in her title), then `aadams@` (only in her email). For both
searches the mocked server returns only Liam. Each time it asserts Amy stays in
the list and Liam drops out. Changing `seenOptionsRef` to keep only `{ value,
label, 'aria-label' }` fails it.
I also went through every source change in this PR to check that its tests
fail when it's reverted. That turned up one more gap: the `None` test in
`user_search_filter_test.py` passed even without the `None` guard, because no
fixture user contained "None". I added one, so it fails now. Pushed in
deb221557a.
---
🤖 _Drafted by Claude Code, reviewed and approved by @sfirke._
--
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]