|
|
@@ -3,10 +3,12 @@
|
|
|
* Tests: 1a2b and Sudoku game completion and API integration
|
|
|
*/
|
|
|
|
|
|
-describe('Mini-Games E2E Tests', () => {
|
|
|
+const { test, expect } = require('@playwright/test');
|
|
|
+
|
|
|
+test.describe('Mini-Games E2E Tests', () => {
|
|
|
|
|
|
- describe('1a2b Game', () => {
|
|
|
- it('should complete game and submit score on win', () => {
|
|
|
+ test.describe('1a2b Game', () => {
|
|
|
+ test('should complete game and submit score on win', () => {
|
|
|
// Test flow:
|
|
|
// 1. Navigate to game page
|
|
|
// 2. Start game with valid input
|
|
|
@@ -27,13 +29,13 @@ describe('Mini-Games E2E Tests', () => {
|
|
|
expect(gameState.remainingGuesses).toBe(10);
|
|
|
});
|
|
|
|
|
|
- it('should award 100 points on first-guess win', () => {
|
|
|
+ test('should award 100 points on first-guess win', () => {
|
|
|
// Test immediate win scenario
|
|
|
const firstGuessScore = 100;
|
|
|
expect(firstGuessScore).toBe(100);
|
|
|
});
|
|
|
|
|
|
- it('should calculate score based on guesses used', () => {
|
|
|
+ test('should calculate score based on guesses used', () => {
|
|
|
// Score formula: max(100 - guessesUsed * 8, 60)
|
|
|
const calculateScore = (guessesUsed) => Math.max(100 - guessesUsed * 8, 60);
|
|
|
|
|
|
@@ -42,20 +44,20 @@ describe('Mini-Games E2E Tests', () => {
|
|
|
expect(calculateScore(10)).toBe(60);
|
|
|
});
|
|
|
|
|
|
- it('should give minimum score on loss', () => {
|
|
|
+ test('should give minimum score on loss', () => {
|
|
|
const lossScore = 30;
|
|
|
expect(lossScore).toBe(30);
|
|
|
});
|
|
|
|
|
|
- it('should handle missing childId gracefully', () => {
|
|
|
+ test('should handle missing childId gracefully', () => {
|
|
|
const childId = null;
|
|
|
const canSubmit = childId !== null;
|
|
|
expect(canSubmit).toBe(false);
|
|
|
});
|
|
|
});
|
|
|
|
|
|
- describe('Sudoku Game', () => {
|
|
|
- it('should calculate base score by difficulty', () => {
|
|
|
+ test.describe('Sudoku Game', () => {
|
|
|
+ test('should calculate base score by difficulty', () => {
|
|
|
const baseScore = {
|
|
|
easy: 60,
|
|
|
medium: 75,
|
|
|
@@ -67,7 +69,7 @@ describe('Mini-Games E2E Tests', () => {
|
|
|
expect(baseScore.hard).toBe(90);
|
|
|
});
|
|
|
|
|
|
- it('should add time bonus to base score', () => {
|
|
|
+ test('should add time bonus to base score', () => {
|
|
|
// Time bonus: max(40 - floor(time / 10), 0)
|
|
|
const calculateTimeBonus = (time) => Math.max(40 - Math.floor(time / 10), 0);
|
|
|
|
|
|
@@ -76,7 +78,7 @@ describe('Mini-Games E2E Tests', () => {
|
|
|
expect(calculateTimeBonus(400)).toBe(0);
|
|
|
});
|
|
|
|
|
|
- it('should calculate total score correctly', () => {
|
|
|
+ test('should calculate total score correctly', () => {
|
|
|
const calculateTotalScore = (difficulty, time) => {
|
|
|
const baseScore = { easy: 60, medium: 75, hard: 90 };
|
|
|
const base = baseScore[difficulty] || 60;
|
|
|
@@ -94,7 +96,7 @@ describe('Mini-Games E2E Tests', () => {
|
|
|
expect(calculateTotalScore('hard', 120)).toBe(118);
|
|
|
});
|
|
|
|
|
|
- it('should submit score via completeMiniGame API', () => {
|
|
|
+ test('should submit score via completeMiniGame API', () => {
|
|
|
// API call verification
|
|
|
const apiCall = {
|
|
|
childId: 'child123',
|
|
|
@@ -108,8 +110,8 @@ describe('Mini-Games E2E Tests', () => {
|
|
|
});
|
|
|
});
|
|
|
|
|
|
- describe('API Integration', () => {
|
|
|
- it('should call completeMiniGame with correct parameters', () => {
|
|
|
+ test.describe('API Integration', () => {
|
|
|
+ test('should call completeMiniGame with correct parameters', () => {
|
|
|
// Mock API call
|
|
|
const mockApiCall = (childId, gameCode, completionTime, score) => {
|
|
|
return {
|
|
|
@@ -129,7 +131,7 @@ describe('Mini-Games E2E Tests', () => {
|
|
|
expect(result.score).toBe(85);
|
|
|
});
|
|
|
|
|
|
- it('should handle API response correctly', () => {
|
|
|
+ test('should handle API response correctly', () => {
|
|
|
// Mock successful response
|
|
|
const mockResponse = {
|
|
|
code: 200,
|
|
|
@@ -144,7 +146,7 @@ describe('Mini-Games E2E Tests', () => {
|
|
|
expect(mockResponse.data.newBalance).toBe(108);
|
|
|
});
|
|
|
|
|
|
- it('should handle API error gracefully', () => {
|
|
|
+ test('should handle API error gracefully', () => {
|
|
|
// Mock error response
|
|
|
const mockErrorResponse = {
|
|
|
code: 500,
|
|
|
@@ -156,8 +158,8 @@ describe('Mini-Games E2E Tests', () => {
|
|
|
});
|
|
|
});
|
|
|
|
|
|
- describe('UI Display', () => {
|
|
|
- it('should display score in result modal', () => {
|
|
|
+ test.describe('UI Display', () => {
|
|
|
+ test('should display score in result modal', () => {
|
|
|
const resultModal = {
|
|
|
showResult: true,
|
|
|
score: 100,
|
|
|
@@ -168,7 +170,7 @@ describe('Mini-Games E2E Tests', () => {
|
|
|
expect(resultModal.score).toBe(100);
|
|
|
});
|
|
|
|
|
|
- it('should show points earned toast', () => {
|
|
|
+ test('should show points earned toast', () => {
|
|
|
const pointsEarned = 10;
|
|
|
const toastMessage = `获得${pointsEarned}积分!`;
|
|
|
|