22 * Tests for long_press tool plugin
33 */
44
5- import { describe , it , expect } from 'vitest' ;
5+ import { describe , it , expect , beforeEach } from 'vitest' ;
66import { z } from 'zod' ;
77import { createMockExecutor } from '../../../../test-utils/mock-executors.ts' ;
8+ import { sessionStore } from '../../../../utils/session-store.ts' ;
89import longPressPlugin , { long_pressLogic } from '../long_press.ts' ;
910
1011describe ( 'Long Press Plugin' , ( ) => {
11- // Setup for each test - no vitest mocks to clear
12+ beforeEach ( ( ) => {
13+ sessionStore . clear ( ) ;
14+ } ) ;
1215
1316 describe ( 'Export Field Validation (Literal)' , ( ) => {
1417 it ( 'should have correct name' , ( ) => {
@@ -28,65 +31,78 @@ describe('Long Press Plugin', () => {
2831 it ( 'should validate schema fields with safeParse' , ( ) => {
2932 const schema = z . object ( longPressPlugin . schema ) ;
3033
31- // Valid case
3234 expect (
3335 schema . safeParse ( {
34- simulatorId : '12345678-1234-1234-1234-123456789012' ,
3536 x : 100 ,
3637 y : 200 ,
3738 duration : 1500 ,
3839 } ) . success ,
3940 ) . toBe ( true ) ;
4041
41- // Invalid simulatorId
42- expect (
43- schema . safeParse ( {
44- simulatorId : 'invalid-uuid' ,
45- x : 100 ,
46- y : 200 ,
47- duration : 1500 ,
48- } ) . success ,
49- ) . toBe ( false ) ;
50-
51- // Invalid x (not integer)
5242 expect (
5343 schema . safeParse ( {
54- simulatorId : '12345678-1234-1234-1234-123456789012' ,
5544 x : 100.5 ,
5645 y : 200 ,
5746 duration : 1500 ,
5847 } ) . success ,
5948 ) . toBe ( false ) ;
6049
61- // Invalid y (not integer)
6250 expect (
6351 schema . safeParse ( {
64- simulatorId : '12345678-1234-1234-1234-123456789012' ,
6552 x : 100 ,
6653 y : 200.5 ,
6754 duration : 1500 ,
6855 } ) . success ,
6956 ) . toBe ( false ) ;
7057
71- // Invalid duration (not positive)
7258 expect (
7359 schema . safeParse ( {
74- simulatorId : '12345678-1234-1234-1234-123456789012' ,
7560 x : 100 ,
7661 y : 200 ,
7762 duration : 0 ,
7863 } ) . success ,
7964 ) . toBe ( false ) ;
8065
81- // Invalid duration (negative)
8266 expect (
8367 schema . safeParse ( {
84- simulatorId : '12345678-1234-1234-1234-123456789012' ,
8568 x : 100 ,
8669 y : 200 ,
8770 duration : - 100 ,
8871 } ) . success ,
8972 ) . toBe ( false ) ;
73+
74+ const withSimId = schema . safeParse ( {
75+ simulatorId : '12345678-1234-1234-1234-123456789012' ,
76+ x : 100 ,
77+ y : 200 ,
78+ duration : 1500 ,
79+ } ) ;
80+ expect ( withSimId . success ) . toBe ( true ) ;
81+ expect ( 'simulatorId' in ( withSimId . data as Record < string , unknown > ) ) . toBe ( false ) ;
82+ } ) ;
83+ } ) ;
84+
85+ describe ( 'Handler Requirements' , ( ) => {
86+ it ( 'should require simulatorId session default' , async ( ) => {
87+ const result = await longPressPlugin . handler ( { x : 100 , y : 200 , duration : 1500 } ) ;
88+
89+ expect ( result . isError ) . toBe ( true ) ;
90+ const message = result . content [ 0 ] . text ;
91+ expect ( message ) . toContain ( 'Missing required session defaults' ) ;
92+ expect ( message ) . toContain ( 'simulatorId is required' ) ;
93+ expect ( message ) . toContain ( 'session-set-defaults' ) ;
94+ } ) ;
95+
96+ it ( 'should surface validation errors once simulator default exists' , async ( ) => {
97+ sessionStore . setDefaults ( { simulatorId : '12345678-1234-1234-1234-123456789012' } ) ;
98+
99+ const result = await longPressPlugin . handler ( { x : 100 , y : 200 , duration : 0 } ) ;
100+
101+ expect ( result . isError ) . toBe ( true ) ;
102+ const message = result . content [ 0 ] . text ;
103+ expect ( message ) . toContain ( 'Parameter validation failed' ) ;
104+ expect ( message ) . toContain ( 'duration: Duration of the long press in milliseconds' ) ;
105+ expect ( message ) . toContain ( 'Tip: set session defaults via session-set-defaults' ) ;
90106 } ) ;
91107 } ) ;
92108
0 commit comments