Logo de Widget Golden And A11y Testing

Widget Golden And A11y Testing

Comunidade
zakariaf
widget-golden-and-a11y-testing

Enforces a disciplined widget/layout/golden/a11y test surface — one pumpApp harness that pins tester.view.physicalSize x devicePixelRatio and layers MediaQuery (textScaler/boldText/accessibleNavigation) above MaterialApp, an overflow net that never suppresses (one testWidgets per device x scale x bold tuple because overflow reports once per RenderObject), a computed getSize/getRect fit-and-geometry gate instead of goldens, two golden lanes (Ahem geometry + one pinned-OS real-font) with loadAppFonts and blocked --update-goldens, RTL goldens under Directionality, pure-Dart WCAG/APCA contrast on colour VALUES, and honest limits on meetsGuideline. Use when writing test/support/harness.dart, calling pumpWidget/pumpApp, chasing an "overflowed by N pixels" failure, reaching for takeException/ignoreOverflowErrors/FittedBox/withClampedTextScaling, adding matchesGoldenFile, or writing a11y_test.dart with isSemantics/simulatedAccessibilityTraversal/meetsGuideline.

Add to TypingMind

Visão geral

Publicado porzakariaf
RepositórioFlutter-Skills
Nome da habilidadewidget-golden-and-a11y-testing
Estrelas
64
Forks
15
Arquivos incluídos
8
LicençaMIT
Links
  • Instruções em Markdown

    Um arquivo SKILL.md que o modelo carrega sob demanda, consumindo tokens apenas quando uma solicitação é realmente relevante para a habilidade.

  • Funciona com qualquer LLM

    As habilidades de IA são escritas em Markdown simples, não em código específico de um provedor. Por isso, funcionam com GPT, Claude, Gemini, Grok ou um modelo local.

  • Arquivos incluídos: 8

    Scripts, templates e referências que o modelo pode ler enquanto trabalha. Os arquivos são somente para leitura e nunca são executados.

  • Código aberto

    Publicada por zakariaf no GitHub. Leia os arquivos da habilidade antes de instalá-la.

Instalação

Instale a habilidade de IA Widget Golden And A11y Testing no TypingMind para usá-la com qualquer LLM ou adicione-a a outro agente que leia SKILL.md.

1

Instalar no TypingMind

O TypingMind instala uma habilidade diretamente da pasta dela no GitHub — lê o arquivo SKILL.md, reúne os arquivos de recursos em um pacote e armazena o resultado localmente.

  1. Abra o app e vá para Plugins → Habilidades.
  2. Escolha "Instalar do GitHub".
  3. Cole a URL abaixo, que aponta para a pasta da habilidade, e confirme.
    https://github.com/zakariaf/Flutter-Skills/tree/main/skills/widget-golden-and-a11y-testing
  4. Ative a habilidade em cada chat em que quiser disponibilizá-la.
Plugins → Habilidades → Adicionar habilidade → Via URL do GitHub. Depois, cole a URL da pasta e pressione Continuar.
2

Instalar em outro agente

Qualquer agente que leia o formato Agent Skills pode usar esta habilidade — copie a pasta para o diretório de habilidades desse agente.

Claude Code — .claude/skills
git clone --depth 1 https://github.com/zakariaf/Flutter-Skills.git /tmp/Flutter-Skills
mkdir -p .claude/skills
cp -r /tmp/Flutter-Skills/skills/widget-golden-and-a11y-testing .claude/skills/widget-golden-and-a11y-testing
Reinicie Claude Code após copiar para que a nova habilidade seja reconhecida.

Use no TypingMind

Ative Widget Golden And A11y Testing em qualquer chat do TypingMind e o modelo cuida do resto. O nome e a descrição da habilidade ficam no prompt do sistema e, assim que uma solicitação relevante aparece, o modelo carrega as instruções completas automaticamente — sem precisar de acionamento manual e sem consumir tokens até que ela seja realmente usada.

O modelo carrega Widget Golden And A11y Testing automaticamente assim que uma solicitação é relevante para essa habilidade.

Funciona com qualquer modelo de IA

Habilidades de IA são instruções em Markdown simples, não código específico de um provedor. Por isso, Widget Golden And A11y Testing não fica vinculada ao modelo para o qual foi criada. Instale-a uma vez no TypingMind e use-a com GPT-5, Claude, Gemini, Grok, DeepSeek, Mistral, Llama ou um modelo local executado por conta própria — tudo com suas próprias chaves de API.

  • Carregada apenas quando necessário

    O prompt do sistema contém apenas o nome e a descrição. As instruções são buscadas na primeira solicitação relevante, então uma habilidade sem uso não gera custo.

  • Troque de modelo durante a conversa

    Como a habilidade é composta de instruções, não de código, trocar de modelo não afeta seu funcionamento — o próximo modelo lê o mesmo arquivo SKILL.md.

Instruções da habilidade

Este é o conteúdo de SKILL.md que o modelo carrega. Leia antes de instalar — uma habilidade é um conjunto de instruções que seu modelo seguirá.

Widget, golden and accessibility testing

One harness pins the surface; layout and accessibility are asserted by computed geometry on the real widget tree, not by blessed pixels. Goldens are a narrow, honest safety net for glyph shaping and mirroring — never the layout gate. This skill covers the widget tier; for the pure-core / Drift / Notifier tiers see testing-strategy.

Read the reference for the task at hand:

  • references/harness-and-mediaquery.md — pumpApp, Device presets, the four load-bearing lines, driving MediaQuery flags, finder policy.
  • references/overflow-and-textscale.md — the two overflow classes, the three traps, the matrix, the fit assertion, and the four wrong fixes.
  • references/a11y-guidelines-and-limits.md — the four built-in guidelines and their defects, the semantics/traversal gate, pure-Dart contrast, and what automation genuinely cannot cover.
  • references/golden-two-lanes.md — the golden-refusal argument, the Ahem-vs-real-font lanes, RTL goldens, and blocking accidental blessing.

Run scripts/check-test-hygiene.sh before a PR.

Non-negotiable rules

  1. Pin the device on every layout/geometry test. The default widget surface is 800x600 logical — wider than any phone. Unpinned, content is ~2x too wide, everything fits, the suite is green, and the shipped phone is broken. useDevice(...) first, pumpApp(...) second.
  2. physicalSize is in PHYSICAL pixels — always multiply by DPR. view.physicalSize = Size(320, 640) at the default DPR 3.0 is a 107x213 logical surface, not a phone. Set devicePixelRatio and physicalSize = logical * dpr, then addTearDown(view.reset) — a leaked size poisons every later test in the file.
  3. Layer MediaQuery ABOVE MaterialApp, built from .copyWith. MaterialApp inserts no MediaQuery of its own; the one from pumpWidget's View is nearest. A bare MediaQueryData() zeroes the view-derived size the device just pinned — the test then measures a 0x0 screen and passes.
  4. pump(), never pumpAndSettle() as an animation wait. pumpAndSettle carries a 10-minute timeout and truncates its stack trace, and hangs forever on an infinite splash/shimmer/spinner. Use pump() for state changes and pump(duration) / fakeAsync for timer-driven async — pump() does not advance the fake clock.
  5. Never suppress overflow. A RenderFlex overflow already fails a widget test (it routes through FlutterError.reportError and the binding rethrows at test end). Never call takeException() to swallow it, never assign FlutterError.onError, never copy ignoreOverflowErrors, and never takeException() in a global tearDown — each disarms the whole net.
  6. One testWidgets per (device, scale, bold) tuple — never a loop inside a test. Overflow is reported once per RenderObject (the flag resets only on reassemble()), so looping scales inside one test silently under-reports every scale after the first. Loop around the testWidgets call.
  7. Assert the fit, not just absence of overflow. A clipped Text reports nothing — RenderParagraph has no overflow indicator. takeException(), isNull is necessary but not sufficient; add a getSize/getRect assertion that the label fits inside its computed cell.
  8. Prefer computed geometry over goldens for layout. Assert cells in a row share a top and cells in a column share a left (moreOrLessEquals, epsilon: 0.5); assert tap targets with a getSize loop. These fail with a sentence a human can act on. Goldens cannot assert anything — a blessed screen of clipped, unreadable text passes forever.
  9. Assert contrast on colour VALUES in pure Dart, never on pixels. meetsGuideline(textContrastGuideline) screenshots and histograms the layer — white text on #FAFAFA passes (an open Flutter defect). A pure-Dart WCAG + APCA test on the theme's colours cannot false-pass. For a state pair distinguished only by chroma (selected vs surface at equal luminance), assert wcag(theme.selected, theme.surface) directly — a grayscale-mode user perceives exactly that luminance gap, so no separate grayscale channel is needed.
  10. await expectLater(...) for meetsGuideline — it returns an AsyncMatcher. A plain expect() looks right and asserts nothing. Keep the four built-in guidelines only as advisory tripwires; the geometry and pure-Dart contrast tests are the gate.
  11. Two golden lanes, both loadAppFonts(); block accidental --update-goldens. Ahem squares are byte-stable cross-OS and prove geometry/mirroring but not glyph shaping; one narrow real-font lane on a pinned OS proves script joining and numeral glyphs. Tag every golden @Tags(['golden']) and generate blessed files in one pinned environment only.
  12. Never clamp TextScaler. withClampedTextScaling, textScaleFactor, and FittedBox defeat the matrix while contrast and tap-target stay green, and override the user's own OS setting. Fix the layout, not the text.

The harness — one file, imported by every test

test/support/harness.dart holds a Device value type and a pumpApp extension. Seams throw until overridden, so an un-overridden dependency fails loudly instead of quietly constructing a live service in a test. See references/harness-and-mediaquery.md and examples/harness.dart.

dart
class Device {
  const Device(this.name, this.logicalSize, this.dpr);
  final String name;
  final Size logicalSize;
  final double dpr;

  // Neutral presets; name them by measured size, not a marketing model.
  static const compact = Device('compact_320', Size(320, 640), 2.0);
  static const small = Device('small_360', Size(360, 800), 3.0);
  static const medium = Device('medium_412', Size(412, 915), 2.625);
  static const all = <Device>[compact, small, medium];
}

extension TestHarness on WidgetTester {
  void useDevice(Device d) {
    view.devicePixelRatio = d.dpr;
    view.physicalSize = d.logicalSize * d.dpr; // physical px — multiply by DPR
    addTearDown(view.reset);                    // one call; nothing forgotten
  }

  Future<void> pumpApp({
    List<Override> overrides = const <Override>[],
    TextScaler textScaler = TextScaler.noScaling,
    bool boldText = false,
    bool accessibleNavigation = false,
  }) async {
    await pumpWidget(
      ProviderScope(
        overrides: overrides,
        child: Builder(
          builder: (context) => MediaQuery(
            data: MediaQuery.of(context).copyWith( // copyWith, NOT MediaQueryData()
              textScaler: textScaler,
              boldText: boldText,
              accessibleNavigation: accessibleNavigation,
            ),
            child: const App(),
          ),
        ),
      ),
    );
    await pump(); // one frame; never pumpAndSettle
  }
}

The overflow + fit matrix

Device.all x [1.0, 1.3, 1.5, 2.0, 3.0] x [false, true] bold = one testWidgets per tuple. TextScaler.linear is a deliberate over-approximation (Android 14+ scales large text less) — conservative, not device-faithful. 1.3 and 1.5 are in the list precisely because nonlinear device scaling makes the mid-range the non-obvious part. boldText widens advance widths — but only when a real proportional font is loaded. Under the default Ahem test font every glyph is a fixed em-square regardless of weight, so the bold axis is a no-op unless the matrix calls loadAppFonts() first; with real fonts loaded it overflows content that passes unbolded, and stresses real character widths the em-square hides.

dart
// Real proportional fonts, or the bold + character-width axes are inert under Ahem.
setUpAll(loadAppFonts);

for (final device in Device.all) {
  for (final scale in const <double>[1.0, 1.3, 1.5, 2.0, 3.0]) {
    for (final bold in const <bool>[false, true]) {
      testWidgets('no overflow @ ${device.name} x$scale${bold ? ' bold' : ''}',
          (tester) async {
        tester.useDevice(device);
        await tester.pumpApp(textScaler: TextScaler.linear(scale), boldText: bold);
        // Explicit for a readable message; the binding also rethrows at test end.
        expect(tester.takeException(), isNull,
            reason: 'content overflowed at ${device.name} x$scale');
      });
    }
  }
}

The fit assertion is the real gate — it catches the silent class a clipped Text never reports. See references/overflow-and-textscale.md and examples/overflow_matrix_test.dart.

The accessibility gate

Semantics is ON by default in testWidgets. Assert the node's role and label directly with isSemantics (not the deprecated containsSemantics), measure tap targets with an explicit getSize loop (the built-in guideline skips every node flush with the view edge), and assert contrast on colour values in pure Dart.

dart
testWidgets('each item exposes a button labelled by its display name',
    (tester) async {
  await tester.pumpApp();
  final node = tester.getSemantics(find.byKey(const ValueKey('item_0')));
  expect(node, isSemantics(
    label: 'First item',
    isButton: true,
    hasEnabledState: true,
    isEnabled: true,
    hasTapAction: true,
  ));
});

Be honest: Flutter ships four machine-checkable guidelines (one known-broken), covering a small minority of real accessibility. Never claim a suite "tests accessibility". Switch Access / Switch Control cannot be tested automatically at all. See references/a11y-guidelines-and-limits.md and examples/a11y_test.dart.

Golden lanes

Layout is proven by computed geometry, so goldens are narrow: glyph shaping, mirroring, and numeral rendering that geometry cannot see. Two lanes, both call loadAppFonts(); RTL goldens pump under Directionality. See references/golden-two-lanes.md.

dart
@Tags(['golden'])
library;

testWidgets('card mirrors correctly in RTL', (tester) async {
  await tester.pumpWidget(const Directionality(
    textDirection: TextDirection.rtl,
    child: _CardHarness(),
  ));
  await expectLater(find.byType(ItemCard),
      matchesGoldenFile('goldens/item_card_rtl.png'));
});

Anti-patterns

  • Unpinned layout test. Passes on 800x600, ships a broken 360dp phone. Rule 1.
  • for loop over scales inside one testWidgets. Overflow reports once per RenderObject; scales 2..n are silently unchecked. Rule 6.
  • takeException() in a global tearDown. Clears _pendingExceptionDetails before the binding rethrows — turns the entire overflow net into a no-op.
  • ignoreOverflowErrors / FlutterError.onError = ... in a layout test. The popular helper that loses the net that already exists.
  • FittedBox / TextOverflow.ellipsis / withClampedTextScaling to green a red matrix. Makes the most complex label the smallest, cancels the user's TextScaler, and passes while the product is unreadable. Fix the layout.
  • expect(tester, meetsGuideline(...)) without await expectLater. Asserts nothing — the matcher is async.
  • Tap-target claim resting on meetsGuideline alone. It skips every node flush with the view edge; add the explicit getSize loop.
  • Contrast claim resting on textContrastGuideline. Open false-negative on low-variance backgrounds; assert the colour ratio in pure Dart.
  • find.byType(SomeWidget) for behaviour or geometry. Couples the test to the class hierarchy; a rename reds the suite for nothing. Use find.bySemanticsLabel for behaviour, find.byKey for geometry.
  • A layout golden as the gate. It blesses whatever shipped, including clipped text, and reds on any host that rasterizes fonts differently.

Definition of done

  • Every layout/geometry test — and any a11y test that measures size or position — calls useDevice(...) before pumpApp(...). Pure-semantics tests (role/label, traversal) need no device.
  • Overflow matrix exists as one testWidgets per (device, scale, bold) tuple; no suppression anywhere in test/.
  • A fit assertion (getSize/getRect inside the computed cell) backs the overflow matrix; a geometry invariant replaces the layout golden.
  • Tap targets measured with an explicit getSize loop; meetsGuideline used only as advisory, always via await expectLater.
  • Semantics asserted with isSemantics; label carries the display name, not internal data; traversal order asserted if it is a deliberate design decision.
  • Contrast asserted in pure Dart (WCAG + APCA) over theme colour values, looped over every theme; chroma-only state pairs assert wcag between the two state colours directly.
  • Goldens (if any) are tagged @Tags(['golden']), both lanes call loadAppFonts, RTL goldens exist, and CI blocks --update-goldens.
  • scripts/check-test-hygiene.sh passes.

Related skills

  • See testing-strategy for the overall test doctrine (pure clock-injected core, fakes-over-mocks, real in-memory DB, coverage policy) this widget tier sits on.
  • See accessibility-as-code for authoring the Semantics/roles/labels these tests assert, and i18n-rtl-l10n for the Directional geometry the RTL goldens verify.
  • See design-system-structure for the theme/ColorScheme the pure-Dart contrast gate reads, and flutter-performance for the const/rebuild rules layout tests should not try to re-prove.
  • See state-management-riverpod for the ProviderScope/override seam pumpApp uses, and ci-pipeline-and-gates for wiring the golden lanes and greps into CI.
  • See run-goldens-rebaseline for the one sanctioned ritual that overwrites committed golden images, and ui-states-and-feedback for the four screen states each golden and widget test pumps.

References

Arquivos incluídos

O modelo lê esses arquivos sob demanda enquanto a habilidade está carregada. Eles são disponibilizados para leitura e nunca são executados.

Perguntas frequentes

O que a habilidade de IA Widget Golden And A11y Testing faz?

Enforces a disciplined widget/layout/golden/a11y test surface — one pumpApp harness that pins tester.view.physicalSize x devicePixelRatio and layers MediaQuery (textScaler/boldText/accessibleNavigation) above MaterialApp, an overflow net that never suppresses (one testWidgets per device x scale x bold tuple because overflow reports once per RenderObject), a computed getSize/getRect fit-and-geometry gate instead of goldens, two golden lanes (Ahem geometry + one pinned-OS real-font) with loadAppFonts and blocked --update-goldens, RTL goldens under Directionality, pure-Dart WCAG/APCA contrast...

Por que usar Widget Golden And A11y Testing no TypingMind?

Porque basta instalar uma vez para usar com qualquer modelo. A habilidade Widget Golden And A11y Testing é escrita em Markdown simples, e não em código específico de um provedor, então a mesma habilidade funciona com GPT-5, Claude, Gemini, Grok ou um modelo local — e é possível trocar de modelo no meio do chat sem que ela deixe de funcionar. No TypingMind, você usa suas próprias chaves de API e paga diretamente aos provedores, em vez de pagar uma assinatura por licença de usuário. Suas habilidades e chats permanecem no seu próprio armazenamento.

Como instalar Widget Golden And A11y Testing no TypingMind?

Abra Plugins → Habilidades → Instalar do GitHub no TypingMind e cole https://github.com/zakariaf/Flutter-Skills/tree/main/skills/widget-golden-and-a11y-testing. O TypingMind lê o arquivo SKILL.md, reúne os arquivos da habilidade e a instala para que possa ser ativada em cada chat.

Quais modelos de IA podem usar Widget Golden And A11y Testing?

Qualquer modelo conectado no TypingMind. As habilidades de IA são instruções em Markdown simples, e não código específico de um provedor. Assim, GPT, Claude, Gemini, Grok e modelos locais podem carregar esta habilidade quando uma solicitação corresponder a ela.

Quantos modelos de IA posso usar com Widget Golden And A11y Testing?

Quantos quiser. Desde que o modelo ofereça suporte a habilidades, é possível usar Widget Golden And A11y Testing com ele — GPT, Claude, Gemini, Grok, DeepSeek, Mistral, Llama e outros — tudo no TypingMind com suas próprias chaves de API.

A habilidade de IA Widget Golden And A11y Testing é gratuita?

Sim. A habilidade é publicada no GitHub por zakariaf sob a licença MIT. O pagamento é feito apenas ao seu provedor de IA pelos tokens usados.

O que são habilidades de IA?

Uma habilidade de IA é um conjunto reutilizável de instruções que ensina um modelo de IA a realizar uma tarefa específica. Ela segue o formato aberto Agent Skills: um arquivo SKILL.md com nome e descrição, além de scripts, templates ou arquivos de referência de que o modelo possa precisar. O modelo lê as instruções apenas quando sua solicitação corresponde à habilidade, então uma habilidade instalada não gera custos até ser usada.

Qual é a diferença entre habilidades de IA e plugins ou servidores MCP?

Um plugin ou servidor MCP oferece ao modelo novas ferramentas que ele pode acionar — código que é executado em algum lugar e retorna um resultado. Já uma habilidade de IA dá ao modelo o conhecimento e as orientações de que ele precisa: como abordar uma tarefa, quais etapas seguir e como deve ser um bom resultado. As habilidades são escritas em Markdown simples, por isso não precisam de servidor, chave de API nem ambiente de execução, e funcionam com qualquer modelo.

Ver lista completa

Crie seu próprio espaço de trabalho com IA agora

Inscreva-se na nossa newsletter para receber avisos sobre novos recursos e futuros sorteios 👇