sadpandajoe commented on code in PR #45591:
URL: https://github.com/apache/superset/pull/45591#discussion_r4381707591
##########
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:
The remembered-option tests only assert the accessible name, so they don't
pin the other props the memory exists to restore. Example: changing
`seenOptionsRef` to keep only `{ value, label, 'aria-label' }` (dropping
`title` and any filter props) still passes this test and the picked-from-search
one above it, yet an off-page user picked or pasted this way would stop
matching a typed search on its title once the base page returns. Could one of
these cases type text that appears only in the option's `title`, with results
that exclude that user, and assert the selected option stays in the list?
--
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]