|
| 1 | +import queryReducer, {setResultTab} from '../query'; |
| 2 | + |
| 3 | +describe('QueryResultViewer tab persistence integration', () => { |
| 4 | + const initialState = { |
| 5 | + input: '', |
| 6 | + history: { |
| 7 | + queries: [], |
| 8 | + currentIndex: -1, |
| 9 | + }, |
| 10 | + }; |
| 11 | + |
| 12 | + it('should save and retrieve tab selection for explain queries', () => { |
| 13 | + // Test that we can set and get the tab preference |
| 14 | + let state = queryReducer(initialState, setResultTab({queryType: 'explain', tabId: 'json'})); |
| 15 | + |
| 16 | + expect(state.selectedResultTab).toEqual({ |
| 17 | + explain: 'json', |
| 18 | + }); |
| 19 | + |
| 20 | + // Test updating the same query type |
| 21 | + state = queryReducer(state, setResultTab({queryType: 'explain', tabId: 'ast'})); |
| 22 | + |
| 23 | + expect(state.selectedResultTab).toEqual({ |
| 24 | + explain: 'ast', |
| 25 | + }); |
| 26 | + }); |
| 27 | + |
| 28 | + it('should save and retrieve tab selection for execute queries', () => { |
| 29 | + const state = queryReducer( |
| 30 | + initialState, |
| 31 | + setResultTab({queryType: 'execute', tabId: 'stats'}), |
| 32 | + ); |
| 33 | + |
| 34 | + expect(state.selectedResultTab).toEqual({ |
| 35 | + execute: 'stats', |
| 36 | + }); |
| 37 | + }); |
| 38 | + |
| 39 | + it('should maintain separate preferences for different query types', () => { |
| 40 | + let state = initialState; |
| 41 | + |
| 42 | + // Set explain tab |
| 43 | + state = queryReducer(state, setResultTab({queryType: 'explain', tabId: 'json'})); |
| 44 | + expect(state.selectedResultTab).toEqual({ |
| 45 | + explain: 'json', |
| 46 | + }); |
| 47 | + |
| 48 | + // Set execute tab - should not override explain |
| 49 | + state = queryReducer(state, setResultTab({queryType: 'execute', tabId: 'stats'})); |
| 50 | + expect(state.selectedResultTab).toEqual({ |
| 51 | + explain: 'json', |
| 52 | + execute: 'stats', |
| 53 | + }); |
| 54 | + |
| 55 | + // Update explain tab - should not affect execute |
| 56 | + state = queryReducer(state, setResultTab({queryType: 'explain', tabId: 'ast'})); |
| 57 | + expect(state.selectedResultTab).toEqual({ |
| 58 | + explain: 'ast', |
| 59 | + execute: 'stats', |
| 60 | + }); |
| 61 | + }); |
| 62 | + |
| 63 | + it('should handle multiple updates to the same query type', () => { |
| 64 | + let state = initialState; |
| 65 | + |
| 66 | + // Set initial value |
| 67 | + state = queryReducer(state, setResultTab({queryType: 'explain', tabId: 'schema'})); |
| 68 | + expect(state.selectedResultTab?.explain).toBe('schema'); |
| 69 | + |
| 70 | + // Update to different tab |
| 71 | + state = queryReducer(state, setResultTab({queryType: 'explain', tabId: 'json'})); |
| 72 | + expect(state.selectedResultTab?.explain).toBe('json'); |
| 73 | + |
| 74 | + // Update again |
| 75 | + state = queryReducer(state, setResultTab({queryType: 'explain', tabId: 'ast'})); |
| 76 | + expect(state.selectedResultTab?.explain).toBe('ast'); |
| 77 | + }); |
| 78 | +}); |
0 commit comments