-
-
Notifications
You must be signed in to change notification settings - Fork 260
Expand file tree
/
Copy pathsimulator-accessibility.test.ts
More file actions
120 lines (102 loc) · 3.91 KB
/
simulator-accessibility.test.ts
File metadata and controls
120 lines (102 loc) · 3.91 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
import { describe, it, expect } from 'vitest';
import {
createMockExecutor,
createCommandMatchingMockExecutor,
createMockCommandResponse,
} from '../../test-utils/mock-executors.ts';
import type { CommandExecutor } from '../execution/index.ts';
import { ensureSimulatorAccessibility } from '../simulator-accessibility.ts';
const SIM_UUID = '12345678-1234-4234-8234-123456789012';
describe('ensureSimulatorAccessibility', () => {
it('should always write both accessibility flags', async () => {
const executorCalls: string[][] = [];
const mockExecutor = createCommandMatchingMockExecutor({
'defaults write': { success: true, output: '' },
});
const trackingExecutor: CommandExecutor = async (...args) => {
executorCalls.push(args[0] as string[]);
return mockExecutor(...args);
};
await ensureSimulatorAccessibility(SIM_UUID, trackingExecutor);
expect(executorCalls).toHaveLength(2);
expect(executorCalls[0].join(' ')).toContain('AccessibilityEnabled');
expect(executorCalls[0].join(' ')).toContain('defaults write');
expect(executorCalls[1].join(' ')).toContain('ApplicationAccessibilityEnabled');
expect(executorCalls[1].join(' ')).toContain('defaults write');
});
it('should not throw when executor throws', async () => {
const mockExecutor = createMockExecutor(new Error('spawn failed'));
// Should not throw
await ensureSimulatorAccessibility(SIM_UUID, mockExecutor);
});
it('should attempt second write even when first executor call throws', async () => {
const executorCalls: string[][] = [];
const callCount = { n: 0 };
const mockExecutor: CommandExecutor = async (command) => {
executorCalls.push(command as string[]);
callCount.n++;
if (callCount.n === 1) {
throw new Error('spawn failed');
}
return createMockCommandResponse({ success: true, output: '' });
};
await ensureSimulatorAccessibility(SIM_UUID, mockExecutor);
// Second write should still be attempted even when first throws
expect(executorCalls).toHaveLength(2);
expect(executorCalls[1].join(' ')).toContain('ApplicationAccessibilityEnabled');
});
it('should attempt both writes even when first write fails', async () => {
const executorCalls: string[][] = [];
const callCount = { n: 0 };
const mockExecutor: CommandExecutor = async (command) => {
executorCalls.push(command as string[]);
callCount.n++;
if (callCount.n === 1) {
return createMockCommandResponse({ success: false, error: 'write failed' });
}
return createMockCommandResponse({ success: true, output: '' });
};
await ensureSimulatorAccessibility(SIM_UUID, mockExecutor);
// Both writes should be attempted even when first fails
expect(executorCalls).toHaveLength(2);
});
it('should not throw when first write fails', async () => {
const mockExecutor = createCommandMatchingMockExecutor({
'AccessibilityEnabled -bool': { success: false, error: 'write failed' },
});
// Should not throw
await ensureSimulatorAccessibility(SIM_UUID, mockExecutor);
});
it('should pass correct simctl spawn commands', async () => {
const executorCalls: string[][] = [];
const mockExecutor: CommandExecutor = async (command) => {
executorCalls.push(command as string[]);
return createMockCommandResponse({ success: true, output: '' });
};
await ensureSimulatorAccessibility(SIM_UUID, mockExecutor);
expect(executorCalls[0]).toEqual([
'xcrun',
'simctl',
'spawn',
SIM_UUID,
'defaults',
'write',
'com.apple.Accessibility',
'AccessibilityEnabled',
'-bool',
'true',
]);
expect(executorCalls[1]).toEqual([
'xcrun',
'simctl',
'spawn',
SIM_UUID,
'defaults',
'write',
'com.apple.Accessibility',
'ApplicationAccessibilityEnabled',
'-bool',
'true',
]);
});
});