forked from Txio-labs/txio
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsettingsToggles.test.ts
More file actions
135 lines (120 loc) · 4.21 KB
/
Copy pathsettingsToggles.test.ts
File metadata and controls
135 lines (120 loc) · 4.21 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
import { describe, it, expect, beforeEach, vi } from 'vitest';
describe('telemetry gate', () => {
beforeEach(() => {
vi.resetModules();
localStorage.clear();
});
it('does not queue events when disabled', async () => {
const tel = await import('./telemetry');
tel.setTelemetryEnabled(false);
tel.clearTelemetryQueue();
tel.track('app_boot');
expect(tel.getTelemetryQueue()).toHaveLength(0);
});
it('queues events when enabled', async () => {
const tel = await import('./telemetry');
tel.setTelemetryEnabled(true);
tel.clearTelemetryQueue();
tel.track('settings_changed', { key: 'telemetry', value: true });
const q = tel.getTelemetryQueue();
expect(q).toHaveLength(1);
expect(q[0].name).toBe('settings_changed');
expect(q[0].props?.key).toBe('telemetry');
});
});
describe('saveCurrentTab + finalizeRequest dirty flag', () => {
beforeEach(() => {
vi.resetModules();
localStorage.clear();
});
it('marks dirty on finalizeRequest and clears on saveCurrentTab', async () => {
vi.doMock('../services/api', () => ({
ApiError: class extends Error {
status = 0;
},
apiService: {
login: vi.fn(),
register: vi.fn(),
setToken: vi.fn(),
getProfile: vi.fn(),
getWorkspaces: vi.fn(),
getCollections: vi.fn()
}
}));
const { appStore } = await import('./store');
const { RequestType } = await import('../types');
appStore.openTab('rpc');
const tabId = appStore.getSnapshot().activeTabId;
expect(tabId).toBeTruthy();
appStore.finalizeRequest(tabId!, 'rpc', {
id: 'req-1',
name: 'Test RPC',
type: RequestType.RPC,
network: 'testnet',
rpcParams: { method: 'sui_getChainIdentifier', params: [] },
moveParams: {
packageId: '',
module: '',
function: '',
typeArguments: [],
arguments: [],
gasBudget: '10000000'
}
});
expect(
appStore.getSnapshot().tabs.find((t) => t.id === tabId)?.isDirty
).toBe(true);
appStore.saveCurrentTab();
const after = appStore.getSnapshot();
expect(after.tabs.find((t) => t.id === tabId)?.isDirty).toBe(false);
expect(after.savedTabs.some((t) => t.id === tabId)).toBe(true);
// Second save upserts, not duplicates
appStore.finalizeRequest(tabId!, 'rpc', {
id: 'req-1',
name: 'Test RPC v2',
type: RequestType.RPC,
network: 'testnet',
rpcParams: { method: 'sui_getChainIdentifier', params: [] },
moveParams: {
packageId: '',
module: '',
function: '',
typeArguments: [],
arguments: [],
gasBudget: '10000000'
}
});
appStore.saveCurrentTab();
expect(
after.savedTabs.filter((t) => t.id === tabId).length
).toBeLessThanOrEqual(1);
expect(
appStore.getSnapshot().savedTabs.filter((t) => t.id === tabId)
).toHaveLength(1);
});
it('updateSettings toggles all three flags', async () => {
vi.doMock('../services/api', () => ({
ApiError: class extends Error {
status = 0;
},
apiService: {
login: vi.fn(),
register: vi.fn(),
setToken: vi.fn(),
getProfile: vi.fn(),
getWorkspaces: vi.fn(),
getCollections: vi.fn()
}
}));
const { appStore } = await import('./store');
appStore.updateSettings({
showLineNumbers: false,
autoSave: false,
telemetry: false
});
const s = appStore.getSnapshot().settings;
expect(s.showLineNumbers).toBe(false);
expect(s.autoSave).toBe(false);
expect(s.telemetry).toBe(false);
});
});