Repository navigation
Expand file tree
/
Copy pathDeveloperArena.test.tsx
More file actions
99 lines (80 loc) · 3.91 KB
/
Copy pathDeveloperArena.test.tsx
File metadata and controls
99 lines (80 loc) · 3.91 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
/* eslint-disable @typescript-eslint/no-explicit-any */
import { render, screen, fireEvent, waitFor } from '@testing-library/react';
import '@testing-library/jest-dom/vitest';
import { describe, it, expect, vi } from 'vitest';
import DeveloperArena from './DeveloperArena';
import React from 'react';
// Mock Next.js Image component
vi.mock('next/image', () => ({
__esModule: true,
default: ({ fill, priority, ...props }: any) => {
// eslint-disable-next-line @next/next/no-img-element
return <img alt="" {...props} />;
},
}));
// Mock framer-motion to bypass animation delays in JSDOM
vi.mock('framer-motion', () => ({
motion: {
div: ({ children, whileHover, ...props }: any) => <div {...props}>{children}</div>,
},
AnimatePresence: ({ children }: any) => <>{children}</>,
}));
describe('DeveloperArena', () => {
it('renders correctly with sections and headings', () => {
const handleSelectBattle = vi.fn();
render(<DeveloperArena onSelectBattle={handleSelectBattle} />);
expect(screen.getByText('Developer Battleground')).toBeInTheDocument();
expect(screen.getByText('Step Into the Esports Arena')).toBeInTheDocument();
expect(screen.getByText('Trending Showdowns')).toBeInTheDocument();
expect(screen.getByText('Guess The Developer')).toBeInTheDocument();
expect(screen.getByText('AI Showdown Predictions')).toBeInTheDocument();
expect(screen.getByText('GitHub Legends Walk of Fame')).toBeInTheDocument();
});
it('triggers onSelectBattle when a trending showdown is clicked', () => {
const handleSelectBattle = vi.fn();
render(<DeveloperArena onSelectBattle={handleSelectBattle} />);
// Get a trending showdown card, e.g., React vs Svelte match gaearon/rich-harris
// There are multiple matching elements because of the infinite duplicate marquee layout, select one.
const showdownCards = screen.getAllByText('React vs Svelte');
expect(showdownCards.length).toBeGreaterThan(0);
fireEvent.click(showdownCards[0]);
expect(handleSelectBattle).toHaveBeenCalledWith('gaearon', 'rich-harris');
});
it('reveals the developer in the trivia game when Reveal button is clicked', async () => {
const handleSelectBattle = vi.fn();
render(<DeveloperArena onSelectBattle={handleSelectBattle} />);
// Initially, the unique biography should not be visible in text
expect(
screen.queryByText('React core team alumnus, creator of Redux and Create React App.')
).not.toBeInTheDocument();
const revealButton = screen.getByRole('button', { name: /reveal developer/i });
fireEvent.click(revealButton);
// The biography of the current challenge should be revealed
await waitFor(() => {
expect(
screen.getByText('React core team alumnus, creator of Redux and Create React App.')
).toBeInTheDocument();
});
});
it('triggers correct challenge action when Challenge Linus is clicked after reveal', async () => {
const handleSelectBattle = vi.fn();
render(<DeveloperArena onSelectBattle={handleSelectBattle} />);
const revealButton = screen.getByRole('button', { name: /reveal developer/i });
fireEvent.click(revealButton);
const challengeButton = await screen.findByRole('button', { name: /challenge linus/i });
fireEvent.click(challengeButton);
expect(handleSelectBattle).toHaveBeenCalledWith('gaearon', 'torvalds');
});
it('allows skipping a trivia game challenge', async () => {
const handleSelectBattle = vi.fn();
render(<DeveloperArena onSelectBattle={handleSelectBattle} />);
// First challenge hint contains "Creator of Redux"
expect(screen.getByText(/Creator of Redux/i)).toBeInTheDocument();
const skipButton = screen.getByRole('button', { name: /skip/i });
fireEvent.click(skipButton);
// Second challenge is Evan You, which contains "Creator of Vue.js"
await waitFor(() => {
expect(screen.getByText(/Creator of Vue.js/i)).toBeInTheDocument();
});
});
});