sadpandajoe commented on code in PR #44858:
URL: https://github.com/apache/superset/pull/44858#discussion_r4159799623
##########
superset-frontend/src/components/Datasource/components/CollectionTable/CollectionTable.test.tsx:
##########
@@ -34,3 +34,99 @@ test('renders a table', () => {
const rows = tableBody?.getElementsByTagName('tr');
expect(rows).toHaveLength(mockDatasource['7__table'].columns.length);
});
+
+test('preserves an edit made while sorted after the sort is cleared', () => {
+ const onChange = jest.fn();
+ const collection = [
+ { id: 1, column_name: 'b_col', type: 'VARCHAR' },
+ { id: 2, column_name: 'a_col', type: 'VARCHAR' },
+ ];
+
+ const { container } = render(
+ <CollectionTable
+ collection={collection}
+ tableColumns={['column_name', 'type']}
+ sortColumns={['column_name']}
+ itemRenderers={{
+ type: (val, onItemChange, _label, record) => (
+ <input
+ data-test={`type-input-${record.id}`}
+ value={val as string}
+ onChange={e => onItemChange(e.target.value)}
+ />
+ ),
+ }}
+ onChange={onChange}
+ />,
+ );
+
+ const sorter = container.querySelector('.ant-table-column-sorters');
+ expect(sorter).toBeInTheDocument();
+
+ // Ascending sort by column_name puts a_col (id 2) first.
+ fireEvent.click(sorter!);
+
+ const editedInput = container.querySelector(
+ '[data-test="type-input-2"]',
+ ) as HTMLInputElement;
+ expect(editedInput).toBeInTheDocument();
+ fireEvent.change(editedInput, { target: { value: 'EDITED' } });
+
+ // Cycle the sort back to unsorted (ascend -> descend -> cancel).
+ fireEvent.click(sorter!);
Review Comment:
This only checks the edit after clearing the sort, which restores it from
`collection`; reverting the active-sort path to `propsCollection` would still
pass while the descending sort drops the displayed edit. Could we assert the
edited value and sorted row order after the descending click, before clearing
the sort?
--
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]