@astryxdesign/core 0.6.3-canary.ea2f048 → 0.6.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,215 +0,0 @@
1
- ---
2
- schema_version: 3
3
- template_version: 5
4
- kind: component
5
- id: component:Timer
6
- authority: current
7
- archive_reason: null
8
- superseded_by: null
9
- approved_by: cixzhang
10
- approved_at: 2026-09-22
11
- owners: [cixzhang]
12
- review_triggers: [public-api, behavior, theming, accessibility, react-runtime]
13
- verified_by:
14
- [
15
- packages/core/src/Timer/Timer.test.tsx,
16
- packages/core/src/theme/themingTargets.test.ts,
17
- scripts/check-knowledge.mjs,
18
- ]
19
- modules: []
20
- families: []
21
- design_specs: []
22
- architecture:
23
- [
24
- architecture:public-component-api,
25
- architecture:component-theming-surface,
26
- architecture:react-component-runtime,
27
- ]
28
- contributing: []
29
- system_specs:
30
- [
31
- spec:AST-002/DEC-1,
32
- spec:AST-037/DEC-1,
33
- spec:AST-037/DEC-2,
34
- spec:AST-037/DEC-3,
35
- ]
36
- ---
37
-
38
- # Timer component contract
39
-
40
- ## Contract at a glance
41
-
42
- | Area | Contract |
43
- | ----------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
44
- | Public contract | `Timer`, `TimerProps`, `TimerFormat`, optional `startTime` Unix milliseconds, `elapsed` or `clock` format, Timestamp-equivalent `type`, `size`, `color`, and `weight`, `<time>` ref, and `BaseProps<HTMLTimeElement>`. |
45
- | Behavior | One semantic duration uses a standardized seconds-to-hours ladder and updates its owned DOM node without React tick renders; elapsed output drops to minute cadence after one hour. |
46
- | End-user impact | People watching active work see a stable, consistent duration without unnecessary timer work competing with the surrounding interface. |
47
- | Builder impact | Zero-config starts on mount with Timestamp's supporting typography; callers choose only an earlier origin, standard format, or standard typography override. |
48
- | Compatibility/readiness | Additive first release implementing current `spec:AST-037`; no existing API or behavior changes. |
49
- | Review checks | Reject custom formatters/cadence, state-driven ticks, callback-count drift, post-hour elapsed second wakes, typography divergence from Timestamp, leaked resources, negative output, lost passthrough/ref behavior, unsolicited live announcements, or extra anatomy/targets. |
50
- | Governing rules | `spec:AST-037`; `architecture:public-component-api`; `architecture:react-component-runtime`; `architecture:component-theming-surface`. |
51
-
52
- This table is a review projection; the body below is authoritative.
53
-
54
- ## Intent
55
-
56
- Timer is the stable Core projection of `spec:AST-037`. It presents a standardized
57
- elapsed duration for active work while keeping clock ticks outside React's render
58
- lifecycle. Its typography surface and defaults match Timestamp so the two temporal
59
- content components behave consistently.
60
-
61
- ## Compatibility and migration
62
-
63
- - Released default preserved: `not yet released`
64
- - Compatibility class: additive component and type exports
65
- - Controlled/uncontrolled behavior: not applicable
66
- - Migration decision: `spec:AST-037/DEC-1`, `spec:AST-037/DEC-2`, and
67
- `spec:AST-037/DEC-3`
68
-
69
- Consumer migration instructions belong in consumer docs and release notes.
70
-
71
- ## Ownership boundary
72
-
73
- **Owns**
74
-
75
- - Elapsed calculation from mount or a finite caller origin.
76
- - The `elapsed` and `clock` representation ladders and their visible precision.
77
- - One `<time>` element, its visible value, synchronized ISO duration, and timer
78
- resource lifecycle.
79
- - Avoiding React update commits for clock ticks.
80
- - Timestamp-equivalent `type`, `size`, `color`, and `weight` behavior.
81
- - The `timer` theming target on the Text wrapper.
82
-
83
- **Does not own / non-goals**
84
-
85
- - Loading indicators, waiting copy, status, or visibility — product composition.
86
- - Dates, relative calendar language, time zones, or absolute instants — Timestamp.
87
- - Pause, resume, countdown, deadlines, alarms, laps, sub-second precision, custom
88
- formatters, or caller-controlled scheduling cadence.
89
- - Automatic live-region announcements.
90
-
91
- Countdown is deferred to a later contract. The standard formatting and scheduling
92
- helpers remain direction-independent so that extension does not require replacing
93
- the current format API.
94
-
95
- ## Public concepts
96
-
97
- | Concept | Closed values or states | Meaning | Availability | Default | Owner | Stability | Invalid-value behavior |
98
- | --------------- | ----------------------------------------- | ---------------------------------------------------- | ------------ | ------------------------------------------------------------------------------ | ----------------- | --------- | ---------------------------------------------------------- |
99
- | Elapsed origin | Mount time or finite `startTime` | Unix-millisecond origin for elapsed duration | Always | Mount time | `component:Timer` | Stable | Non-finite values fall back to mount time |
100
- | Duration format | `elapsed`, `clock` | Compact units or stopwatch notation | Always | `elapsed` | `component:Timer` | Stable | Types reject other values; runtime falls back to `elapsed` |
101
- | Typography | `type`, `size`, `color`, `weight` | Same Text-backed surface and resolution as Timestamp | Always | Timestamp defaults: supporting type, secondary color, type-derived size/weight | Timestamp/Text | Stable | Existing Text type behavior |
102
- | Time surface | `<time>` with visible text and `dateTime` | Semantic elapsed duration and time-element props/ref | Always | Selected format's zero value and `PT0S` before client synchronization | `component:Timer` | Stable | Timer-owned `dateTime` wins |
103
-
104
- ## Behavioral and layout contract
105
-
106
- | ID | Candidate invariant | Basis | Draft review state |
107
- | ---- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ---------------------------- | ------------------ |
108
- | FR1 | Timer MUST render one `<time>` element with selected-format text and matching non-negative ISO 8601 duration. | `spec:AST-037` FR1, FR3, FR5 | Settled |
109
- | FR2 | Omitted or non-finite `startTime` MUST use the mount origin; a finite value MUST use that caller origin. | `spec:AST-037` FR2 | Settled |
110
- | FR3 | Ticks MUST recompute from the clock and origin, directly update the owned node, and produce zero React update commits. | `spec:AST-037` FR3–FR4 | Settled |
111
- | FR4 | Prop changes MUST take effect without remounting or duplicate resources; every setup MUST clean up its resource. | `spec:AST-037` FR6–FR7 | Settled |
112
- | FR5 | `type`, `size`, `color`, `weight`, `xstyle`, `className`, and `style` MUST resolve on the Text wrapper exactly as Timestamp does; other admitted DOM, data, ARIA, and event props and the ref MUST reach `<time>`. | `spec:AST-037` FR8 | Settled |
113
- | FR6 | Timer MUST NOT add live-region semantics by default. | `spec:AST-037` FR9 | Settled |
114
- | FR7 | The Text wrapper MUST carry exactly the `timer` target for this component. | `spec:AST-037` FR10 | Settled |
115
- | FR8 | Initial markup MUST use the selected format's zero value and `PT0S` without exposing a clock read in rendered markup. | `spec:AST-037` FR11 | Settled |
116
- | FR9 | `elapsed` and `clock` MUST update on second boundaries below one hour; `elapsed` MUST update on minute boundaries at or above one hour while `clock` remains second-precise. A future origin MUST schedule toward its first visible change rather than waking each second at zero. | `spec:AST-037` FR12 | Settled |
117
- | FR10 | Timer SHOULD skip DOM writes while the represented text and duration are unchanged. | `spec:AST-037` FR13 | Settled |
118
-
119
- ### Allowed variation
120
-
121
- - **AV1 — Scheduling mechanism.** The private browser scheduling mechanism may
122
- change while format-aware cadence, clock derivation, no-render ticks, and
123
- complete cleanup remain true.
124
- - **AV2 — Composition.** Callers may use the supported typography and styling
125
- inputs without changing timing behavior.
126
-
127
- ### Representative states
128
-
129
- | State | Required invariant | Allowed variation |
130
- | ---------------- | -------------------------------------------------------------- | --------------------------------------- |
131
- | Initial elapsed | `0s` and `PT0S` on one `<time>` | Root props and styling |
132
- | Initial clock | `0:00` and `PT0S` on one `<time>` | Root props and styling |
133
- | Seconds/minutes | `34s`, `2m 08s`, `0:34`, or `2:08` with whole-second semantics | Finite elapsed value |
134
- | Hour-scale | `1h 02m` at minute cadence or `1:02:33` at second cadence | Format |
135
- | Delayed callback | Catch up to clock without accumulated drift | Delay length |
136
- | Prop update | New origin or format applies on the same `<time>` | Parent render cause |
137
- | Replay/unmount | Each acquired resource is released | Development replay count |
138
- | Typography | Timestamp defaults or explicit Text-family overrides | Supported type, size, color, and weight |
139
-
140
- ### Transformation and precedence order
141
-
142
- - **ORD1 — Resolve → calculate → clamp → floor to visible precision → format →
143
- write → schedule next visible boundary.** Apply the pipeline from `spec:AST-037`
144
- to visible text and machine-readable duration.
145
- - **ORD2 — Timestamp styling split.** Typography, `xstyle`, `className`, `style`,
146
- and the `timer` target compose on the Text wrapper. Time-element props and the ref
147
- compose on `<time>`; Timer owns `dateTime`.
148
-
149
- ### Performance and resources
150
-
151
- - **PR1 — No tick renders.** Advancing time produces zero React update commits.
152
- - **PR2 — One resource.** Each mounted Timer owns at most one active timer resource,
153
- and each setup cleanup releases its resource.
154
- - **PR3 — Visible cadence.** Elapsed output at or above one hour does not wake for
155
- hidden second changes; clock output remains second-precise.
156
- - **PR4 — Bounded writes.** Unchanged represented text and duration are not rewritten.
157
-
158
- ## Accessibility contract
159
-
160
- - **AR1 — Semantic duration.** The `<time>` element exposes the current non-negative
161
- ISO 8601 duration at the same precision as its visible output.
162
- - **AR2 — Quiet by default.** No role or `aria-live` value is added automatically;
163
- deliberate caller ARIA passes through.
164
- - **AR3 — Perceivable text.** The formatted duration remains real text content.
165
-
166
- ## Design relationships
167
-
168
- | Anatomy or state | Design requirement | Representation authority | Hierarchy role | Component contract |
169
- | ---------------- | ------------------------------------------------------------------------------------------------------------------ | ------------------------------------------ | -------------- | ----------------------- |
170
- | Elapsed time | One stable inline duration with Timestamp-equivalent supporting typography by default and standard Text overrides. | `spec:AST-037/DEC-1`, `spec:AST-037/DEC-3` | Supporting | FR1, FR3, FR5, AR1, AR3 |
171
-
172
- ### Theming anatomy
173
-
174
- <!-- anatomy-theming:v1 -->
175
-
176
- ```json
177
- {
178
- "Elapsed time": {"target": "timer"}
179
- }
180
- ```
181
-
182
- ## Family and system relationships
183
-
184
- - Timer and Timestamp are temporal Text-family content components: Timer owns
185
- durations; Timestamp owns instants. Their typography API and defaults match.
186
- - `spec:AST-037` owns the public behavior, API, accessibility, performance, and
187
- first-Core-admission decisions projected here.
188
- - `architecture:public-component-api` owns exports, BaseProps, styling, ref, and
189
- caller-choice rules.
190
- - `architecture:react-component-runtime` owns Effect and resource lifecycle.
191
- - `architecture:component-theming-surface` owns target qualification.
192
-
193
- ## Verification map
194
-
195
- | Contract | Verification | Representative states | Mutation or failure expectation | Audit section |
196
- | --------------------------- | -------------------------------------------------------------------------------- | ---------------------------------------------------------------------------------------------------------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | --------------------------- |
197
- | FR1–FR4, FR8–FR10, AR1, AR3 | `Timer.test.tsx` controlled-clock tests | Initial formats, origin variants including future scheduling, delayed callback, format change, second/minute/hour boundaries | State ticks, callback accumulation, wrong ladder/padding, negative values, needless pre-origin wakes, stale semantics, wrong cadence, or clock-derived initial markup fail | `audit:Timer/behavior` |
198
- | FR3, PR1 | React Profiler commit-count test | Several ticks | A state-based implementation adds update commits and fails | `audit:Timer/performance` |
199
- | FR4, PR2 | Resource spies under rerender, StrictMode, and unmount | Setup, dependency change, replay, cleanup | Duplicate or leaked resources fail counts | `audit:Timer/resources` |
200
- | FR5 | Public import, Timestamp-default typography, overrides, BaseProps, and ref tests | Default and explicit typography, ref, event, ARIA, class, style | Missing export, styling divergence, or dropped input fails | `audit:Timer/api` |
201
- | FR6, AR2 | Accessibility attribute tests | Default and deliberate caller ARIA | Unsolicited live semantics or dropped ARIA fails | `audit:Timer/accessibility` |
202
- | FR7 | `themingTargets.test.ts` and `scripts/check-knowledge.mjs` | One wrapper target | Missing, extra, or misplaced target fails | `audit:Timer/theming` |
203
-
204
- ## Decision log
205
-
206
- No additional decision. This component projects `spec:AST-037` without widening it.
207
-
208
- ## Open questions
209
-
210
- None.
211
-
212
- ## Content boundary
213
-
214
- This file does not duplicate consumer examples, implementation code, private
215
- scheduling mechanics, measurements, or system rules. It links to their owners.
@@ -1,302 +0,0 @@
1
- // Copyright (c) Meta Platforms, Inc. and affiliates.
2
-
3
- /**
4
- * @file Timer.test.tsx
5
- * @input Uses React Testing Library, fake clocks, React Profiler, and Timer
6
- * @output Verifies formats, adaptive cadence, render isolation, typography, resources, semantics, and passthrough
7
- */
8
-
9
- import {Profiler, StrictMode, createRef} from 'react';
10
- import {renderToString} from 'react-dom/server';
11
- import {act, fireEvent, render, screen} from '@testing-library/react';
12
- import {afterEach, beforeEach, describe, expect, it, vi} from 'vitest';
13
- import {Timer} from './Timer';
14
-
15
- describe('Timer', () => {
16
- beforeEach(() => {
17
- vi.useFakeTimers();
18
- vi.setSystemTime(new Date('2026-09-22T00:00:00Z'));
19
- });
20
-
21
- afterEach(() => {
22
- vi.useRealTimers();
23
- vi.restoreAllMocks();
24
- });
25
-
26
- it('renders deterministic zero-duration markup for each standard format', () => {
27
- const {rerender} = render(<Timer data-testid="timer" />);
28
- const timer = screen.getByTestId('timer');
29
-
30
- expect(timer.tagName).toBe('TIME');
31
- expect(timer).toHaveTextContent('0s');
32
- expect(timer).toHaveAttribute('datetime', 'PT0S');
33
-
34
- rerender(<Timer format="clock" data-testid="timer" />);
35
- expect(timer).toHaveTextContent('0:00');
36
- expect(timer).toHaveAttribute('datetime', 'PT0S');
37
- });
38
-
39
- it('keeps server markup independent of the clock', () => {
40
- const firstMarkup = renderToString(<Timer startTime={0} />);
41
- const firstClockMarkup = renderToString(
42
- <Timer startTime={0} format="clock" />,
43
- );
44
-
45
- vi.setSystemTime(new Date('2030-01-01T00:00:00Z'));
46
- const secondMarkup = renderToString(<Timer startTime={0} />);
47
- const secondClockMarkup = renderToString(
48
- <Timer startTime={0} format="clock" />,
49
- );
50
-
51
- expect(firstMarkup).toBe(secondMarkup);
52
- expect(firstMarkup).toContain('dateTime="PT0S"');
53
- expect(firstMarkup).toContain('>0s</time>');
54
- expect(firstClockMarkup).toBe(secondClockMarkup);
55
- expect(firstClockMarkup).toContain('>0:00</time>');
56
- });
57
-
58
- it('derives elapsed time from the clock without accumulating callback count', () => {
59
- let scheduledTick: (() => void) | undefined;
60
- vi.spyOn(globalThis, 'setTimeout').mockImplementation(callback => {
61
- scheduledTick = callback as () => void;
62
- return 1 as unknown as ReturnType<typeof setTimeout>;
63
- });
64
-
65
- render(<Timer data-testid="timer" />);
66
-
67
- vi.setSystemTime(new Date('2026-09-22T00:00:08.750Z'));
68
- act(() => {
69
- scheduledTick?.();
70
- });
71
-
72
- const timer = screen.getByTestId('timer');
73
- expect(timer).toHaveTextContent('8s');
74
- expect(timer).toHaveAttribute('datetime', 'PT8S');
75
- });
76
-
77
- it('formats elapsed durations across seconds, minutes, and hours', () => {
78
- const now = Date.now();
79
- const {rerender} = render(
80
- <Timer startTime={now - 34_000} data-testid="timer" />,
81
- );
82
- const timer = screen.getByTestId('timer');
83
- expect(timer).toHaveTextContent('34s');
84
- expect(timer).toHaveAttribute('datetime', 'PT34S');
85
-
86
- rerender(<Timer startTime={now - 128_000} data-testid="timer" />);
87
- expect(timer).toHaveTextContent('2m 08s');
88
- expect(timer).toHaveAttribute('datetime', 'PT128S');
89
-
90
- rerender(<Timer startTime={now - 3_753_000} data-testid="timer" />);
91
- expect(timer).toHaveTextContent('1h 02m');
92
- expect(timer).toHaveAttribute('datetime', 'PT3720S');
93
- });
94
-
95
- it('formats clock durations across minutes and hours', () => {
96
- const now = Date.now();
97
- const {rerender} = render(
98
- <Timer format="clock" startTime={now - 128_000} data-testid="timer" />,
99
- );
100
- const timer = screen.getByTestId('timer');
101
- expect(timer).toHaveTextContent('2:08');
102
- expect(timer).toHaveAttribute('datetime', 'PT128S');
103
-
104
- rerender(
105
- <Timer format="clock" startTime={now - 3_753_000} data-testid="timer" />,
106
- );
107
- expect(timer).toHaveTextContent('1:02:33');
108
- expect(timer).toHaveAttribute('datetime', 'PT3753S');
109
- });
110
-
111
- it('uses second cadence until elapsed format reaches an hour, then minute cadence', () => {
112
- const setTimeoutSpy = vi.spyOn(globalThis, 'setTimeout');
113
- const startTime = Date.now() - 3_599_000;
114
- render(<Timer startTime={startTime} data-testid="timer" />);
115
- const timer = screen.getByTestId('timer');
116
-
117
- expect(timer).toHaveTextContent('59m 59s');
118
- expect(setTimeoutSpy).toHaveBeenLastCalledWith(expect.any(Function), 1000);
119
-
120
- act(() => {
121
- vi.advanceTimersByTime(1000);
122
- });
123
- expect(timer).toHaveTextContent('1h 00m');
124
- expect(timer).toHaveAttribute('datetime', 'PT3600S');
125
- expect(setTimeoutSpy).toHaveBeenLastCalledWith(
126
- expect.any(Function),
127
- 60_000,
128
- );
129
- });
130
-
131
- it('keeps clock format on second cadence after an hour', () => {
132
- const setTimeoutSpy = vi.spyOn(globalThis, 'setTimeout');
133
- render(
134
- <Timer
135
- format="clock"
136
- startTime={Date.now() - 3_723_000}
137
- data-testid="timer"
138
- />,
139
- );
140
-
141
- expect(screen.getByTestId('timer')).toHaveTextContent('1:02:03');
142
- expect(setTimeoutSpy).toHaveBeenLastCalledWith(expect.any(Function), 1000);
143
- });
144
-
145
- it('counts from a finite caller-provided start time', () => {
146
- const now = Date.now();
147
- render(<Timer startTime={now - 12_400} data-testid="timer" />);
148
-
149
- expect(screen.getByTestId('timer')).toHaveTextContent('12s');
150
- expect(screen.getByTestId('timer')).toHaveAttribute('datetime', 'PT12S');
151
- });
152
-
153
- it('returns to the original mount origin when startTime is removed', () => {
154
- const mountedAt = Date.now();
155
- const {rerender} = render(
156
- <Timer startTime={mountedAt - 10_000} data-testid="timer" />,
157
- );
158
-
159
- act(() => {
160
- vi.advanceTimersByTime(2000);
161
- });
162
- rerender(<Timer data-testid="timer" />);
163
-
164
- expect(screen.getByTestId('timer')).toHaveTextContent('2s');
165
- expect(screen.getByTestId('timer')).toHaveAttribute('datetime', 'PT2S');
166
- });
167
-
168
- it('falls back to mount time for a non-finite start time', () => {
169
- render(<Timer startTime={Number.NaN} data-testid="timer" />);
170
-
171
- act(() => {
172
- vi.advanceTimersByTime(2000);
173
- });
174
-
175
- expect(screen.getByTestId('timer')).toHaveTextContent('2s');
176
- });
177
-
178
- it('clamps a future origin to zero and schedules its first visible change directly', () => {
179
- const setTimeoutSpy = vi.spyOn(globalThis, 'setTimeout');
180
- render(<Timer startTime={Date.now() + 5000} data-testid="timer" />);
181
-
182
- expect(screen.getByTestId('timer')).toHaveTextContent('0s');
183
- expect(screen.getByTestId('timer')).toHaveAttribute('datetime', 'PT0S');
184
- expect(setTimeoutSpy).toHaveBeenLastCalledWith(expect.any(Function), 6000);
185
-
186
- act(() => {
187
- vi.advanceTimersByTime(6000);
188
- });
189
-
190
- expect(screen.getByTestId('timer')).toHaveTextContent('1s');
191
- expect(screen.getByTestId('timer')).toHaveAttribute('datetime', 'PT1S');
192
- });
193
-
194
- it('updates format without remounting or losing current elapsed time', () => {
195
- const now = Date.now();
196
- const {rerender} = render(
197
- <Timer startTime={now - 3_723_000} data-testid="timer" />,
198
- );
199
- const timer = screen.getByTestId('timer');
200
- expect(timer).toHaveTextContent('1h 02m');
201
- expect(timer).toHaveAttribute('datetime', 'PT3720S');
202
-
203
- rerender(
204
- <Timer format="clock" startTime={now - 3_723_000} data-testid="timer" />,
205
- );
206
- expect(screen.getByTestId('timer')).toBe(timer);
207
- expect(timer).toHaveTextContent('1:02:03');
208
- expect(timer).toHaveAttribute('datetime', 'PT3723S');
209
- });
210
-
211
- it('does not schedule React update commits as time advances', () => {
212
- const onRender = vi.fn();
213
- render(
214
- <Profiler id="timer" onRender={onRender}>
215
- <Timer />
216
- </Profiler>,
217
- );
218
- expect(onRender).toHaveBeenCalledTimes(1);
219
-
220
- act(() => {
221
- vi.advanceTimersByTime(5000);
222
- });
223
-
224
- expect(onRender).toHaveBeenCalledTimes(1);
225
- });
226
-
227
- it('owns one timer resource and cleans up under StrictMode replay', () => {
228
- const setTimeoutSpy = vi.spyOn(window, 'setTimeout');
229
- const clearTimeoutSpy = vi.spyOn(window, 'clearTimeout');
230
- const {unmount} = render(
231
- <StrictMode>
232
- <Timer />
233
- </StrictMode>,
234
- );
235
-
236
- expect(setTimeoutSpy).toHaveBeenCalledTimes(2);
237
- expect(clearTimeoutSpy).toHaveBeenCalledTimes(1);
238
-
239
- unmount();
240
- expect(clearTimeoutSpy).toHaveBeenCalledTimes(2);
241
- });
242
-
243
- it('matches Timestamp typography defaults and accepts overrides', () => {
244
- const {rerender} = render(<Timer data-testid="timer" />);
245
- const timer = screen.getByTestId('timer');
246
- const text = timer.parentElement;
247
-
248
- expect(text).toHaveClass('astryx-text');
249
- expect(text).toHaveClass('astryx-timer');
250
- expect(text).toHaveAttribute('data-type', 'supporting');
251
- expect(text).toHaveAttribute('data-color', 'secondary');
252
-
253
- rerender(
254
- <Timer
255
- type="body"
256
- size="lg"
257
- color="primary"
258
- weight="bold"
259
- data-testid="timer"
260
- />,
261
- );
262
- expect(text).toHaveAttribute('data-type', 'body');
263
- expect(text).toHaveAttribute('data-size', 'lg');
264
- expect(text).toHaveAttribute('data-color', 'primary');
265
- });
266
-
267
- it('forwards its time ref and preserves Timestamp-style root styling and time props', () => {
268
- const ref = createRef<HTMLTimeElement>();
269
- const onClick = vi.fn();
270
- render(
271
- <Timer
272
- ref={ref}
273
- id="elapsed"
274
- className="custom-class"
275
- style={{color: 'rgb(1, 2, 3)'}}
276
- aria-live="polite"
277
- onClick={onClick}
278
- data-testid="timer"
279
- />,
280
- );
281
-
282
- const timer = screen.getByTestId('timer');
283
- const text = timer.parentElement;
284
- expect(ref.current).toBe(timer);
285
- expect(timer).toHaveAttribute('id', 'elapsed');
286
- expect(text).toHaveClass('astryx-timer');
287
- expect(text).toHaveClass('custom-class');
288
- expect(text).toHaveStyle({color: 'rgb(1, 2, 3)'});
289
- expect(timer).toHaveAttribute('aria-live', 'polite');
290
-
291
- fireEvent.click(timer);
292
- expect(onClick).toHaveBeenCalledTimes(1);
293
- });
294
-
295
- it('does not add live-region semantics by default', () => {
296
- render(<Timer data-testid="timer" />);
297
- const timer = screen.getByTestId('timer');
298
-
299
- expect(timer).not.toHaveAttribute('aria-live');
300
- expect(timer).not.toHaveAttribute('role');
301
- });
302
- });