|
| 1 | +/** |
| 2 | + * Tauri API Helper for E2E Tests |
| 3 | + * |
| 4 | + * Uses window.__TAURI_TEST_API__ exposed by the app. |
| 5 | + */ |
| 6 | + |
| 7 | +// Generic invoke helper |
| 8 | +export async function invoke<T>(command: string, args?: Record<string, unknown>): Promise<T> { |
| 9 | + return browser.execute(async (cmd: string, cmdArgs: Record<string, unknown>) => { |
| 10 | + if (!window.__TAURI_TEST_API__) { |
| 11 | + throw new Error('Tauri Test API not available'); |
| 12 | + } |
| 13 | + return window.__TAURI_TEST_API__.invoke(cmd, cmdArgs); |
| 14 | + }, command, args || {}) as Promise<T>; |
| 15 | +} |
| 16 | + |
| 17 | +// ============================================================================ |
| 18 | +// Space API |
| 19 | +// ============================================================================ |
| 20 | + |
| 21 | +export interface Space { |
| 22 | + id: string; |
| 23 | + name: string; |
| 24 | + icon: string | null; |
| 25 | + is_default: boolean; |
| 26 | +} |
| 27 | + |
| 28 | +export async function createSpace(name: string, icon?: string): Promise<Space> { |
| 29 | + return invoke<Space>('create_space', { name, icon }); |
| 30 | +} |
| 31 | + |
| 32 | +export async function deleteSpace(id: string): Promise<void> { |
| 33 | + return invoke<void>('delete_space', { id }); |
| 34 | +} |
| 35 | + |
| 36 | +export async function listSpaces(): Promise<Space[]> { |
| 37 | + return invoke<Space[]>('list_spaces'); |
| 38 | +} |
| 39 | + |
| 40 | +export async function getActiveSpace(): Promise<Space | null> { |
| 41 | + return invoke<Space | null>('get_active_space'); |
| 42 | +} |
| 43 | + |
| 44 | +export async function setActiveSpace(id: string): Promise<void> { |
| 45 | + return invoke<void>('set_active_space', { id }); |
| 46 | +} |
| 47 | + |
| 48 | +// ============================================================================ |
| 49 | +// Client API |
| 50 | +// ============================================================================ |
| 51 | + |
| 52 | +export interface Client { |
| 53 | + id: string; |
| 54 | + name: string; |
| 55 | + client_type: string; |
| 56 | + connection_mode: 'locked' | 'follow_active' | 'ask_on_change'; |
| 57 | + locked_space_id: string | null; |
| 58 | + grants: Record<string, string[]>; |
| 59 | +} |
| 60 | + |
| 61 | +export interface CreateClientInput { |
| 62 | + name: string; |
| 63 | + client_type: string; |
| 64 | + connection_mode: string; |
| 65 | + locked_space_id?: string; |
| 66 | +} |
| 67 | + |
| 68 | +export async function createClient(input: CreateClientInput): Promise<Client> { |
| 69 | + return invoke<Client>('create_client', { input }); |
| 70 | +} |
| 71 | + |
| 72 | +export async function deleteClient(id: string): Promise<void> { |
| 73 | + return invoke<void>('delete_client', { id }); |
| 74 | +} |
| 75 | + |
| 76 | +export async function listClients(): Promise<Client[]> { |
| 77 | + return invoke<Client[]>('list_clients'); |
| 78 | +} |
| 79 | + |
| 80 | +export async function grantFeatureSetToClient( |
| 81 | + clientId: string, |
| 82 | + spaceId: string, |
| 83 | + featureSetId: string |
| 84 | +): Promise<void> { |
| 85 | + return invoke<void>('grant_feature_set_to_client', { clientId, spaceId, featureSetId }); |
| 86 | +} |
| 87 | + |
| 88 | +// ============================================================================ |
| 89 | +// FeatureSet API |
| 90 | +// ============================================================================ |
| 91 | + |
| 92 | +export interface FeatureSet { |
| 93 | + id: string; |
| 94 | + name: string; |
| 95 | + feature_set_type: 'all' | 'default' | 'server-all' | 'custom'; |
| 96 | + server_id: string | null; |
| 97 | + is_builtin: boolean; |
| 98 | +} |
| 99 | + |
| 100 | +export async function listFeatureSetsBySpace(spaceId: string): Promise<FeatureSet[]> { |
| 101 | + return invoke<FeatureSet[]>('list_feature_sets_by_space', { spaceId }); |
| 102 | +} |
| 103 | + |
| 104 | +export async function createFeatureSet(input: { |
| 105 | + name: string; |
| 106 | + space_id: string; |
| 107 | + description?: string; |
| 108 | +}): Promise<FeatureSet> { |
| 109 | + return invoke<FeatureSet>('create_feature_set', { input }); |
| 110 | +} |
| 111 | + |
| 112 | +export async function deleteFeatureSet(id: string): Promise<void> { |
| 113 | + return invoke<void>('delete_feature_set', { id }); |
| 114 | +} |
| 115 | + |
| 116 | +// ============================================================================ |
| 117 | +// Server API |
| 118 | +// ============================================================================ |
| 119 | + |
| 120 | +export interface InstalledServer { |
| 121 | + id: string; |
| 122 | + space_id: string; |
| 123 | + is_enabled: boolean; |
| 124 | + input_values: Record<string, string>; |
| 125 | +} |
| 126 | + |
| 127 | +export async function installServer(id: string, spaceId: string): Promise<void> { |
| 128 | + return invoke<void>('install_server', { id, spaceId }); |
| 129 | +} |
| 130 | + |
| 131 | +export async function uninstallServer(id: string, spaceId: string): Promise<void> { |
| 132 | + return invoke<void>('uninstall_server', { id, spaceId }); |
| 133 | +} |
| 134 | + |
| 135 | +export async function listInstalledServers(spaceId?: string): Promise<InstalledServer[]> { |
| 136 | + return invoke<InstalledServer[]>('list_installed_servers', { spaceId }); |
| 137 | +} |
| 138 | + |
| 139 | +export async function saveServerInputs( |
| 140 | + id: string, |
| 141 | + inputValues: Record<string, string>, |
| 142 | + spaceId: string |
| 143 | +): Promise<void> { |
| 144 | + return invoke<void>('save_server_inputs', { id, inputValues, spaceId }); |
| 145 | +} |
| 146 | + |
| 147 | +export async function enableServerV2(spaceId: string, serverId: string): Promise<void> { |
| 148 | + return invoke<void>('enable_server_v2', { spaceId, serverId }); |
| 149 | +} |
| 150 | + |
| 151 | +export async function disableServerV2(spaceId: string, serverId: string): Promise<void> { |
| 152 | + return invoke<void>('disable_server_v2', { spaceId, serverId }); |
| 153 | +} |
| 154 | + |
| 155 | +// ============================================================================ |
| 156 | +// Gateway API |
| 157 | +// ============================================================================ |
| 158 | + |
| 159 | +export interface GatewayStatus { |
| 160 | + running: boolean; |
| 161 | + url: string | null; |
| 162 | + connected_backends: number; |
| 163 | +} |
| 164 | + |
| 165 | +export async function getGatewayStatus(): Promise<GatewayStatus> { |
| 166 | + return invoke<GatewayStatus>('get_gateway_status'); |
| 167 | +} |
0 commit comments