Skip to content

Commit c7cf7f9

Browse files
talissoncostaclaude
andcommitted
fix(test): fix FlagsTab test mock pattern matching and role selector
- Sort mock URL patterns by length to match more specific patterns first - Fix dashboard link test to use 'link' role instead of 'button' - Remove unused mockEntity import 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <[email protected]>
1 parent 0f1a9e6 commit c7cf7f9

File tree

2 files changed

+8
-5
lines changed

2 files changed

+8
-5
lines changed

src/__tests__/fixtures/testUtils.tsx

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,11 @@ export const createMockDiscoveryApi = (baseUrl = 'http://localhost:7007'): Disco
2020
export const createMockFetchApi = (responses: Record<string, unknown> = {}) => {
2121
const mockFetch = jest.fn().mockImplementation(async (url: string) => {
2222
// Find matching response based on URL pattern
23-
for (const [pattern, data] of Object.entries(responses)) {
23+
// Sort patterns by length (longest first) to match more specific patterns first
24+
const sortedPatterns = Object.entries(responses).sort(
25+
([a], [b]) => b.length - a.length,
26+
);
27+
for (const [pattern, data] of sortedPatterns) {
2428
if (url.includes(pattern)) {
2529
return {
2630
ok: true,

src/components/FlagsTab/__tests__/FlagsTab.test.tsx

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ import {
66
mockProject,
77
mockEnvironments,
88
mockFeatures,
9-
mockEntity,
109
mockEntityNoAnnotations,
1110
} from '../../../__tests__/fixtures';
1211

@@ -173,8 +172,8 @@ describe('FlagsTab', () => {
173172
expect(screen.getByText('feature-one')).toBeInTheDocument();
174173
});
175174

176-
// Should have Open Dashboard button
177-
const dashboardButton = screen.getByRole('button', { name: /open dashboard/i });
178-
expect(dashboardButton).toBeInTheDocument();
175+
// Should have Open Dashboard link (renders as an anchor with aria-label)
176+
const dashboardLink = screen.getByRole('link', { name: /open dashboard/i });
177+
expect(dashboardLink).toBeInTheDocument();
179178
});
180179
});

0 commit comments

Comments
 (0)