mirror of
https://github.com/apache/superset.git
synced 2026-04-23 01:55:09 +00:00
fix(sqllab): prevent unwanted tab switching when autocompleting table names on SQL Lab (#35992)
This commit is contained in:
committed by
GitHub
parent
d123249bd2
commit
9fbfcf0ccd
@@ -370,6 +370,93 @@ describe('sqlLabReducer', () => {
|
||||
newState = sqlLabReducer(newState, action);
|
||||
expect(newState.tables).toHaveLength(0);
|
||||
});
|
||||
test('should set activeSouthPaneTab when adding expanded table', () => {
|
||||
const expandedTable = {
|
||||
...table,
|
||||
id: 'expanded_table_id',
|
||||
name: 'expanded_table',
|
||||
expanded: true,
|
||||
};
|
||||
const action = {
|
||||
type: actions.MERGE_TABLE,
|
||||
table: expandedTable,
|
||||
};
|
||||
newState = sqlLabReducer(initialState, action);
|
||||
expect(newState.tables).toHaveLength(1);
|
||||
expect(newState.activeSouthPaneTab).toBe(expandedTable.id);
|
||||
});
|
||||
test('should not set activeSouthPaneTab when adding collapsed table', () => {
|
||||
const collapsedTable = {
|
||||
...table,
|
||||
id: 'collapsed_table_id',
|
||||
name: 'collapsed_table',
|
||||
expanded: false,
|
||||
};
|
||||
const action = {
|
||||
type: actions.MERGE_TABLE,
|
||||
table: collapsedTable,
|
||||
};
|
||||
newState = sqlLabReducer(initialState, action);
|
||||
expect(newState.tables).toHaveLength(1);
|
||||
expect(newState.activeSouthPaneTab).toBe(initialState.activeSouthPaneTab);
|
||||
});
|
||||
test('should set activeSouthPaneTab when merging existing table with expanded=true', () => {
|
||||
// First add a table with expanded=false
|
||||
const collapsedTable = {
|
||||
...table,
|
||||
id: 'existing_table_id',
|
||||
name: 'existing_table',
|
||||
expanded: false,
|
||||
};
|
||||
const addAction = {
|
||||
type: actions.MERGE_TABLE,
|
||||
table: collapsedTable,
|
||||
};
|
||||
newState = sqlLabReducer(initialState, addAction);
|
||||
const previousActiveSouthPaneTab = newState.activeSouthPaneTab;
|
||||
|
||||
// Now merge the same table with expanded=true
|
||||
const expandedTable = {
|
||||
...collapsedTable,
|
||||
expanded: true,
|
||||
};
|
||||
const mergeAction = {
|
||||
type: actions.MERGE_TABLE,
|
||||
table: expandedTable,
|
||||
};
|
||||
newState = sqlLabReducer(newState, mergeAction);
|
||||
expect(newState.tables).toHaveLength(1);
|
||||
expect(newState.activeSouthPaneTab).toBe(expandedTable.id);
|
||||
expect(newState.activeSouthPaneTab).not.toBe(previousActiveSouthPaneTab);
|
||||
});
|
||||
test('should not set activeSouthPaneTab when merging existing table with expanded=false', () => {
|
||||
// First add a table with expanded=true
|
||||
const expandedTable = {
|
||||
...table,
|
||||
id: 'existing_table_id_2',
|
||||
name: 'existing_table_2',
|
||||
expanded: true,
|
||||
};
|
||||
const addAction = {
|
||||
type: actions.MERGE_TABLE,
|
||||
table: expandedTable,
|
||||
};
|
||||
newState = sqlLabReducer(initialState, addAction);
|
||||
expect(newState.activeSouthPaneTab).toBe(expandedTable.id);
|
||||
|
||||
// Now merge the same table with expanded=false
|
||||
const collapsedTable = {
|
||||
...expandedTable,
|
||||
expanded: false,
|
||||
};
|
||||
const mergeAction = {
|
||||
type: actions.MERGE_TABLE,
|
||||
table: collapsedTable,
|
||||
};
|
||||
newState = sqlLabReducer(newState, mergeAction);
|
||||
expect(newState.tables).toHaveLength(1);
|
||||
expect(newState.activeSouthPaneTab).toBe(expandedTable.id);
|
||||
});
|
||||
});
|
||||
// eslint-disable-next-line no-restricted-globals -- TODO: Migrate from describe blocks
|
||||
describe('Run Query', () => {
|
||||
|
||||
Reference in New Issue
Block a user