-
Notifications
You must be signed in to change notification settings - Fork 1
1378 lines (1123 loc) · 43.5 KB
/
update-prompt-transfer.yml
File metadata and controls
1378 lines (1123 loc) · 43.5 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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
name: Update PromptTransfer Documentation
on:
push:
branches: [ main ]
paths:
- 'src/**'
- 'package.json'
- 'package-lock.json'
- 'tsconfig.json'
- 'vite.config.ts'
- 'tailwind.config.js'
- 'supabase/**'
jobs:
update-prompt-transfer:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3
with:
token: ${{ secrets.GITHUB_TOKEN }}
- name: Setup Node.js
uses: actions/setup-node@v3
with:
node-version: '18'
- name: Install Dependencies
run: npm install
- name: Analyze Codebase and Update PromptTransfer
run: |
# Create a script to analyze the codebase and update PromptTransfer.md
cat > analyze_codebase.js << 'EOF'
const fs = require('fs');
const path = require('path');
// Function to recursively read directory
function readDirectory(dir, extensions = ['.tsx', '.ts', '.js', '.json']) {
const results = [];
const files = fs.readdirSync(dir, { withFileTypes: true });
for (const file of files) {
const fullPath = path.join(dir, file.name);
if (file.isDirectory() && !file.name.startsWith('.') && file.name !== 'node_modules' && file.name !== 'dist') {
results.push(...readDirectory(fullPath, extensions));
} else if (file.isFile() && extensions.some(ext => file.name.endsWith(ext))) {
results.push(fullPath);
}
}
return results;
}
// Analyze key files
function analyzeCodebase() {
const analysis = {
components: [],
types: [],
features: [],
dependencies: {},
dbSchema: []
};
// Read package.json for dependencies
try {
const packageJson = JSON.parse(fs.readFileSync('package.json', 'utf8'));
analysis.dependencies = { ...packageJson.dependencies, ...packageJson.devDependencies };
} catch (e) {
console.warn('Could not read package.json');
}
// Analyze source files
const sourceFiles = readDirectory('src');
sourceFiles.forEach(file => {
try {
const content = fs.readFileSync(file, 'utf8');
const relativePath = path.relative('.', file);
// Extract component names and key features
if (file.includes('components/') && file.endsWith('.tsx')) {
const componentName = path.basename(file, '.tsx');
analysis.components.push({
name: componentName,
path: relativePath,
hasState: content.includes('useState'),
hasEffect: content.includes('useEffect'),
hasAI: content.includes('hf.textGeneration') || content.includes('AI') || content.includes('inference'),
hasDatabase: content.includes('supabase') || content.includes('database'),
hasTimer: content.includes('timer') || content.includes('Timer'),
hasNavigation: content.includes('navigation') || content.includes('Navigate'),
exports: extractExports(content)
});
}
// Extract type definitions
if (file.includes('types/') && file.endsWith('.ts')) {
analysis.types.push({
file: relativePath,
interfaces: extractInterfaces(content),
types: extractTypes(content)
});
}
// Identify key features
if (content.includes('AI') || content.includes('textGeneration')) {
analysis.features.push('AI Integration');
}
if (content.includes('supabase') || content.includes('database')) {
analysis.features.push('Database Integration');
}
if (content.includes('timer') || content.includes('Timer')) {
analysis.features.push('Timer Functionality');
}
if (content.includes('filter') || content.includes('Filter')) {
analysis.features.push('Filtering System');
}
} catch (e) {
console.warn(`Could not analyze file: ${file}`);
}
});
// Analyze database migrations
if (fs.existsSync('supabase/migrations')) {
const migrationFiles = readDirectory('supabase/migrations', ['.sql']);
migrationFiles.forEach(file => {
try {
const content = fs.readFileSync(file, 'utf8');
analysis.dbSchema.push({
file: path.relative('.', file),
content: content.substring(0, 500) + (content.length > 500 ? '...' : '')
});
} catch (e) {
console.warn(`Could not read migration: ${file}`);
}
});
}
return analysis;
}
function extractExports(content) {
const exports = [];
const exportRegex = /export\s+(default\s+)?(function|const|class|interface|type)\s+(\w+)/g;
let match;
while ((match = exportRegex.exec(content)) !== null) {
exports.push(match[3]);
}
return exports;
}
function extractInterfaces(content) {
const interfaces = [];
const interfaceRegex = /interface\s+(\w+)/g;
let match;
while ((match = interfaceRegex.exec(content)) !== null) {
interfaces.push(match[1]);
}
return interfaces;
}
function extractTypes(content) {
const types = [];
const typeRegex = /type\s+(\w+)\s*=/g;
let match;
while ((match = typeRegex.exec(content)) !== null) {
types.push(match[1]);
}
return types;
}
// Generate updated PromptTransfer.md
function generatePromptTransfer(analysis) {
const currentDate = new Date().toISOString().split('T')[0];
let content = `# AgileGamifAI Application Recreation Prompt
*Last Updated: ${currentDate}*
*Auto-generated based on current codebase analysis*
## Overview
Create a modern web application called "AgileGamifAI" that serves as a comprehensive platform for Agile games and activities. The application helps Agile practitioners discover, create, manage, and facilitate games that enhance team collaboration and learning.
## Current Codebase Analysis
### Detected Features
${analysis.features.length > 0 ? analysis.features.map(f => `- ${f}`).join('\n') : '- No specific features detected'}
### Component Architecture
`;
// Add component details
analysis.components.forEach(comp => {
content += `
#### ${comp.name}
- **Path**: \`${comp.path}\`
- **Capabilities**: `;
const capabilities = [];
if (comp.hasState) capabilities.push('State Management');
if (comp.hasEffect) capabilities.push('Side Effects');
if (comp.hasAI) capabilities.push('AI Integration');
if (comp.hasDatabase) capabilities.push('Database Operations');
if (comp.hasTimer) capabilities.push('Timer/Scheduling');
if (comp.hasNavigation) capabilities.push('Navigation');
content += capabilities.length > 0 ? capabilities.join(', ') : 'Basic Component';
if (comp.exports.length > 0) {
content += `\n- **Exports**: ${comp.exports.join(', ')}`;
}
});
content += `
### Type System
`;
analysis.types.forEach(typeFile => {
content += `
#### ${typeFile.file}
`;
if (typeFile.interfaces.length > 0) {
content += `- **Interfaces**: ${typeFile.interfaces.join(', ')}\n`;
}
if (typeFile.types.length > 0) {
content += `- **Types**: ${typeFile.types.join(', ')}\n`;
}
});
content += `
### Dependencies
#### Production Dependencies
`;
Object.entries(analysis.dependencies).forEach(([name, version]) => {
if (!name.startsWith('@types/') && !name.includes('eslint') && !name.includes('typescript')) {
content += `- **${name}**: ${version}\n`;
}
});
content += `
### Database Schema
`;
if (analysis.dbSchema.length > 0) {
analysis.dbSchema.forEach(schema => {
content += `
#### ${schema.file}
\`\`\`sql
${schema.content}
\`\`\`
`;
});
} else {
content += 'No database migrations detected.\n';
}
content += `
## Core Technologies Stack
- **Frontend Framework**: React 18+ with TypeScript
- **Build Tool**: Vite
- **Styling**: Tailwind CSS with custom components
- **Database**: Any modern database (SQL-based preferred for relational data)
- **AI Integration**: Any text generation AI service with API access
- **Deployment**: Static hosting platform with CI/CD pipeline
- **Icons**: Lucide React icon library
## Application Architecture
### Essential Type Definitions
Based on the current codebase, implement these core types:
\`\`\`typescript
export type AgileMethodology = 'Scrum' | 'Kanban' | 'XP' | 'Lean' | 'LeSS' | 'Nexus' | 'General';
export type GamePurpose = 'Team Building' | 'Problem Solving' | 'Retrospective' | 'Estimation' | 'Planning' | 'Prioritization' | 'Process Improvement';
export type GameComplexity = 'Easy' | 'Medium' | 'Hard';
export type AgileKnowledgeLevel = 'New to Agile' | 'Agile Basics' | 'Agile Practitioner' | 'Agile Master';
export interface Game {
id: string;
title: string;
description: string;
methodology: AgileMethodology[];
purpose: GamePurpose[];
minParticipants: number;
maxParticipants: number;
duration: number; // in minutes
materials: string[];
instructions: string;
facilitationTips: string;
complexity: GameComplexity;
isFavorite: boolean;
learningOutcomes: string[];
isAccessible: boolean;
accessibilityNotes?: string;
requiredKnowledgeLevel: AgileKnowledgeLevel;
}
export interface GameFilters {
methodology: AgileMethodology[];
purpose: GamePurpose[];
participants: number;
maxDuration: number;
complexity: GameComplexity[];
searchTerm: string;
knowledgeLevel: AgileKnowledgeLevel[];
accessibleOnly: boolean;
}
\`\`\`
## Key Features & Implementation Requirements
### 1. Main Application Structure
- **State Management**: Games list, filters, current view, selected game, pagination
- **Views**: Library, Create, Favorites, Detail, Facilitator modes
- **Database Integration**: Load games from database, handle favorites
- **Responsive Pagination**: Adaptive items per page based on screen size
- **Error Handling**: Loading states and error messages
### 2. Game Library System
**Components**: GameGrid, GameCard, GameFilter
- **Grid Display**: Responsive grid layout for game cards
- **Advanced Filtering**: Multi-criteria filtering by methodology, purpose, complexity, knowledge level, participants, duration, search terms, accessibility
- **Game Cards**: Display game overview with key metadata and actions
- **Pagination**: Page-based navigation for large game collections
### 3. AI-Powered Game Suggestion
- **Custom Prompts**: User input for specific game requirements
- **AI Integration**: Generate games using text generation AI with structured prompts
- **System Prompt**: Expert Agile coach persona with specific JSON response format
- **Response Parsing**: Parse AI-generated JSON into Game objects
- **Save Integration**: Save liked AI-generated games to database with popularity tracking
- **Error Handling**: Graceful failure with user-friendly messages
### 4. Manual Game Creation
- **Form Interface**: Comprehensive form for all game properties
- **AI Assistance**: Auto-complete missing fields using AI when partial data is provided
- **Validation**: Required field validation with error display
- **Dynamic Arrays**: Add/remove materials and learning outcomes
- **Multi-Select**: Methodology and purpose selection with toggle functionality
### 5. Game Facilitation Mode
- **Timer System**: Countdown timer with play/pause/reset functionality
- **Step Navigation**: Step-by-step instruction walkthrough
- **Progress Tracking**: Visual progress bar and step indicators
- **Real-time Updates**: 1-second timer intervals with cleanup
- **Visual Feedback**: Color-coded timer states (green/yellow/red)
### 6. UI Component System
**Components**: Button, Badge, Card
- **Variant System**: Multiple visual variants for different contexts
- **Accessibility**: Proper ARIA attributes and keyboard navigation
- **Consistent Styling**: Unified design system across components
## AI Integration Specifications
### Game Generation Prompt Structure
\`\`\`
System: You are an expert Agile coach. Create an engaging Agile game with the following JSON format:
{
"title": "Game Title",
"description": "Brief description",
"methodology": ["Array of methodologies"],
"purpose": ["Array of purposes"],
"minParticipants": number,
"maxParticipants": number,
"duration": number (in minutes),
"materials": ["List of required materials"],
"instructions": "Step by step instructions",
"facilitationTips": "Tips for facilitators",
"complexity": "Easy/Medium/Hard",
"learningOutcomes": ["List of learning outcomes"],
"isAccessible": boolean,
"accessibilityNotes": "If isAccessible is true, provide notes",
"requiredKnowledgeLevel": "New to Agile/Agile Basics/Agile Practitioner/Agile Master"
}
User request: [User's prompt]
\`\`\`
### AI Model Requirements
- **Capability**: Text generation with JSON output
- **Parameters**: Max tokens ~1000, temperature 0.7
- **Error Handling**: JSON parsing with fallback error messages
## Development Environment Setup
\`\`\`json
{
"scripts": {
"dev": "vite",
"build": "vite build",
"lint": "eslint .",
"preview": "vite preview"
}
}
\`\`\`
## Environment Variables Required
\`\`\`env
VITE_DATABASE_URL=your_database_connection_string
VITE_DATABASE_ANON_KEY=your_database_anonymous_key
\`\`\`
## Styling Guidelines
- **Color Scheme**: Teal and purple gradient theme
- **Typography**: Clean, modern fonts with proper hierarchy
- **Responsive Design**: Mobile-first approach with breakpoints
- **Accessibility**: High contrast, screen reader support, keyboard navigation
- **Visual Feedback**: Loading states, hover effects, transitions
---
# Comprehensive Regression Test Scripts
## Test Suite 1: Core Application Functionality
### Test 1.1: Application Initialization
\`\`\`javascript
describe('Application Initialization', () => {
test('should load the application without errors', async () => {
const { getByRole, queryByText } = render(<App />);
// Verify main app components render
expect(getByRole('banner')).toBeInTheDocument(); // Header
expect(getByRole('main')).toBeInTheDocument(); // Main content
// Check for no JavaScript errors
expect(console.error).not.toHaveBeenCalled();
});
test('should display default library view', async () => {
const { getByTestId, getByText } = render(<App />);
// Verify library view is active
expect(getByText('Library')).toHaveClass('active');
// Check for game grid or loading state
await waitFor(() => {
expect(getByTestId('game-grid') || getByTestId('loading-spinner')).toBeInTheDocument();
});
});
});
\`\`\`
### Test 1.2: Navigation System
\`\`\`javascript
describe('Navigation System', () => {
test('should navigate between main views', async () => {
const { getByText, getByTestId } = render(<App />);
// Test Library → Create navigation
fireEvent.click(getByText('Create'));
await waitFor(() => {
expect(getByTestId('game-create-form')).toBeInTheDocument();
});
// Test Create → Favorites navigation
fireEvent.click(getByText('Favorites'));
await waitFor(() => {
expect(getByTestId('favorites-grid')).toBeInTheDocument();
});
// Return to Library
fireEvent.click(getByText('Library'));
await waitFor(() => {
expect(getByTestId('game-grid')).toBeInTheDocument();
});
});
test('should handle mobile navigation', async () => {
// Set mobile viewport
Object.defineProperty(window, 'innerWidth', { value: 500 });
const { getByRole, getByText } = render(<App />);
// Find mobile menu button
const menuButton = getByRole('button', { name: /menu/i });
expect(menuButton).toBeInTheDocument();
// Test menu toggle
fireEvent.click(menuButton);
await waitFor(() => {
expect(getByText('Create')).toBeVisible();
});
});
});
\`\`\`
## Test Suite 2: Game Library Features
### Test 2.1: Game Display and Grid
\`\`\`javascript
describe('Game Library Display', () => {
const mockGames = [
{ id: '1', title: 'Test Game 1', methodology: ['Scrum'], complexity: 'Easy' },
{ id: '2', title: 'Test Game 2', methodology: ['Kanban'], complexity: 'Medium' }
];
test('should display games in responsive grid', async () => {
const { getAllByTestId } = render(<GameGrid games={mockGames} />);
// Verify game cards are rendered
const gameCards = getAllByTestId('game-card');
expect(gameCards).toHaveLength(2);
// Check responsive behavior
expect(gameCards[0]).toHaveClass('responsive-card');
});
test('should handle empty states', () => {
const { getByText } = render(<GameGrid games={[]} isLoading={false} />);
expect(getByText(/no games found/i)).toBeInTheDocument();
});
test('should display loading state', () => {
const { getByTestId } = render(<GameGrid games={[]} isLoading={true} />);
expect(getByTestId('loading-spinner')).toBeInTheDocument();
});
});
\`\`\`
### Test 2.2: Advanced Filtering System
\`\`\`javascript
describe('Game Filtering', () => {
const mockGames = [
{
id: '1',
title: 'Scrum Game',
methodology: ['Scrum'],
purpose: ['Planning'],
complexity: 'Easy',
minParticipants: 3,
maxParticipants: 8,
duration: 30,
isAccessible: true
},
{
id: '2',
title: 'Kanban Game',
methodology: ['Kanban'],
purpose: ['Process Improvement'],
complexity: 'Medium',
minParticipants: 5,
maxParticipants: 12,
duration: 60,
isAccessible: false
}
];
test('should filter by methodology', async () => {
const { getByLabelText, queryByText } = render(<App initialGames={mockGames} />);
// Select Scrum methodology
fireEvent.click(getByLabelText('Scrum'));
await waitFor(() => {
expect(queryByText('Scrum Game')).toBeInTheDocument();
expect(queryByText('Kanban Game')).not.toBeInTheDocument();
});
});
test('should filter by multiple criteria', async () => {
const { getByLabelText, getByDisplayValue, queryByText } = render(<App initialGames={mockGames} />);
// Apply multiple filters
fireEvent.click(getByLabelText('Medium'));
fireEvent.change(getByDisplayValue('0'), { target: { value: '5' } }); // participants
await waitFor(() => {
expect(queryByText('Kanban Game')).toBeInTheDocument();
expect(queryByText('Scrum Game')).not.toBeInTheDocument();
});
});
test('should perform text search', async () => {
const { getByPlaceholderText, queryByText } = render(<App initialGames={mockGames} />);
// Search for "Scrum"
fireEvent.change(getByPlaceholderText(/search/i), { target: { value: 'Scrum' } });
await waitFor(() => {
expect(queryByText('Scrum Game')).toBeInTheDocument();
expect(queryByText('Kanban Game')).not.toBeInTheDocument();
});
});
test('should filter by accessibility', async () => {
const { getByLabelText, queryByText } = render(<App initialGames={mockGames} />);
// Enable accessibility filter
fireEvent.click(getByLabelText(/accessible only/i));
await waitFor(() => {
expect(queryByText('Scrum Game')).toBeInTheDocument();
expect(queryByText('Kanban Game')).not.toBeInTheDocument();
});
});
test('should reset all filters', async () => {
const { getByText, queryByText } = render(<App initialGames={mockGames} />);
// Apply a filter first
fireEvent.click(getByText('Scrum'));
// Reset filters
fireEvent.click(getByText(/reset/i));
await waitFor(() => {
expect(queryByText('Scrum Game')).toBeInTheDocument();
expect(queryByText('Kanban Game')).toBeInTheDocument();
});
});
});
\`\`\`
## Test Suite 3: AI Integration
### Test 3.1: AI Game Suggestion
\`\`\`javascript
describe('AI Game Suggestion', () => {
const mockAIResponse = {
generated_text: JSON.stringify({
title: 'AI Generated Game',
description: 'A test game',
methodology: ['Scrum'],
purpose: ['Team Building'],
minParticipants: 4,
maxParticipants: 8,
duration: 45,
materials: ['Cards', 'Timer'],
instructions: 'Step by step',
facilitationTips: 'Keep it fun',
complexity: 'Medium',
learningOutcomes: ['Collaboration'],
isAccessible: true,
accessibilityNotes: 'Inclusive design',
requiredKnowledgeLevel: 'Agile Basics'
})
};
beforeEach(() => {
global.fetch = jest.fn(() =>
Promise.resolve({
ok: true,
json: () => Promise.resolve(mockAIResponse)
})
);
});
test('should generate games from custom prompts', async () => {
const { getByPlaceholderText, getByText, getByTestId } = render(<AIGameSuggestion />);
// Enter custom prompt
fireEvent.change(getByPlaceholderText(/describe your ideal game/i), {
target: { value: 'A team building exercise for new team members' }
});
// Generate game
fireEvent.click(getByText(/generate/i));
// Wait for AI response
await waitFor(() => {
expect(getByText('AI Generated Game')).toBeInTheDocument();
});
expect(global.fetch).toHaveBeenCalledWith(
expect.stringContaining('api'),
expect.objectContaining({
method: 'POST',
body: expect.stringContaining('team building exercise')
})
);
});
test('should handle AI generation errors', async () => {
global.fetch = jest.fn(() => Promise.reject(new Error('Network error')));
const { getByText, getByPlaceholderText } = render(<AIGameSuggestion />);
fireEvent.change(getByPlaceholderText(/describe your ideal game/i), {
target: { value: 'Test prompt' }
});
fireEvent.click(getByText(/generate/i));
await waitFor(() => {
expect(getByText(/failed to generate/i)).toBeInTheDocument();
});
});
test('should save and rate generated games', async () => {
const mockSaveGame = jest.fn();
const { getByText, getByRole } = render(
<AIGameSuggestion onGameGenerated={mockSaveGame} />
);
// Mock having a generated game
const component = getByTestId('ai-suggestion');
// Like the game
fireEvent.click(getByRole('button', { name: /like/i }));
await waitFor(() => {
expect(mockSaveGame).toHaveBeenCalledWith(
expect.objectContaining({ title: 'AI Generated Game' })
);
});
});
});
\`\`\`
### Test 3.2: AI-Assisted Game Creation
\`\`\`javascript
describe('AI-Assisted Creation', () => {
test('should auto-complete missing fields', async () => {
const { getByDisplayValue, getByText, getByLabelText } = render(<GameCreate />);
// Fill in partial data
fireEvent.change(getByLabelText(/title/i), { target: { value: 'Partial Game' } });
fireEvent.change(getByLabelText(/description/i), { target: { value: 'A test game' } });
// Trigger AI completion
fireEvent.click(getByText(/generate missing fields/i));
await waitFor(() => {
expect(getByDisplayValue(/step by step/i)).toBeInTheDocument(); // AI-generated instructions
});
});
test('should preserve user input during AI assistance', async () => {
const { getByDisplayValue, getByText, getByLabelText } = render(<GameCreate />);
const userTitle = 'My Custom Game';
// User enters title
fireEvent.change(getByLabelText(/title/i), { target: { value: userTitle } });
// AI completes other fields
fireEvent.click(getByText(/generate missing fields/i));
await waitFor(() => {
// User's title should be preserved
expect(getByDisplayValue(userTitle)).toBeInTheDocument();
});
});
});
\`\`\`
## Test Suite 4: Game Management
### Test 4.1: Game Creation
\`\`\`javascript
describe('Manual Game Creation', () => {
test('should validate required fields', async () => {
const { getByText, getByRole } = render(<GameCreate />);
// Try to save without required fields
fireEvent.click(getByRole('button', { name: /save game/i }));
await waitFor(() => {
expect(getByText(/title is required/i)).toBeInTheDocument();
expect(getByText(/description is required/i)).toBeInTheDocument();
});
});
test('should create complete game', async () => {
const mockOnSave = jest.fn();
const { getByLabelText, getByRole, getByText } = render(<GameCreate onSaveGame={mockOnSave} />);
// Fill all required fields
fireEvent.change(getByLabelText(/title/i), { target: { value: 'Test Game' } });
fireEvent.change(getByLabelText(/description/i), { target: { value: 'Test description' } });
fireEvent.click(getByText('Scrum')); // methodology
fireEvent.click(getByText('Team Building')); // purpose
fireEvent.change(getByLabelText(/min participants/i), { target: { value: '3' } });
fireEvent.change(getByLabelText(/max participants/i), { target: { value: '8' } });
fireEvent.change(getByLabelText(/duration/i), { target: { value: '30' } });
fireEvent.change(getByLabelText(/instructions/i), { target: { value: 'Test instructions' } });
// Save game
fireEvent.click(getByRole('button', { name: /save game/i }));
await waitFor(() => {
expect(mockOnSave).toHaveBeenCalledWith(
expect.objectContaining({
title: 'Test Game',
description: 'Test description',
methodology: ['Scrum'],
purpose: ['Team Building']
})
);
});
});
test('should manage dynamic arrays', async () => {
const { getByText, getByLabelText, getAllByLabelText } = render(<GameCreate />);
// Add material
fireEvent.click(getByText(/add material/i));
fireEvent.change(getByLabelText(/material/i), { target: { value: 'Cards' } });
// Add another material
fireEvent.click(getByText(/add material/i));
const materialInputs = getAllByLabelText(/material/i);
fireEvent.change(materialInputs[1], { target: { value: 'Timer' } });
// Remove first material
const removeButtons = getAllByText(/remove/i);
fireEvent.click(removeButtons[0]);
// Should have one material remaining
expect(getAllByLabelText(/material/i)).toHaveLength(1);
});
});
\`\`\`
### Test 4.2: Game Detail View
\`\`\`javascript
describe('Game Detail Display', () => {
const mockGame = {
id: '1',
title: 'Test Game',
description: 'A comprehensive test game',
methodology: ['Scrum', 'Kanban'],
purpose: ['Team Building'],
minParticipants: 3,
maxParticipants: 8,
duration: 45,
materials: ['Cards', 'Timer'],
instructions: 'Detailed instructions',
facilitationTips: 'Keep it engaging',
complexity: 'Medium',
learningOutcomes: ['Collaboration', 'Communication'],
isAccessible: true,
accessibilityNotes: 'Suitable for all abilities',
requiredKnowledgeLevel: 'Agile Basics'
};
test('should display comprehensive game information', () => {
const { getByText } = render(<GameDetail game={mockGame} />);
// Check all key information is displayed
expect(getByText('Test Game')).toBeInTheDocument();
expect(getByText('A comprehensive test game')).toBeInTheDocument();
expect(getByText('Scrum')).toBeInTheDocument();
expect(getByText('Kanban')).toBeInTheDocument();
expect(getByText('3-8 participants')).toBeInTheDocument();
expect(getByText('45 minutes')).toBeInTheDocument();
expect(getByText('Cards')).toBeInTheDocument();
expect(getByText('Timer')).toBeInTheDocument();
});
test('should handle accessibility features', () => {
const { getByText } = render(<GameDetail game={mockGame} />);
// Accessibility section should be visible
expect(getByText(/accessibility notes/i)).toBeInTheDocument();
expect(getByText('Suitable for all abilities')).toBeInTheDocument();
});
test('should hide accessibility section when not accessible', () => {
const inaccessibleGame = { ...mockGame, isAccessible: false };
const { queryByText } = render(<GameDetail game={inaccessibleGame} />);
expect(queryByText(/accessibility notes/i)).not.toBeInTheDocument();
});
});
\`\`\`
## Test Suite 5: Game Facilitation
### Test 5.1: Facilitator Mode
\`\`\`javascript
describe('Game Facilitator', () => {
const mockGame = {
id: '1',
title: 'Test Game',
duration: 2, // 2 minutes for testing
instructions: 'Step 1: Do this\\nStep 2: Do that\\nStep 3: Finish'
};
beforeEach(() => {
jest.useFakeTimers();
});
afterEach(() => {
jest.useRealTimers();
});
test('should initialize with correct timer duration', () => {
const { getByText } = render(<GameFacilitator game={mockGame} />);
// Should show 2:00 (2 minutes)
expect(getByText('02:00')).toBeInTheDocument();
});
test('should start and pause timer', () => {
const { getByRole, getByText } = render(<GameFacilitator game={mockGame} />);
const playButton = getByRole('button', { name: /play/i });
// Start timer
fireEvent.click(playButton);
// Advance timer by 1 second
act(() => {
jest.advanceTimersByTime(1000);
});
// Should show 1:59
expect(getByText('01:59')).toBeInTheDocument();
// Pause timer
const pauseButton = getByRole('button', { name: /pause/i });
fireEvent.click(pauseButton);
// Advance timer - should not change
act(() => {
jest.advanceTimersByTime(1000);
});
expect(getByText('01:59')).toBeInTheDocument();
});
test('should reset timer', () => {
const { getByRole, getByText } = render(<GameFacilitator game={mockGame} />);
// Start and run timer
fireEvent.click(getByRole('button', { name: /play/i }));
act(() => {
jest.advanceTimersByTime(5000);
});
// Reset timer
fireEvent.click(getByRole('button', { name: /reset/i }));
// Should be back to original duration
expect(getByText('02:00')).toBeInTheDocument();
});
test('should navigate through instruction steps', () => {
const { getByText, getByRole } = render(<GameFacilitator game={mockGame} />);
// Should start at first step
expect(getByText('Step 1: Do this')).toBeInTheDocument();
// Go to next step
fireEvent.click(getByRole('button', { name: /next/i }));
expect(getByText('Step 2: Do that')).toBeInTheDocument();
// Go to previous step
fireEvent.click(getByRole('button', { name: /previous/i }));
expect(getByText('Step 1: Do this')).toBeInTheDocument();
});
test('should show progress bar updates', () => {
const { getByRole } = render(<GameFacilitator game={mockGame} />);
const progressBar = getByRole('progressbar');
// Start timer
fireEvent.click(getByRole('button', { name: /play/i }));
// Advance timer by half duration
act(() => {
jest.advanceTimersByTime(60000); // 1 minute of 2 minutes
});
// Progress should be approximately 50%
expect(progressBar).toHaveStyle('width: 50%');
});
test('should handle timer completion', () => {
const mockOnComplete = jest.fn();
const { getByRole } = render(<GameFacilitator game={mockGame} onComplete={mockOnComplete} />);
// Start timer
fireEvent.click(getByRole('button', { name: /play/i }));
// Complete the timer
act(() => {
jest.advanceTimersByTime(120000); // 2 minutes
});
// Timer should stop at 00:00
expect(getByText('00:00')).toBeInTheDocument();
});
});
\`\`\`
## Test Suite 6: Database Integration
### Test 6.1: Data Persistence
\`\`\`javascript
describe('Database Operations', () => {
const mockDatabase = {
insert: jest.fn(() => Promise.resolve({ data: { id: 'new-id' } })),
select: jest.fn(() => Promise.resolve({ data: [] })),
update: jest.fn(() => Promise.resolve({ data: {} })),