Skip to content

Commit b3966fd

Browse files
committed
Refactor Avatar component to use Astro Image component
1 parent 6e7e798 commit b3966fd

4 files changed

Lines changed: 167 additions & 10 deletions

File tree

‎.vscode/settings.json‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939
"shiki",
4040
"shipit",
4141
"signup",
42+
"Southam",
4243
"spriter",
4344
"squoosh",
4445
"tanabata",

‎src/components/Avatar/index.astro‎

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@
1111
* <Avatar name="Chris Southam" class="custom-class" />
1212
* ```
1313
*/
14-
// eslint-disable-next-line import/no-unresolved
14+
15+
import { Image } from 'astro:assets'
1516
import { getAvatarImage } from './avatars.ts'
1617
1718
export interface Props {
@@ -51,8 +52,8 @@ const fallbackInitial = name.charAt(0).toUpperCase()
5152

5253
<div class:list={['avatar-container', className]}>
5354
{avatarImage ? (
54-
<img
55-
src={avatarImage.src}
55+
<Image
56+
src={avatarImage}
5657
alt={avatarAlt}
5758
loading="lazy"
5859
class="avatar-image"

‎src/lib/markdown/README.md‎

Lines changed: 37 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
Components intended for use in *.mdx files:
2+
3+
* Avatar
4+
15
/**
26
* Add accessible name to section in footnotes plugin
37
*/
@@ -303,11 +307,37 @@ export function myAccessibleListPlugin() {
303307
└─────────────────────────────────────────────────┘
304308
↓
305309
┌─────────────────────────────────────────────────┐
306-
│ Layer 4: E2E Tests (Build Output) │
307-
│ • Test actual built pages in browser │
308-
│ • Real-world rendering validation │
309-
│ • Purpose: Validate production behavior │
310-
│ • Speed: Minutes │
311-
│ • Run: CI/CD only │
312-
│ • Tools: Playwright │
310+
│ Layer 4: E2E Component Rendering Tests │
311+
│ • Test markdown rendering through Astro │
312+
│ • Component-based validation with fixtures │
313+
│ • Purpose: E2E validation with accessibility │
314+
│ • Speed: Seconds │
315+
│ • Run: Before commits / CI │
316+
│ • Tools: Vitest + Testing Library + Axe │
317+
│ │
318+
│ Test Architecture: │
319+
│ • Fixtures → Test Component (Astro) → │
320+
│ Full Pipeline → HTML → Accessibility Check │
321+
│ │
322+
│ Test Component (src/components/Test): │
323+
│ • Accepts markdown content as prop │
324+
│ • Processes through production pipeline │
325+
│ • Returns rendered HTML │
326+
│ │
327+
│ Accessibility Testing (vitest-axe): │
328+
│ ✅ Every test validates with Axe library │
329+
│ ✅ Ensures WCAG compliance │
330+
│ ✅ Validates ARIA attributes │
331+
│ ✅ Checks semantic HTML structure │
332+
│ │
333+
│ Test Coverage (11 tests): │
334+
│ • Abbreviations with accessibility │
335+
│ • Custom attributes on elements │
336+
│ • Blockquote attributions semantic HTML │
337+
│ • Emojis with ARIA attributes │
338+
│ • Full pipeline integration (3 tests) │
339+
│ • Accessibility compliance (4 tests) │
340+
│ │
341+
│ Example: markdown-rendering.spec.tsx │
342+
│ Run: npx vitest run src/lib/markdown/__tests__/e2e/
313343
└─────────────────────────────────────────────────┘
Lines changed: 125 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,125 @@
1+
# Layer 4: E2E Markdown Rendering Tests
2+
3+
## Overview
4+
5+
Layer 4 provides end-to-end testing of markdown rendering through the complete Astro pipeline with comprehensive accessibility validation using the Axe library.
6+
7+
## Architecture
8+
9+
```bash
10+
Markdown Fixtures
11+
↓
12+
Test Component (Astro)
13+
↓
14+
Full Markdown Pipeline
15+
↓
16+
Rendered HTML
17+
↓
18+
Testing Library + Axe Validation
19+
```
20+
21+
## Test Component
22+
23+
Located at `src/components/Test/index.astro`, this component:
24+
25+
- Accepts markdown content as a prop
26+
- Processes through the production-identical plugin pipeline
27+
- Returns rendered HTML for testing
28+
29+
## Test Strategy
30+
31+
### Fixtures (`__fixtures__/markdown/`)
32+
33+
Five comprehensive fixtures testing different features:
34+
35+
1. **abbreviations.md** - Tests MDAST abbreviation plugin
36+
2. **attributes.md** - Tests remark-attr custom classes
37+
3. **attribution.md** - Tests blockquote attributions with figure/figcaption
38+
4. **emoji.md** - Tests emoji shortcodes with accessibility
39+
5. **full-pipeline.md** - Tests all features working together
40+
41+
### Test Coverage (11 tests)
42+
43+
#### Feature Tests (4)
44+
45+
- ✅ Abbreviations with proper HTML and accessibility
46+
- ✅ Custom attributes on elements
47+
- ✅ Blockquote attributions with semantic HTML
48+
- ✅ Emojis with accessibility attributes
49+
50+
#### Integration Tests (3)
51+
52+
- ✅ All features together with proper semantics
53+
- ✅ Valid semantic HTML structure
54+
- ✅ Complex markdown with GFM features
55+
56+
#### Accessibility Tests (4)
57+
58+
- ✅ Abbreviations have title attributes
59+
- ✅ Emojis have proper ARIA attributes
60+
- ✅ Heading anchor links are accessible
61+
- ✅ Blockquote attributions use semantic HTML
62+
63+
## Accessibility Validation
64+
65+
Every test includes accessibility validation using `vitest-axe`:
66+
67+
```typescript
68+
const results = await axe(container)
69+
expect(results).toHaveNoViolations()
70+
```
71+
72+
This ensures:
73+
74+
- WCAG compliance
75+
- Proper ARIA attributes
76+
- Semantic HTML structure
77+
- Screen reader compatibility
78+
79+
## Running Tests
80+
81+
```bash
82+
# Run Layer 4 E2E tests only
83+
npx vitest run src/lib/markdown/__tests__/e2e/
84+
85+
# Run all markdown tests (all 4 layers)
86+
npx vitest run src/lib/markdown/__tests__/
87+
88+
# Run with watch mode
89+
npx vitest watch src/lib/markdown/__tests__/e2e/
90+
```
91+
92+
## Key Features
93+
94+
### No Snapshots
95+
96+
Tests use explicit assertions instead of snapshots for better maintainability and clearer test failures.
97+
98+
### Production Pipeline
99+
100+
Uses the exact same plugin configuration as production to ensure accurate E2E validation.
101+
102+
### Accessibility First
103+
104+
Every test validates accessibility with Axe, ensuring WCAG compliance is maintained.
105+
106+
### Preact Integration
107+
108+
Uses `@testing-library/preact` (not React) to match the project's Preact configuration.
109+
110+
## Test Statistics
111+
112+
- **Total Tests**: 146 across all 4 layers
113+
- Layer 1 (Isolated): 119 tests
114+
- Layer 2 (Astro Pipeline): 57 tests
115+
- Layer 3 (Full Integration): 10 tests
116+
- Layer 4 (E2E + Accessibility): 11 tests
117+
118+
## Dependencies
119+
120+
- `vitest` - Test runner
121+
- `@testing-library/preact` - Component rendering
122+
- `vitest-axe` - Accessibility testing
123+
- `jsdom` - DOM environment
124+
125+
All dependencies were already present in the project.

0 commit comments

Comments
 (0)