用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
直接命令不会经过审查 Prompt;运行前请先检查来源。
npx skills add https://github.com/tomevault-io/skills-registry --skill flutter-adaptive-cards-testing命令会保持在同一行。复制前请横向滚动并检查完整内容。
想先保存到本地?可下载 SkillsMP 当前能够提供的文件。
正在显示 SKILL.md
基于 SOC 职业分类
| name | flutter-adaptive-cards-testing |
| description | > Use when this capability is needed. |
All library tests live under:
packages/flutter_adaptive_cards_fs/test/
Tests are run from that package directory, not the monorepo root:
cd packages/flutter_adaptive_cards_fs
fvm flutter test # all tests
fvm flutter test test/golden_sample_test.dart # specific file
fvm flutter test --tags golden # only golden image tests
fvm flutter test --update-goldens # regenerate golden images
To ensure tests are resilient to UI refactoring, always locate widgets via
generateWidgetKey() / generateAdaptiveWidgetKey() rather than hardcoded
ValueKey strings or text/type finders.
import 'package:flutter_adaptive_cards_fs/src/utils/utils.dart';
// Extract the element map from the card body before assertions
final elementMap = map['body'][0] as Map<String, dynamic>;
// [GOOD] Derived from the same map used to build the widget
expect(find.byKey(generateWidgetKey(elementMap)), findsOneWidget);
// [GOOD] Outer StatefulWidget wrapper
expect(find.byKey(generateAdaptiveWidgetKey(elementMap)), findsOneWidget);
// [GOOD] ChoiceSet item (suffix form)
expect(
find.byKey(generateWidgetKey(elementMap, suffix: 'Choice 1')),
findsOneWidget,
);
// [NEVER] Hard-coded string — breaks silently if the id format changes
// find.byKey(const ValueKey('submitButton')) ← do NOT do this
// [AVOID] Brittle and broken by text changes
// find.text('Submit')
// [AVOID] Ambiguous in large cards
// find.byType(ElevatedButton)
[!IMPORTANT] Never write
find.byKey(const ValueKey('someId'))in tests. If the key format ever changes, string literals silently break whereasgenerateWidgetKey()calls continue to match the live implementation.
test/utils/test_utils.dartImport this in every test file:
import 'utils/test_utils.dart';
getTestWidgetFromPath & getTestWidgetFromMap — Primary Test HelpersThese helpers load an Adaptive Card (from a file or a Map) and return a fully-wrapped MaterialApp.
[!IMPORTANT] Mandatory Usage: Always use these helpers instead of
RawAdaptiveCard.fromMaporAdaptiveCardsCanvasdirectly. They ensure that:
- ID Injection: Missing IDs are recursively injected into the JSON map.
- Context: Necessary
ProviderScopeandInheritedAdaptiveCardHandlersare provided.- UI Context: The card is wrapped in a
MaterialApp,Scaffold, andRepaintBoundary.
Architecture Note: These helpers automatically wrap the card in:
key, used to target specific regions for golden images.onSubmit, onExecute, onChange, etc., if provided as arguments.Widget getTestWidgetFromPath({
required String path, // relative to test/samples/
Key? key, // targets the RepaintBoundary for Goldens
// ... handlers
})
Widget getTestWidgetFromMap({
required Map<String, dynamic> map,
required String title,
Key? key,
// ... handlers
})
All widgets use deterministic ValueKeys generated by two functions from
package:flutter_adaptive_cards_fs/src/utils/utils.dart.
| Widget Type | Generator call | Produced key |
|---|---|---|
| Card Wrapper | generateAdaptiveWidgetKey(elementMap) | ValueKey('{id}_adaptive') |
| Input Content | generateWidgetKey(elementMap) | ValueKey('{id}') |
| ChoiceSet Item | generateWidgetKey(elementMap, suffix: 'Choice 1') | ValueKey('{id}_Choice 1') |
| Modal Search | generateWidgetKey(elementMap) | Same id as input field |
import 'package:flutter_adaptive_cards_fs/src/utils/utils.dart';
// 1. Define the card map
final Map<String, dynamic> map = {
'type': 'AdaptiveCard',
'body': [
{'type': 'Input.Text', 'id': 'myField', 'label': 'Name'},
],
};
// 2. Pump the widget
await tester.pumpWidget(getTestWidgetFromMap(map: map, title: 'Test'));
await tester.pumpAndSettle();
// 3. Extract element map — the single source of truth for keys
final fieldMap = map['body'][0] as Map<String, dynamic>;
// 4. Find widgets
expect(find.byKey(generateAdaptiveWidgetKey(fieldMap)), findsOneWidget); // wrapper
expect(find.byKey(generateWidgetKey(fieldMap)), findsOneWidget); // input
// 5. Interact
await tester.enterText(find.byKey(generateWidgetKey(fieldMap)), 'hello');
Reference: See AdaptiveWidget-Key-Generation.md for the full key contract and automatic ID injection rules.
[!WARNING] Golden image pixels are platform-specific. This project organizes golden images into platform-specific subdirectories:
test/gold_files/linux/: Project-wide source of truth (CI generated).test/gold_files/macos/: Local verification images.Updating Goldens: Should primarily be done via CI (for Linux results). Use
getGoldenPath(filename)to dynamically resolve the path.
testWidgets('My Card Golden', (tester) async {
// 1. Fixed viewport
RendererBinding.instance.renderViews.first.configuration =
TestViewConfiguration.fromView(
size: const Size(500, 700),
view: PlatformDispatcher.instance.implicitView!,
);
const key = ValueKey('paint');
// 2. Load and Pump
await tester.pumpWidget(getTestWidgetFromPath(path: 'my_card.json', key: key));
await tester.pumpAndSettle();
// 3. Compare (Note: targets the key, uses dynamic platform path)
await expectLater(
find.byKey(key),
matchesGoldenFile(getGoldenPath('my_card-base.png')),
);
}, tags: ['golden']);
You can generate goldens on your local machine for visual verification purposes, but they will not be used for CI testing and they should not be comitted to the repository.
cd packages/flutter_adaptive_cards_fs
flutter test --update-goldens --tags golden
Warning: Golden image pixels are platform-specific. macOS-generated goldens may not match Linux CI exactly. The project uses
dart_test.yamlto manage this. Checktest/analysis_options.yamlfor any tag restrictions.
The local AI agents should always run the tests with the --exclude-tags golden flag to speed up the test execution and because local execution of golden tests will fail due to the platform aliasing issues.
flutter test --exclude-tags golden
Sample JSON cards live in test/samples/.
Always add a new sample JSON when implementing a feature or fixing a bug to enable regression testing and designer validation.
test/samples/feature_name.json.getTestWidgetFromPath(path: 'feature_name.json').Source: freemansoft/Flutter-AdaptiveCards — distributed by TomeVault.