Open cloverzer0 opened 2 months ago
Summary of what muktar and I did, could be useful for others when they write unit tests for components and complex structures: --HOW TO DO UNIT TEST FOR LEADERBOARDS---
Examples of failing test w/assertions
TESTS FOR LEADERBOARD POSITIONS (test for a funciton that determines leaderboard positions) --> expect(team[2]).toBe(1) --> expect(team[1]).toBe(2) --> expect(team[0]).toBe(3)
TESTS FOR TOTAL TEAM POINTS (test for a function that determines team points) -->expect(team[0]).toBe(150) -->expect(team[1]).toBe(110)
TEST FOR INDIVIDUAL POINTS (sanity test) --> expect(person[0]).toBe(20) --> expect(person[1]).toBe(50)
MOCK DATA
Mock data for users (simplified)
const mockUsers = [
{
name: "Hasith"
point: 10
team_id: 12
},
{
name: "Muktar"
points: 20
team_id: 5
},
{
name: "Farabi"
points: 12,
team_id: 3
},
{
name: "Jowi"
points: 22,
team_id: 5
}
]
Mock data for teams (simplified)
const mockTeams = [
{
team_id: 5
total_points: 42
team_name: "Husky"
},
{
team_id: 3
total_points: 12
team_name: "Husky"
},
{
team_id: 12
total_points: 10
team_name: "Husky"
}
]
team 5 points: 42 team 3 points: 12 team 12 points: 10
HOW TO MOCK AN API CALL
import { vi } from 'vitest';
import axios from 'axios';
import { mockUsers } from 'data/mock/users';
import { mockTeams } from 'data/mock/team';
vi.mock('axios', () => ({
get: vi.fn(() =>
Promise.resolve({
data: {
users: mockUsers,
team: mockTeams
},
})
),
}));
Example test (not how the code will actually look)
describe('Team Leader Component', () => {
it('renders a leaderboard that keeps track of team points', async () => {
render(
<Leaderboard
teams={mockTeams}
/>
);
// Check that the events are rendered
expect(await screen.findByText('Event 1')).toBeInTheDocument();
expect(await screen.findByText('Event 2')).toBeInTheDocument();
});
});
DON'T GET CARRIED AWAY!! THINK CAREFULLY ABOUT YOUR DESIGN CHOICES
Feature Overview for Gamification
Goals:
Increase Competitiveness, Participation and User Experience:
Implement a points-based system to foster a competitive environment among participants. Motivate increased engagement and active participation through competitive elements. Enhance Engagement:
Utilize gamification techniques to make activities more rewarding and enjoyable. Boost user engagement and retention by integrating engaging and interactive features. Components Needed:
Rewards: Types of Rewards: Tangible Rewards: Consider offering physical items such as gift cards, merchandise, or tech gadgets. Intangible Rewards: Recognize participants with non-physical rewards like exclusive access, certificates, or public recognition. Distribution: Reward the highest performers to sustain competitive levels. Common approaches include rewarding the top 3 individuals or the top 10% of participants. Frequency: Determine the schedule for distributing rewards, which could be at the end of each event, or at the conclusion of the entire hackathon.
Categories for Earning Points: Tasks: Points are awarded for completing specific tasks or assignments within the platform. Challenges: Participation in and successful completion of special challenges will earn participants points. Events: Engaging in hackathon events, workshops, or similar activities will contribute to the point total. Performance: Achieving notable milestones or high scores in tasks or challenges will be rewarded with points.
Badges: Purpose: Badges serve as symbols of achievement or expertise, providing visual recognition of accomplishments. Usage: Assign badges to mark significant milestones or skills. For example, a “TypeRace Champion” badge could be awarded for winning a specific challenge. Points:
Unit of Measurement: Points will be the primary metric used to rank and reward participants. Balance: Ensure fair distribution of points to avoid skewed competition and maintain participant motivation. Leaderboard:
Real-Time Updates: Display team rankings in real-time to keep the competition dynamic and engaging. Sorting: Sort teams based on their point totals, with options to view different metrics and performance indicators. Feedback and Adaptation:
User Feedback: Collect feedback from participants to refine and enhance the gamification system, ensuring it meets user expectations. Metrics and Analytics: Track engagement and performance metrics to assess the impact of the gamification features and make data-driven improvements. Endpoints:
Progress Page:
URL: https://cuhackplatform.com/user/progress/ Provides an overview of completed and ongoing events for individual users. Leaderboard Page:
URL: https://cuhackplatform.com/Leaderboard Displays real-time rankings of teams based on their accumulated points. History Page:
URL: https://cuhackplatform.com/History/2025/ Keeps track of the top 10 winners for each hackathon, providing historical performance data.
This will be a team based platform so its only reasonable if we look at only the teams points which is going to be the total of each individual points in the team. Database Schema: