Skip to content

Commit b1495c3

Browse files
committed
Add comprehensive tests for tab persistence functionality
1 parent ce3435f commit b1495c3

File tree

2 files changed

+133
-0
lines changed

2 files changed

+133
-0
lines changed
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
import queryReducer, {setResultTab} from '../query';
2+
import type {QueryState} from '../types';
3+
4+
describe('resultTab functionality', () => {
5+
const initialState: QueryState = {
6+
input: '',
7+
history: {
8+
queries: [],
9+
currentIndex: -1,
10+
},
11+
};
12+
13+
test('should set result tab for explain query type', () => {
14+
const action = setResultTab({queryType: 'explain', tabId: 'json'});
15+
const newState = queryReducer(initialState, action);
16+
17+
expect(newState.selectedResultTab).toEqual({
18+
explain: 'json',
19+
});
20+
});
21+
22+
test('should set result tab for execute query type', () => {
23+
const action = setResultTab({queryType: 'execute', tabId: 'stats'});
24+
const newState = queryReducer(initialState, action);
25+
26+
expect(newState.selectedResultTab).toEqual({
27+
execute: 'stats',
28+
});
29+
});
30+
31+
test('should maintain separate tabs for different query types', () => {
32+
const state1 = queryReducer(
33+
initialState,
34+
setResultTab({queryType: 'explain', tabId: 'json'}),
35+
);
36+
const state2 = queryReducer(state1, setResultTab({queryType: 'execute', tabId: 'stats'}));
37+
38+
expect(state2.selectedResultTab).toEqual({
39+
explain: 'json',
40+
execute: 'stats',
41+
});
42+
});
43+
44+
test('should update existing tab preference', () => {
45+
const state1 = queryReducer(
46+
initialState,
47+
setResultTab({queryType: 'explain', tabId: 'json'}),
48+
);
49+
const state2 = queryReducer(state1, setResultTab({queryType: 'explain', tabId: 'ast'}));
50+
51+
expect(state2.selectedResultTab).toEqual({
52+
explain: 'ast',
53+
});
54+
});
55+
});
Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
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

Comments
 (0)