-
Notifications
You must be signed in to change notification settings - Fork 0
π§ͺ [testing improvement github integration] Add test for invalid severity fallback #195
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. Weβll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Hardonian
merged 2 commits into
main
from
fix-github-formatfinding-tests-4569134560466602312
Jun 9, 2026
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,67 +1,63 @@ | ||
| import { describe, it, expect } from 'vitest'; | ||
| import { formatFindingAsMarkdown } from '../github'; | ||
| import { type AccessibilityFinding } from '../types'; | ||
|
|
||
| describe('formatFindingAsMarkdown', () => { | ||
| const baseFinding: AccessibilityFinding = { | ||
| id: 'f-1234', | ||
| url: 'https://example.com', | ||
| wcagCriteria: '1.4.3 Contrast (Minimum)', | ||
| severity: 'minor', | ||
| description: 'Text has insufficient color contrast.', | ||
| help: 'Ensure text has a contrast ratio of at least 4.5:1.', | ||
| impact: 'Users with low vision cannot read the text.', | ||
| timestamp: '2023-10-27T10:00:00Z', | ||
| element: 'div.low-contrast' | ||
| }; | ||
|
|
||
| it('maps critical severity to π΄', () => { | ||
| const finding: AccessibilityFinding = { ...baseFinding, severity: 'critical' }; | ||
| const markdown = formatFindingAsMarkdown(finding); | ||
| expect(markdown).toContain('π΄ **Severity:** CRITICAL'); | ||
| }); | ||
|
|
||
| it('maps serious severity to π ', () => { | ||
| const finding: AccessibilityFinding = { ...baseFinding, severity: 'serious' }; | ||
| const markdown = formatFindingAsMarkdown(finding); | ||
| expect(markdown).toContain('π **Severity:** SERIOUS'); | ||
| }); | ||
|
|
||
| it('maps moderate severity to π‘', () => { | ||
| const finding: AccessibilityFinding = { ...baseFinding, severity: 'moderate' }; | ||
| const markdown = formatFindingAsMarkdown(finding); | ||
| expect(markdown).toContain('π‘ **Severity:** MODERATE'); | ||
| }); | ||
|
|
||
| it('maps minor severity to π΅', () => { | ||
| const finding: AccessibilityFinding = { ...baseFinding, severity: 'minor' }; | ||
| const markdown = formatFindingAsMarkdown(finding); | ||
| expect(markdown).toContain('π΅ **Severity:** MINOR'); | ||
| }); | ||
|
|
||
| it('uses βͺ for unknown severity', () => { | ||
| const finding = { ...baseFinding, severity: 'unknown' } as unknown as AccessibilityFinding; | ||
| const markdown = formatFindingAsMarkdown(finding); | ||
| expect(markdown).toContain('βͺ **Severity:** UNKNOWN'); | ||
| }); | ||
|
|
||
| it('includes all fields in the generated markdown', () => { | ||
| const markdown = formatFindingAsMarkdown(baseFinding); | ||
| expect(markdown).toContain('## Accessibility Finding'); | ||
| expect(markdown).toContain('Text has insufficient color contrast.'); | ||
| expect(markdown).toContain('Ensure text has a contrast ratio of at least 4.5:1.'); | ||
| expect(markdown).toContain('Users with low vision cannot read the text.'); | ||
| expect(markdown).toContain('| URL | https://example.com |'); | ||
| expect(markdown).toContain('| Element | div.low-contrast |'); | ||
| expect(markdown).toContain('| WCAG Criteria | 1.4.3 Contrast (Minimum) |'); | ||
| expect(markdown).toContain('| Finding ID | f-1234 |'); | ||
| expect(markdown).toContain('| Timestamp | 2023-10-27T10:00:00Z |'); | ||
| expect(markdown).toContain('*Generated by AccessibleMadeFlexible*'); | ||
| }); | ||
|
|
||
| it('falls back to "N/A" when element is undefined', () => { | ||
| const findingWithoutElement: AccessibilityFinding = { ...baseFinding, element: undefined }; | ||
| const markdown = formatFindingAsMarkdown(findingWithoutElement); | ||
| expect(markdown).toContain('| Element | N/A |'); | ||
| import { AccessibilityFinding } from '../types'; | ||
|
|
||
| describe('github integrations', () => { | ||
| describe('formatFindingAsMarkdown', () => { | ||
| const baseFinding: AccessibilityFinding = { | ||
| id: 'test-123', | ||
| url: 'https://example.com', | ||
| element: '<button>click</button>', | ||
| wcagCriteria: '1.1.1 Non-text Content', | ||
| severity: 'serious', | ||
| description: 'Button has no accessible name', | ||
| help: 'Provide an accessible name for the button', | ||
| impact: 'high', | ||
| timestamp: '2023-10-27T10:00:00Z' | ||
| }; | ||
|
|
||
| it('should format a finding with valid severity properly', () => { | ||
| const markdown = formatFindingAsMarkdown(baseFinding); | ||
| expect(markdown).toContain('π **Severity:** SERIOUS'); | ||
| expect(markdown).toContain(baseFinding.description); | ||
| expect(markdown).toContain(baseFinding.help); | ||
| expect(markdown).toContain(baseFinding.impact); | ||
| expect(markdown).toContain(baseFinding.url); | ||
| expect(markdown).toContain(baseFinding.element!); | ||
| }); | ||
|
|
||
| it('should format a finding with critical severity properly', () => { | ||
| const finding = { ...baseFinding, severity: 'critical' as const }; | ||
| const markdown = formatFindingAsMarkdown(finding); | ||
| expect(markdown).toContain('π΄ **Severity:** CRITICAL'); | ||
| }); | ||
|
|
||
| it('should format a finding with moderate severity properly', () => { | ||
| const finding = { ...baseFinding, severity: 'moderate' as const }; | ||
| const markdown = formatFindingAsMarkdown(finding); | ||
| expect(markdown).toContain('π‘ **Severity:** MODERATE'); | ||
| }); | ||
|
|
||
| it('should format a finding with minor severity properly', () => { | ||
| const finding = { ...baseFinding, severity: 'minor' as const }; | ||
| const markdown = formatFindingAsMarkdown(finding); | ||
| expect(markdown).toContain('π΅ **Severity:** MINOR'); | ||
| }); | ||
|
|
||
| it('should handle missing element field', () => { | ||
| const findingWithoutElement = { ...baseFinding, element: undefined }; | ||
| const markdown = formatFindingAsMarkdown(findingWithoutElement); | ||
| expect(markdown).toContain('| Element | N/A |'); | ||
| }); | ||
|
|
||
| it('should use fallback emoji for invalid or unexpected severity strings', () => { | ||
| // @ts-expect-error - Intentionally passing an invalid severity string to test the fallback behavior | ||
| const invalidFinding: AccessibilityFinding = { | ||
| ...baseFinding, | ||
| severity: 'unknown_severity_level' | ||
| }; | ||
| const markdown = formatFindingAsMarkdown(invalidFinding); | ||
| expect(markdown).toContain('βͺ **Severity:** UNKNOWN_SEVERITY_LEVEL'); | ||
| }); | ||
| }); | ||
| }); | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.