( runtime, options, )
| 249 | }; |
| 250 | |
| 251 | export const isCommand: RuntimeCommand<IsCommandOptions, IsCommandResult> = async ( |
| 252 | runtime, |
| 253 | options, |
| 254 | ): Promise<IsCommandResult> => { |
| 255 | if (!isSupportedPredicate(options.predicate)) { |
| 256 | throw new AppError( |
| 257 | 'INVALID_ARGS', |
| 258 | 'is requires predicate: visible|hidden|exists|editable|selected|text', |
| 259 | ); |
| 260 | } |
| 261 | if (options.predicate === 'text' && !options.expectedText) { |
| 262 | throw new AppError('INVALID_ARGS', 'is text requires expected text value'); |
| 263 | } |
| 264 | const includeRects = predicateNeedsRects(options.predicate); |
| 265 | const capture = await captureSelectorSnapshot(runtime, options, { |
| 266 | updateSession: true, |
| 267 | includeRects, |
| 268 | }); |
| 269 | const chain = parseSelectorChain(options.selector); |
| 270 | |
| 271 | if (options.predicate === 'exists') { |
| 272 | const matched = findSelectorChainMatch(capture.snapshot.nodes, chain, { |
| 273 | platform: runtime.backend.platform, |
| 274 | }); |
| 275 | if (!matched) { |
| 276 | throw new AppError('COMMAND_FAILED', formatSelectorFailure(chain, [], { unique: false })); |
| 277 | } |
| 278 | return { |
| 279 | predicate: options.predicate, |
| 280 | pass: true, |
| 281 | selector: matched.selector.raw, |
| 282 | matches: matched.matches, |
| 283 | selectorChain: chain.selectors.map((entry) => entry.raw), |
| 284 | }; |
| 285 | } |
| 286 | |
| 287 | const resolved = resolveSelectorChain(capture.snapshot.nodes, chain, { |
| 288 | platform: runtime.backend.platform, |
| 289 | requireRect: false, |
| 290 | requireUnique: true, |
| 291 | disambiguateAmbiguous: false, |
| 292 | }); |
| 293 | if (!resolved) { |
| 294 | throw new AppError('COMMAND_FAILED', formatSelectorFailure(chain, [], { unique: true }), { |
| 295 | command: 'is', |
| 296 | reason: 'selector_not_found', |
| 297 | predicate: options.predicate, |
| 298 | selector: chain.raw, |
| 299 | }); |
| 300 | } |
| 301 | const result = evaluateIsPredicate({ |
| 302 | predicate: options.predicate, |
| 303 | node: resolved.node, |
| 304 | nodes: capture.snapshot.nodes, |
| 305 | expectedText: options.expectedText, |
| 306 | platform: runtime.backend.platform, |
| 307 | }); |
| 308 | if (!result.pass) { |
no test coverage detected