Skip to content

Commit c19a028

Browse files
committed
test: testing ai instructions
1 parent f5bcafe commit c19a028

File tree

9 files changed

+227
-0
lines changed

9 files changed

+227
-0
lines changed

AGENTS.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
React component library for [Cloudscape Design System](https://cloudscape.design/) — an open source design system for building accessible, inclusive web experiences at scale.
2+
3+
To install dependencies use `npm install`
4+
Build with `npm run quick-build` for dev, or `npm run build` for a full production build.
5+
6+
For component structure, props, events, and refs, see docs/COMPONENT_CONVENTIONS.md.
7+
For design tokens, CSS rules, and RTL support, see docs/STYLING.md.
8+
For test commands, see docs/TESTING.md.
9+
For writing tests and test utils, see docs/WRITING_TESTS.md.
10+
For prettier, stylelint, and eslint (`npm run lint`), see docs/CODE_STYLE.md.
11+
For dev/test pages, see docs/DEV_PAGES.md.
12+
For API documentation comments, see docs/API_DOCS.md.
13+
For internal shared utilities, see docs/INTERNALS.md.

docs/API_DOCS.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
# API Documentation Comments
2+
3+
This project uses `@cloudscape-design/documenter` to generate API docs from JSDoc comments in component interface files (`src/<component>/interfaces.ts`).
4+
5+
## Special tags
6+
7+
- `@i18n` — marks internationalization properties
8+
- `@analytics` — marks analytics metadata properties
9+
- `@deprecated` — marks deprecated properties (include replacement info)
10+
- `@displayname` — overrides the display name (e.g. `children``text`)

docs/CODE_STYLE.md

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# Code Style
2+
3+
This project enforces formatting and linting via prettier, stylelint, and eslint. Run `npm run lint` to check everything.
4+
5+
Before writing or modifying code, read the relevant config files:
6+
7+
- Prettier: `.prettierrc`
8+
- Stylelint: `.stylelintrc`
9+
- ESLint: `eslint.config.mjs`
10+
11+
Follow whatever rules are defined there. Do not guess — read the configs.
12+
13+
All source files must include the license header:
14+
15+
```
16+
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
17+
// SPDX-License-Identifier: Apache-2.0
18+
```

docs/COMPONENT_CONVENTIONS.md

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
# Component Conventions
2+
3+
## Ground Rules
4+
5+
- Always read existing code for the component you're working on before writing new code. For new components, pick a similar one as your template.
6+
- Inner HTML structure and class names are not public API — don't rely on them.
7+
8+
## Component Structure
9+
10+
Each public component lives in `src/<component-name>/index.tsx` and must:
11+
12+
- Assign default prop values in the destructuring signature (not `defaultProps`), then pass them explicitly to the internal component
13+
- Call `useBaseComponent` for telemetry — pass `props` (primitive/enum values with defaults applied) and optionally `metadata` (derived counters or booleans). No state props, no PII, no user input strings.
14+
- Use `getExternalProps` or `getBaseProps` to strip internal `__`-prefixed props
15+
- Call `applyDisplayName` at the bottom of the file
16+
- Export the props interface as `${ComponentName}Props`
17+
18+
Each public component has a private counterpart at `src/<component-name>/internal.tsx` for composition. Internal props are prefixed with `__`. The public component must not add behavior beyond what the internal component provides.
19+
20+
Shared hooks, components, contexts, and helpers live in `src/internal/`. Always check there before building new shared code.
21+
22+
## Props & Interfaces
23+
24+
- Props interface: `${ComponentName}Props`, namespace sub-types under it (e.g. `${ComponentName}Props.Variant`)
25+
- Union types must be type aliases (no inline unions)
26+
- Array types must use `ReadonlyArray<T>`
27+
- Cast string props to string at runtime if rendered in JSX — React accepts JSX content there
28+
- Component return type must be exactly `JSX.Element``null` or arrays break the doc generator
29+
- Components exported as default from `index.tsx` are public; everything else is private
30+
31+
## Events
32+
33+
- Use `CancelableEventHandler<DetailType>` or `NonCancelableEventHandler<DetailType>` from `../internal/events`
34+
- All `on*` props must use these interfaces (build fails otherwise)
35+
36+
## Refs
37+
38+
- Expose via `${ComponentName}Props.Ref` interface
39+
- Use `useForwardFocus(ref, elementRef)` for simple focus delegation
40+
- For `React.forwardRef` generics, create a `${ComponentName}ForwardRefType` interface
41+
42+
## Controllable Components
43+
44+
- Controlled: requires `value` + `onChange` (e.g. Input)
45+
- Uncontrolled: internal state only (e.g. dropdown open)
46+
- Controllable: uncontrolled by default, controlled when `value` is set
47+
48+
Use `useControllable` — read existing components for the pattern.
49+
50+
## Element Queries
51+
52+
Use `useContainerBreakpoints` instead of CSS media queries. Handle `null` on first render.
53+
54+
## I18n
55+
56+
Three string categories:
57+
- Static → `i18nStrings` property
58+
- Dynamic → functions in `i18nStrings` returning strings
59+
- Context-dependent → top-level props (out of scope for i18n provider)
60+
61+
Use `useInternalI18n('<component>')` to consume. Test with `TestI18nProvider` from `src/i18n/testing`.
62+
63+
## Dependencies
64+
65+
Before adding any dependency: must support React 16.8+ and latest 3 major Chrome/Firefox/Edge, no global state, ESM preferred, no external resources (CSP).

docs/DEV_PAGES.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# Dev Pages
2+
3+
Dev and test pages live in `pages/<component-name>/`. They are used for local development, integration tests, and visual regression tests.
4+
5+
## Rules
6+
7+
- Export a default function component
8+
- Import components via `~components/<name>` (not relative paths to `src/`)
9+
- For visual regression content, either use `SimplePage` from `pages/app/templates` (handles heading, screenshot area, i18n, and layout) or wrap content in `ScreenshotArea` from `pages/utils/screenshot-area` with a manual `<h1>`
10+
- Use `createPermutations` and `PermutationsView` from `pages/utils/` for permutation pages
11+
- If multiple pages share data (like `i18nStrings`), put it in a `common.tsx` in the same directory

docs/INTERNALS.md

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
# Internal Utilities
2+
3+
Shared infrastructure lives in `src/internal/`.
4+
5+
## What's in there
6+
7+
- `hooks/` — shared React hooks (component telemetry, controllable state, focus management, container/element queries, visual mode detection, intersection observers, debounce/throttle, etc.)
8+
- `components/` — shared internal UI building blocks (dropdowns, options, focus locks, tooltips, chart primitives, transitions, screen-reader utilities, drag handles, etc.)
9+
- `context/` — React contexts for cross-component communication (form fields, modals, split panels, container headers, etc.)
10+
- `utils/` — pure helper functions (DOM helpers, key handling, date/time, locale, display names, prop stripping, etc.)
11+
- `events/` — event handler type definitions used by all component `on*` props
12+
- `base-component/` — base prop extraction utilities
13+
- `styles/` — shared SCSS mixins
14+
- `analytics/` — telemetry and funnel metrics
15+
16+
Always check `src/internal/` before introducing new utilities, hooks, or shared components.

docs/STYLING.md

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
# Styling
2+
3+
Never hardcode CSS spacing, colors, borders, shadows, typography, or motion values. This project uses design tokens and custom CSS properties.
4+
5+
## Design Tokens
6+
7+
Tokens are defined in `style-dictionary/` and consumed in SCSS via the `awsui` namespace.
8+
9+
## Custom CSS Properties
10+
11+
Custom CSS properties are defined in `build-tools/utils/custom-css-properties.js`. Read this file to see what's available.
12+
13+
## Rules
14+
15+
- Apply `styles-reset` mixin on every root element — prevents parent styles from leaking in
16+
- Root elements must not have outer margins — spacing is managed by parent components
17+
- No descendant combinators (`.a .b` with a space) — breaks CSS scoping
18+
- Wrap all animations in the `with-motion` mixin — ensures motion can be toggled
19+
- Use logical properties only — no `left`/`right`/`top`/`bottom`/`width`/`height` in CSS. Use `inline-start`/`inline-end`/`block-start`/`block-end`/`inline-size`/`block-size` instead. This is required for RTL support.
20+
21+
## RTL Support
22+
23+
For bidirectional layout support, use the internal RTL utilities in `src/internal/`:
24+
25+
- SCSS: `with-direction` mixin for direction-aware styles
26+
- JS: `getIsRtl` for detecting direction, `handleKey` for direction-aware key handling, `getLogicalBoundingClientRect` / `getOffsetInlineStart` / `getScrollInlineStart` for direction-aware measurements

docs/TESTING.md

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
# Testing
2+
3+
## Quick Reference
4+
5+
```
6+
npm test # all tests (unit + integ + a11y)
7+
npm run test:unit # unit + build-tool tests
8+
npm run test:integ # integration tests (starts dev server automatically)
9+
npm run test:motion # motion tests (starts dev server automatically)
10+
npm run test:a11y # accessibility tests
11+
```
12+
13+
The npm scripts use gulp tasks that handle env vars (`TZ=UTC`, `NODE_OPTIONS=--experimental-vm-modules`) and dev server lifecycle automatically.
14+
15+
## Targeting Specific Files
16+
17+
For running a specific test file or folder, call jest directly with the appropriate config:
18+
19+
```
20+
# Unit
21+
TZ=UTC node_modules/.bin/jest -c jest.unit.config.js src/button/__tests__/button.test.tsx
22+
23+
# Integration (requires dev server running via `npm start`)
24+
NODE_OPTIONS=--experimental-vm-modules node_modules/.bin/jest -c jest.integ.config.js src/input/__integ__/
25+
26+
# Motion (requires dev server running via `npm start`)
27+
NODE_OPTIONS=--experimental-vm-modules node_modules/.bin/jest -c jest.motion.config.js src/flashbar/__motion__/
28+
29+
# Build-tool / stylelint
30+
NODE_OPTIONS=--experimental-vm-modules node_modules/.bin/jest -c jest.build-tools.config.js build-tools/stylelint
31+
```
32+
33+
## Updating Snapshots
34+
35+
```
36+
TZ=UTC node_modules/.bin/jest -u -c jest.unit.config.js src/__tests__/snapshot-tests/
37+
```

docs/WRITING_TESTS.md

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
# Writing Tests
2+
3+
## Test Utils
4+
5+
Use the project's test utils in `src/test-utils/` — don't query the DOM directly.
6+
7+
- `src/test-utils/dom/` — unit test wrappers (JSDOM)
8+
- `src/test-utils/selectors/` — integration test wrappers (real browser)
9+
10+
Read the wrapper for the component you're testing to see available `find*` methods.
11+
12+
### Authoring Test Utils
13+
14+
Each wrapper extends `ComponentWrapper`, has a static `rootSelector`, and explicit return types on all methods. Test-util CSS classes go in `src/<component-name>/test-classes/styles.scss`. Read existing wrappers for the pattern.
15+
16+
## Unit Tests
17+
18+
Use `react-testing-library` to render, combined with test-utils. Prefer test-utils for public interactions, react-testing-library for internal corner cases. Read an existing test file for the setup pattern.
19+
20+
## Integration Tests
21+
22+
Use `useBrowser` from `@amzn/awsui-browser-test-tools/use-browser`. Use a `setupTest` wrapper with `waitForVisible`. Don't wait on tag name selectors — they're visible before JS loads. Multiple assertions per test are fine (e2e tests are slow). Use page object pattern for files with many tests.
23+
24+
## I18n Testing
25+
26+
Test `useInternalI18n` with `TestI18nProvider` from `src/i18n/testing`. Read existing i18n tests for the pattern.
27+
28+
## Gotchas
29+
30+
- `findAll`/`findAllByClassName` with `.get()` uses `:nth-child()` — only works if items share the same parent node
31+
- All dev pages are axe-checked automatically. A11y violations fail the build. Checks run in dark mode only.

0 commit comments

Comments
 (0)