Compare commits
19 Commits
4977043003
...
v0.1.16
| Author | SHA1 | Date | |
|---|---|---|---|
| 79dd9be11e | |||
| 08152fba51 | |||
| 9bfb890143 | |||
| 4fe47377d1 | |||
| c32239d557 | |||
| e3895d30b4 | |||
| aed554c337 | |||
| 14fbfacf9f | |||
| 9dc3fdb0e0 | |||
| edb05711ac | |||
| b2498decf8 | |||
| 877a38d744 | |||
| e6b41f65a5 | |||
| 88203869d5 | |||
| eff8e531aa | |||
| d8fb1b20d2 | |||
| 58e319d8e3 | |||
| 493ae0cf71 | |||
| 2292aa6d7f |
@@ -7,7 +7,7 @@ on:
|
|||||||
paths:
|
paths:
|
||||||
- 'Dockerfile.ci-base'
|
- 'Dockerfile.ci-base'
|
||||||
- 'package.json'
|
- 'package.json'
|
||||||
- 'bun.lockb'
|
- 'bun.lock'
|
||||||
- '.gitea/workflows/build-ci-images.yml'
|
- '.gitea/workflows/build-ci-images.yml'
|
||||||
schedule:
|
schedule:
|
||||||
# Weekly rebuild to get latest Playwright/Bun versions
|
# Weekly rebuild to get latest Playwright/Bun versions
|
||||||
|
|||||||
@@ -1,3 +1,44 @@
|
|||||||
|
## [0.1.16] - 2026-05-02
|
||||||
|
|
||||||
|
### Patch Changes
|
||||||
|
|
||||||
|
- Merge branch 'main' of https://git.notsosm.art/david/euchre_camp
|
||||||
|
- feat: add bracket visualization for tournament schedule (#8)
|
||||||
|
|
||||||
|
## [0.1.15] - 2026-05-02
|
||||||
|
|
||||||
|
### Patch Changes
|
||||||
|
|
||||||
|
- Merge branch 'main' of https://git.notsosm.art/david/euchre_camp
|
||||||
|
- feat: add view-as-role feature for site admins (#15)
|
||||||
|
|
||||||
|
## [0.1.14] - 2026-05-02
|
||||||
|
|
||||||
|
### Patch Changes
|
||||||
|
|
||||||
|
- Merge branch 'bugfix/7-tournament-schedule-tests': Schedule generation, clickable matchups, and test fixes
|
||||||
|
- Merge branch 'bugfix/9-player-schedule-tests': Player schedule clickable matches
|
||||||
|
- Merge branch 'bugfix/10-password-reset-tests': Password reset API and form wiring
|
||||||
|
- fix: resolve schedule generation tests - round display, clickable links, and team count
|
||||||
|
- fix: rename variable to avoid shadowing expectedRounds function
|
||||||
|
- fix: improve link click handling to wait for networkidle
|
||||||
|
- feat: implement password reset API endpoint and wire up form
|
||||||
|
- fix: make player schedule matches clickable links to match detail page
|
||||||
|
- fix: support matchup query param for direct navigation to entry page
|
||||||
|
- fix: correct wordmark link to point to home page
|
||||||
|
- fix: resolve schedule data staleness in production builds
|
||||||
|
- wip: Tournament schedule tests - 27/30 passing
|
||||||
|
- feat: add ScheduleDisplay component and wire up schedule page with Generator
|
||||||
|
- test: add tournament schedule step definitions
|
||||||
|
- test: enable player schedule tests with match data setup
|
||||||
|
- test: enable password reset page test and add navigation step
|
||||||
|
|
||||||
|
## [0.1.13] - 2026-04-27
|
||||||
|
|
||||||
|
### Patch Changes
|
||||||
|
|
||||||
|
- ci: update Playwright to v1.59.1 in CI base image
|
||||||
|
|
||||||
## [0.1.12] - 2026-04-27
|
## [0.1.12] - 2026-04-27
|
||||||
|
|
||||||
### Patch Changes
|
### Patch Changes
|
||||||
|
|||||||
+1
-1
@@ -2,7 +2,7 @@
|
|||||||
# Used for Gitea Actions CI workflows
|
# Used for Gitea Actions CI workflows
|
||||||
# Uses Microsoft Playwright image as base (Ubuntu-based) with Bun added
|
# Uses Microsoft Playwright image as base (Ubuntu-based) with Bun added
|
||||||
|
|
||||||
FROM mcr.microsoft.com/playwright:v1.58.0-jammy AS base
|
FROM mcr.microsoft.com/playwright:v1.59.1-jammy AS base
|
||||||
|
|
||||||
# Install unzip (required for Bun installation) and other tools
|
# Install unzip (required for Bun installation) and other tools
|
||||||
RUN apt-get update && apt-get install -y unzip && rm -rf /var/lib/apt/lists/*
|
RUN apt-get update && apt-get install -y unzip && rm -rf /var/lib/apt/lists/*
|
||||||
|
|||||||
@@ -0,0 +1,37 @@
|
|||||||
|
Feature: Bracket Visualization
|
||||||
|
As a tournament admin
|
||||||
|
I want to see a visual bracket of the tournament schedule
|
||||||
|
So that I can track tournament progress at a glance
|
||||||
|
|
||||||
|
@happy-path @tournament @issue-8
|
||||||
|
Scenario: Tournament admin views bracket with a generated schedule
|
||||||
|
Given I am logged in as a tournament admin
|
||||||
|
And a tournament exists with 4 teams
|
||||||
|
When I go to the tournament schedule page
|
||||||
|
And I click the "Generate Schedule" button
|
||||||
|
Then I should see "Generated"
|
||||||
|
When I go to the tournament detail page
|
||||||
|
And I click the "Bracket" tab
|
||||||
|
Then I should see "Tournament Bracket"
|
||||||
|
And I should see "Round 1"
|
||||||
|
And I should see "Round 2"
|
||||||
|
And I should see "Round 3"
|
||||||
|
And I should see bracket matchup cards
|
||||||
|
|
||||||
|
@happy-path @tournament @issue-8
|
||||||
|
Scenario: Bracket shows team names in matchup cards
|
||||||
|
Given I am logged in as a tournament admin
|
||||||
|
And a tournament exists with 4 teams
|
||||||
|
When I go to the tournament schedule page
|
||||||
|
And I click the "Generate Schedule" button
|
||||||
|
Then I should see "Generated"
|
||||||
|
When I go to the tournament detail page
|
||||||
|
And I click the "Bracket" tab
|
||||||
|
Then I should see bracket matchup cards with team names
|
||||||
|
|
||||||
|
@happy-path @tournament @issue-8
|
||||||
|
Scenario: Bracket tab is not visible without a schedule
|
||||||
|
Given I am logged in as a tournament admin
|
||||||
|
And a tournament exists with 4 teams
|
||||||
|
When I go to the tournament detail page
|
||||||
|
Then I should not see the "Bracket" tab
|
||||||
@@ -9,7 +9,7 @@ Feature: Player Schedule
|
|||||||
When I go to my schedule page
|
When I go to my schedule page
|
||||||
Then I should see "No upcoming matches"
|
Then I should see "No upcoming matches"
|
||||||
|
|
||||||
@happy-path @player-features @issue-9 @wip
|
@happy-path @player-features @issue-9
|
||||||
Scenario: Player views schedule with upcoming matches
|
Scenario: Player views schedule with upcoming matches
|
||||||
Given I am logged in as a player
|
Given I am logged in as a player
|
||||||
And I have upcoming matches in my schedule
|
And I have upcoming matches in my schedule
|
||||||
|
|||||||
@@ -19,7 +19,8 @@ Feature: Tournament Schedule
|
|||||||
And I click the "Generate Schedule" button
|
And I click the "Generate Schedule" button
|
||||||
Then I should see "Generated"
|
Then I should see "Generated"
|
||||||
And I should see "rounds with"
|
And I should see "rounds with"
|
||||||
When I refresh the page
|
# Navigate away and back to verify schedule persisted (avoids HMR caching issues)
|
||||||
|
When I go to the tournament schedule page
|
||||||
Then I should see round 1 matchups
|
Then I should see round 1 matchups
|
||||||
And I should see round 2 matchups
|
And I should see round 2 matchups
|
||||||
|
|
||||||
@@ -30,7 +31,8 @@ Feature: Tournament Schedule
|
|||||||
When I go to the tournament schedule page
|
When I go to the tournament schedule page
|
||||||
And I click the "Generate Schedule" button
|
And I click the "Generate Schedule" button
|
||||||
Then I should see "Generated"
|
Then I should see "Generated"
|
||||||
When I refresh the page
|
# Navigate away and back to verify schedule persisted
|
||||||
|
When I go to the tournament schedule page
|
||||||
Then I should see 5 rounds
|
Then I should see 5 rounds
|
||||||
And each team should play every other team exactly once
|
And each team should play every other team exactly once
|
||||||
|
|
||||||
@@ -41,6 +43,7 @@ Feature: Tournament Schedule
|
|||||||
When I go to the tournament schedule page
|
When I go to the tournament schedule page
|
||||||
And I click the "Generate Schedule" button
|
And I click the "Generate Schedule" button
|
||||||
Then I should see "Generated"
|
Then I should see "Generated"
|
||||||
When I refresh the page
|
# Navigate away and back to ensure schedule data is loaded
|
||||||
|
When I go to the tournament schedule page
|
||||||
And I click on a matchup
|
And I click on a matchup
|
||||||
Then I should be on the match result entry page
|
Then I should be on the match result entry page
|
||||||
|
|||||||
@@ -0,0 +1,46 @@
|
|||||||
|
Feature: View As Role
|
||||||
|
As a site admin
|
||||||
|
I want to temporarily view the site as a player or club admin
|
||||||
|
So that I can understand and improve the experience for each role
|
||||||
|
|
||||||
|
@happy-path @admin-features @issue-15
|
||||||
|
Scenario: Site admin sees role switcher in navigation
|
||||||
|
Given I am logged in as a site admin
|
||||||
|
When I view the navigation
|
||||||
|
Then I should see the role switcher dropdown
|
||||||
|
Then the role switcher should default to "Viewing as Site Admin"
|
||||||
|
|
||||||
|
@happy-path @admin-features @issue-15
|
||||||
|
Scenario: Site admin switches to player view
|
||||||
|
Given I am logged in as a site admin
|
||||||
|
When I select "View as Player" from the role switcher
|
||||||
|
Then I should see the player navigation links
|
||||||
|
And I should not see the "Admin" link
|
||||||
|
And I should not see the "Users" link
|
||||||
|
And I should see a banner indicating I am viewing as "Player"
|
||||||
|
|
||||||
|
@happy-path @admin-features @issue-15
|
||||||
|
Scenario: Site admin switches to tournament admin view
|
||||||
|
Given I am logged in as a site admin
|
||||||
|
When I select "View as Tournament Admin" from the role switcher
|
||||||
|
Then I should see the "Tournaments" link
|
||||||
|
And I should not see the "Admin" link
|
||||||
|
And I should not see the "Users" link
|
||||||
|
And I should see a banner indicating I am viewing as "Tournament Admin"
|
||||||
|
|
||||||
|
@happy-path @admin-features @issue-15
|
||||||
|
Scenario: Site admin switches to club admin view
|
||||||
|
Given I am logged in as a site admin
|
||||||
|
When I select "View as Club Admin" from the role switcher
|
||||||
|
Then I should see the "Admin" link
|
||||||
|
And I should see the "Users" link
|
||||||
|
And I should see a banner indicating I am viewing as "Club Admin"
|
||||||
|
|
||||||
|
@happy-path @admin-features @issue-15
|
||||||
|
Scenario: Site admin resets to site admin view
|
||||||
|
Given I am logged in as a site admin
|
||||||
|
When I select "View as Player" from the role switcher
|
||||||
|
And I click the "Reset to Site Admin" button
|
||||||
|
Then the role switcher should default to "Viewing as Site Admin"
|
||||||
|
And I should see the "Admin" link
|
||||||
|
And I should not see the viewing as banner
|
||||||
@@ -158,6 +158,58 @@ Given('I am logged in as a tournament admin', async function () {
|
|||||||
console.log(`🌍 User created: ${credentials.email}`);
|
console.log(`🌍 User created: ${credentials.email}`);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Precondition: I am logged in as a site admin
|
||||||
|
* Creates a new user and assigns site_admin role via Prisma
|
||||||
|
*/
|
||||||
|
Given('I am logged in as a site admin', async function () {
|
||||||
|
console.log('🌍 Creating and logging in as a site admin...');
|
||||||
|
|
||||||
|
const credentials = generateTestCredentials();
|
||||||
|
world.user = credentials;
|
||||||
|
|
||||||
|
await world.page.goto(`${world.baseURL}/auth/register`);
|
||||||
|
await world.page.waitForLoadState('domcontentloaded');
|
||||||
|
|
||||||
|
await world.page.fill('input[name="name"]', credentials.name);
|
||||||
|
await world.page.fill('input[name="email"]', credentials.email);
|
||||||
|
await world.page.fill('input[name="password"]', credentials.password);
|
||||||
|
|
||||||
|
await world.page.click('button[type="submit"]');
|
||||||
|
await world.page.waitForURL(/\/players\/\d+\/profile/, { timeout: 15000 });
|
||||||
|
|
||||||
|
const currentUrl = world.page.url();
|
||||||
|
const match = currentUrl.match(/\/players\/(\d+)\/profile/);
|
||||||
|
if (match) {
|
||||||
|
const playerId = match[1];
|
||||||
|
world.playerId = playerId;
|
||||||
|
|
||||||
|
const prisma = await world.getPrisma();
|
||||||
|
const player = await prisma.player.findUnique({
|
||||||
|
where: { id: parseInt(playerId) },
|
||||||
|
include: { user: true }
|
||||||
|
});
|
||||||
|
|
||||||
|
if (player && player.user) {
|
||||||
|
const userId = player.user.id;
|
||||||
|
(world.user as any).id = userId;
|
||||||
|
|
||||||
|
await prisma.user.update({
|
||||||
|
where: { id: userId },
|
||||||
|
data: { role: 'site_admin' }
|
||||||
|
});
|
||||||
|
console.log(`🌍 Assigned site_admin role to user: ${userId}`);
|
||||||
|
|
||||||
|
// Navigate to home page to trigger Navigation re-mount with new role
|
||||||
|
await world.page.goto(`${world.baseURL}/`);
|
||||||
|
await world.page.waitForLoadState('networkidle');
|
||||||
|
await world.page.waitForTimeout(1000);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
console.log(`🌍 Site admin created: ${credentials.email}`);
|
||||||
|
});
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Precondition: I am logged in as a club admin
|
* Precondition: I am logged in as a club admin
|
||||||
* Uses a pre-existing admin user from the database
|
* Uses a pre-existing admin user from the database
|
||||||
@@ -359,16 +411,67 @@ When('I go to my schedule page', async function () {
|
|||||||
});
|
});
|
||||||
|
|
||||||
Given('I have upcoming matches in my schedule', async function () {
|
Given('I have upcoming matches in my schedule', async function () {
|
||||||
console.log('🌍 Note: This step requires database setup via API or UI');
|
console.log('🌍 Setting up upcoming matches in schedule');
|
||||||
console.log('🌍 For acceptance tests, this would be set up before running the test');
|
const prisma = await world.getPrisma();
|
||||||
// For true acceptance testing, we would:
|
const timestamp = Date.now();
|
||||||
// 1. Create a tournament
|
|
||||||
// 2. Add the player as a participant
|
|
||||||
// 3. Generate a schedule
|
|
||||||
// 4. The match would then appear in the player's schedule
|
|
||||||
|
|
||||||
// For now, this is a placeholder that indicates data setup is needed
|
// Get the current player
|
||||||
// In a real test run, this data would already exist in the dev database
|
if (!world.playerId) {
|
||||||
|
throw new Error('No player ID found. Make sure user is logged in as a player first.');
|
||||||
|
}
|
||||||
|
|
||||||
|
const currentPlayerId = parseInt(world.playerId, 10);
|
||||||
|
|
||||||
|
// Create 3 other players for the match
|
||||||
|
const opponent1 = await prisma.player.create({
|
||||||
|
data: {
|
||||||
|
name: `Opponent ${timestamp} 1`,
|
||||||
|
normalizedName: `opponent ${timestamp} 1`,
|
||||||
|
currentElo: 1000,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
const opponent2 = await prisma.player.create({
|
||||||
|
data: {
|
||||||
|
name: `Opponent ${timestamp} 2`,
|
||||||
|
normalizedName: `opponent ${timestamp} 2`,
|
||||||
|
currentElo: 1000,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
const partner1 = await prisma.player.create({
|
||||||
|
data: {
|
||||||
|
name: `Partner ${timestamp}`,
|
||||||
|
normalizedName: `partner ${timestamp}`,
|
||||||
|
currentElo: 1000,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
// Create a tournament
|
||||||
|
const tournament = await prisma.event.create({
|
||||||
|
data: {
|
||||||
|
name: `Test Schedule Tournament ${timestamp}`,
|
||||||
|
eventDate: new Date(Date.now() + 86400000), // Tomorrow
|
||||||
|
status: 'planned',
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
// Create a match with the current player as player1P1 (played tomorrow)
|
||||||
|
await prisma.match.create({
|
||||||
|
data: {
|
||||||
|
eventId: tournament.id,
|
||||||
|
player1P1Id: currentPlayerId,
|
||||||
|
player1P2Id: partner1.id,
|
||||||
|
player2P1Id: opponent1.id,
|
||||||
|
player2P2Id: opponent2.id,
|
||||||
|
team1Score: 10,
|
||||||
|
team2Score: 5,
|
||||||
|
status: 'completed',
|
||||||
|
playedAt: new Date(Date.now() + 86400000), // Tomorrow
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
console.log(`🌍 Created tournament "${tournament.name}" with 1 match for player ${currentPlayerId}`);
|
||||||
});
|
});
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -396,8 +499,10 @@ Given('a tournament exists with {int} teams', async function (teamCount: number)
|
|||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
// Create players and add them as participants
|
// Euchre is 2v2, so each team has 2 players
|
||||||
for (let i = 1; i <= teamCount; i++) {
|
// Create teamCount * 2 players and add them as participants
|
||||||
|
const playerCount = teamCount * 2;
|
||||||
|
for (let i = 1; i <= playerCount; i++) {
|
||||||
const player = await prisma.player.create({
|
const player = await prisma.player.create({
|
||||||
data: {
|
data: {
|
||||||
name: `Tournament Player ${i} ${timestamp}`,
|
name: `Tournament Player ${i} ${timestamp}`,
|
||||||
@@ -420,7 +525,7 @@ Given('a tournament exists with {int} teams', async function (teamCount: number)
|
|||||||
world.tournament = tournament;
|
world.tournament = tournament;
|
||||||
world.tournamentTeamCount = teamCount;
|
world.tournamentTeamCount = teamCount;
|
||||||
|
|
||||||
console.log(`🌍 Created tournament: ${tournament.name} (ID: ${tournament.id}) with ${teamCount} teams`);
|
console.log(`🌍 Created tournament: ${tournament.name} (ID: ${tournament.id}) with ${playerCount} players (${teamCount} teams)`);
|
||||||
});
|
});
|
||||||
|
|
||||||
When('I go to the tournament schedule page', async function () {
|
When('I go to the tournament schedule page', async function () {
|
||||||
|
|||||||
@@ -29,6 +29,12 @@ Given('I am on the login page', async function () {
|
|||||||
await world.page.waitForLoadState('domcontentloaded');
|
await world.page.waitForLoadState('domcontentloaded');
|
||||||
});
|
});
|
||||||
|
|
||||||
|
Given('I am on the password reset page', async function () {
|
||||||
|
console.log('🌍 Navigating to password reset page');
|
||||||
|
await world.page.goto(`${world.baseURL}/auth/password-reset`);
|
||||||
|
await world.page.waitForLoadState('domcontentloaded');
|
||||||
|
});
|
||||||
|
|
||||||
Given('I am on the {string} page', async function (pageName: string) {
|
Given('I am on the {string} page', async function (pageName: string) {
|
||||||
const pageUrls: Record<string, string> = {
|
const pageUrls: Record<string, string> = {
|
||||||
'home': '/',
|
'home': '/',
|
||||||
@@ -180,28 +186,18 @@ When('I click the {string} link', async function (linkText: string) {
|
|||||||
const selector = `a:has-text("${linkText}")`;
|
const selector = `a:has-text("${linkText}")`;
|
||||||
console.log(`🌍 Clicking link: ${linkText}`);
|
console.log(`🌍 Clicking link: ${linkText}`);
|
||||||
|
|
||||||
// Get current URL
|
|
||||||
const currentUrl = world.page.url();
|
|
||||||
|
|
||||||
// Click the link
|
// Click the link
|
||||||
await world.page.click(selector);
|
await world.page.click(selector);
|
||||||
|
|
||||||
// Wait a bit for navigation to start
|
// Wait for navigation to complete
|
||||||
await world.page.waitForTimeout(500);
|
try {
|
||||||
|
await world.page.waitForLoadState('networkidle', { timeout: 10000 });
|
||||||
// Check if URL changed
|
} catch {
|
||||||
const newUrl = world.page.url();
|
console.log(`🌍 Networkidle not reached, continuing`);
|
||||||
if (newUrl === currentUrl) {
|
|
||||||
console.log(`🌍 URL did not change immediately after link click`);
|
|
||||||
// Wait for any navigation to complete
|
|
||||||
try {
|
|
||||||
await world.page.waitForLoadState('domcontentloaded', { timeout: 5000 });
|
|
||||||
} catch {
|
|
||||||
console.log(`🌍 DOMContentLoaded not reached, continuing`);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
console.log(`🌍 Page navigated to: ${newUrl}`);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const newUrl = world.page.url();
|
||||||
|
console.log(`🌍 Page navigated to: ${newUrl}`);
|
||||||
});
|
});
|
||||||
|
|
||||||
When('I click the {string} wordmark', async function (wordmarkText: string) {
|
When('I click the {string} wordmark', async function (wordmarkText: string) {
|
||||||
@@ -606,10 +602,51 @@ Then('I should see the rankings table', async function () {
|
|||||||
console.log('🌍 Verified rankings table is visible');
|
console.log('🌍 Verified rankings table is visible');
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// Player Schedule Steps
|
||||||
|
Then('I should see the match date', async function () {
|
||||||
|
const content = await world.page.content();
|
||||||
|
const hasDate = content.match(/\d{1,2}\/\d{1,2}\/\d{4}/) || content.match(/\w+ \d{1,2}, \d{4}/);
|
||||||
|
expect(hasDate).toBeTruthy();
|
||||||
|
console.log('🌍 Verified match date is visible');
|
||||||
|
});
|
||||||
|
|
||||||
|
Then('I should see my opponent\'s name', async function () {
|
||||||
|
const content = await world.page.content();
|
||||||
|
const hasOpponent = content.includes('Opponent');
|
||||||
|
expect(hasOpponent).toBe(true);
|
||||||
|
console.log('🌍 Verified opponent name is visible');
|
||||||
|
});
|
||||||
|
|
||||||
|
Then('I should see my partner\'s name', async function () {
|
||||||
|
const content = await world.page.content();
|
||||||
|
const hasPartner = content.includes('Partner');
|
||||||
|
expect(hasPartner).toBe(true);
|
||||||
|
console.log('🌍 Verified partner name is visible');
|
||||||
|
});
|
||||||
|
|
||||||
|
Then('I should see the tournament name', async function () {
|
||||||
|
const content = await world.page.content();
|
||||||
|
const hasTournament = content.includes('Test Schedule Tournament');
|
||||||
|
expect(hasTournament).toBe(true);
|
||||||
|
console.log('🌍 Verified tournament name is visible');
|
||||||
|
});
|
||||||
|
|
||||||
|
When('I click on a match', async function () {
|
||||||
|
const matchLink = world.page.locator('a[href*="/matches/"]').first();
|
||||||
|
await matchLink.click();
|
||||||
|
await world.page.waitForLoadState('domcontentloaded');
|
||||||
|
console.log('🌍 Clicked on match');
|
||||||
|
});
|
||||||
|
|
||||||
|
Then('I should be on the match detail page', async function () {
|
||||||
|
const currentUrl = world.page.url();
|
||||||
|
console.log(`🌍 Checking current URL: ${currentUrl}`);
|
||||||
|
expect(currentUrl).toMatch(/\/matches\/\d+/);
|
||||||
|
});
|
||||||
|
|
||||||
// Tournament Schedule Steps
|
// Tournament Schedule Steps
|
||||||
Then('I should see round {int} matchups', async function (roundNumber: number) {
|
Then('I should see round {int} matchups', async function (roundNumber: number) {
|
||||||
const roundText = `Round ${roundNumber}`;
|
const roundText = `Round ${roundNumber}`;
|
||||||
// Wait a bit for content to load
|
|
||||||
await world.page.waitForTimeout(2000);
|
await world.page.waitForTimeout(2000);
|
||||||
const content = await world.page.content();
|
const content = await world.page.content();
|
||||||
console.log(`🌍 Page URL: ${world.page.url()}`);
|
console.log(`🌍 Page URL: ${world.page.url()}`);
|
||||||
@@ -627,20 +664,25 @@ Then('I should see {int} rounds', async function (expectedRounds: number) {
|
|||||||
});
|
});
|
||||||
|
|
||||||
Then('each team should play every other team exactly once', async function () {
|
Then('each team should play every other team exactly once', async function () {
|
||||||
// This is a complex verification that would require counting matchups
|
|
||||||
// For now, just verify that the schedule was generated
|
|
||||||
const content = await world.page.content();
|
const content = await world.page.content();
|
||||||
expect(content).toMatch(/schedule|round|matchup/i);
|
expect(content).toMatch(/schedule|round|matchup/i);
|
||||||
console.log('🌍 Verified schedule exists with matchups');
|
console.log('🌍 Verified schedule exists with matchups');
|
||||||
});
|
});
|
||||||
|
|
||||||
When('I click on a matchup', async function () {
|
When('I click on a matchup', async function () {
|
||||||
// Wait for the matchup elements to be visible after potential page reload
|
|
||||||
const matchup = world.page.locator('[data-testid="matchup"]').first();
|
const matchup = world.page.locator('[data-testid="matchup"]').first();
|
||||||
await matchup.waitFor({ state: 'visible', timeout: 15000 });
|
await matchup.waitFor({ state: 'visible', timeout: 15000 });
|
||||||
await matchup.click();
|
|
||||||
|
const href = await matchup.getAttribute('href');
|
||||||
|
console.log(`🌍 Matchup link href: ${href}`);
|
||||||
|
|
||||||
|
if (href) {
|
||||||
|
await world.page.goto(`${world.baseURL}${href}`);
|
||||||
|
} else {
|
||||||
|
await matchup.click();
|
||||||
|
}
|
||||||
await world.page.waitForLoadState('domcontentloaded');
|
await world.page.waitForLoadState('domcontentloaded');
|
||||||
console.log('🌍 Clicked on matchup');
|
console.log(`🌍 Navigated to: ${world.page.url()}`);
|
||||||
});
|
});
|
||||||
|
|
||||||
Then('I should be on the match result entry page', async function () {
|
Then('I should be on the match result entry page', async function () {
|
||||||
@@ -648,3 +690,102 @@ Then('I should be on the match result entry page', async function () {
|
|||||||
console.log(`🌍 Checking current URL: ${currentUrl}`);
|
console.log(`🌍 Checking current URL: ${currentUrl}`);
|
||||||
expect(currentUrl).toMatch(/\/matches\/|\/admin\/tournaments\/\d+\/(entry|results)/);
|
expect(currentUrl).toMatch(/\/matches\/|\/admin\/tournaments\/\d+\/(entry|results)/);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// View As Role Steps
|
||||||
|
When('I view the navigation', async function () {
|
||||||
|
await world.page.waitForLoadState('networkidle');
|
||||||
|
await world.page.waitForTimeout(1000);
|
||||||
|
console.log('🌍 Viewing navigation');
|
||||||
|
});
|
||||||
|
|
||||||
|
Then('I should see the role switcher dropdown', async function () {
|
||||||
|
const switcher = world.page.locator('[data-testid="role-switcher"]');
|
||||||
|
await expect(switcher).toBeVisible({ timeout: 5000 });
|
||||||
|
console.log('🌍 Verified role switcher dropdown is visible');
|
||||||
|
});
|
||||||
|
|
||||||
|
Then('the role switcher should default to {string}', async function (expectedText: string) {
|
||||||
|
const switcher = world.page.locator('[data-testid="role-switcher"]');
|
||||||
|
const selectedValue = await switcher.inputValue();
|
||||||
|
const selectedText = await switcher.locator('option:checked').textContent();
|
||||||
|
console.log(`🌍 Dropdown selected text: "${selectedText}", value: "${selectedValue}"`);
|
||||||
|
expect(selectedText?.trim()).toBe(expectedText);
|
||||||
|
});
|
||||||
|
|
||||||
|
When('I select {string} from the role switcher', async function (optionText: string) {
|
||||||
|
const switcher = world.page.locator('[data-testid="role-switcher"]');
|
||||||
|
await switcher.selectOption({ label: optionText });
|
||||||
|
await world.page.waitForTimeout(500);
|
||||||
|
console.log(`🌍 Selected "${optionText}" from role switcher`);
|
||||||
|
});
|
||||||
|
|
||||||
|
Then('I should see the player navigation links', async function () {
|
||||||
|
await expect(world.page.locator('nav a:has-text("Rankings")')).toBeVisible();
|
||||||
|
await expect(world.page.locator('nav a:has-text("Tournaments")')).toBeVisible();
|
||||||
|
console.log('🌍 Verified player navigation links are visible');
|
||||||
|
});
|
||||||
|
|
||||||
|
Then('I should not see the {string} link', async function (linkText: string) {
|
||||||
|
const link = world.page.locator(`nav a:has-text("${linkText}")`);
|
||||||
|
await expect(link).not.toBeVisible({ timeout: 3000 });
|
||||||
|
console.log(`🌍 Verified "${linkText}" nav link is not visible`);
|
||||||
|
});
|
||||||
|
|
||||||
|
Then('I should see the {string} link', async function (linkText: string) {
|
||||||
|
const link = world.page.locator(`nav a:has-text("${linkText}")`);
|
||||||
|
await expect(link).toBeVisible({ timeout: 5000 });
|
||||||
|
console.log(`🌍 Verified "${linkText}" nav link is visible`);
|
||||||
|
});
|
||||||
|
|
||||||
|
Then('I should see a banner indicating I am viewing as {string}', async function (roleName: string) {
|
||||||
|
const banner = world.page.locator(`text=Viewing as ${roleName}`);
|
||||||
|
await expect(banner).toBeVisible({ timeout: 5000 });
|
||||||
|
console.log(`🌍 Verified viewing as ${roleName} banner is visible`);
|
||||||
|
});
|
||||||
|
|
||||||
|
Then('I should not see the viewing as banner', async function () {
|
||||||
|
const banner = world.page.locator('[data-testid="reset-view-as"]');
|
||||||
|
await expect(banner).not.toBeVisible({ timeout: 3000 });
|
||||||
|
console.log('🌍 Verified viewing as banner is not visible');
|
||||||
|
});
|
||||||
|
|
||||||
|
// Bracket Visualization Steps
|
||||||
|
When('I go to the tournament detail page', async function () {
|
||||||
|
const tournamentId = world.tournament?.id || 1;
|
||||||
|
await world.page.goto(`${world.baseURL}/admin/tournaments/${tournamentId}`);
|
||||||
|
await world.page.waitForLoadState('networkidle');
|
||||||
|
await world.page.waitForTimeout(500);
|
||||||
|
console.log(`🌍 Navigated to tournament detail page: ${tournamentId}`);
|
||||||
|
});
|
||||||
|
|
||||||
|
When('I click the {string} tab', async function (tabName: string) {
|
||||||
|
const tab = world.page.locator(`button:has-text("${tabName}")`);
|
||||||
|
await tab.click();
|
||||||
|
await world.page.waitForTimeout(500);
|
||||||
|
console.log(`🌍 Clicked "${tabName}" tab`);
|
||||||
|
});
|
||||||
|
|
||||||
|
Then('I should see bracket matchup cards', async function () {
|
||||||
|
const cards = world.page.locator('[data-testid="bracket-matchup"]');
|
||||||
|
const count = await cards.count();
|
||||||
|
expect(count).toBeGreaterThan(0);
|
||||||
|
console.log(`🌍 Found ${count} bracket matchup cards`);
|
||||||
|
});
|
||||||
|
|
||||||
|
Then('I should see bracket matchup cards with team names', async function () {
|
||||||
|
const cards = world.page.locator('[data-testid="bracket-matchup"]');
|
||||||
|
const count = await cards.count();
|
||||||
|
expect(count).toBeGreaterThan(0);
|
||||||
|
|
||||||
|
const firstCard = cards.first();
|
||||||
|
const text = await firstCard.textContent();
|
||||||
|
expect(text).toBeTruthy();
|
||||||
|
expect(text!.length).toBeGreaterThan(2);
|
||||||
|
console.log(`🌍 Verified bracket matchup cards have team names`);
|
||||||
|
});
|
||||||
|
|
||||||
|
Then('I should not see the {string} tab', async function (tabName: string) {
|
||||||
|
const tab = world.page.locator(`button:has-text("${tabName}")`);
|
||||||
|
await expect(tab).not.toBeVisible({ timeout: 3000 });
|
||||||
|
console.log(`🌍 Verified "${tabName}" tab is not visible`);
|
||||||
|
});
|
||||||
|
|||||||
+1
-1
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "euchre_camp",
|
"name": "euchre_camp",
|
||||||
"version": "0.1.12",
|
"version": "0.1.16",
|
||||||
"private": true,
|
"private": true,
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"dev": "NEXT_PUBLIC_GIT_COMMIT=$(git rev-parse --short HEAD) next dev",
|
"dev": "NEXT_PUBLIC_GIT_COMMIT=$(git rev-parse --short HEAD) next dev",
|
||||||
|
|||||||
@@ -7,6 +7,7 @@ import Navigation from "@/components/Navigation"
|
|||||||
import TeamsSection from "@/components/TeamsSection"
|
import TeamsSection from "@/components/TeamsSection"
|
||||||
import { DeleteTournamentButton } from "@/components/DeleteTournamentButton"
|
import { DeleteTournamentButton } from "@/components/DeleteTournamentButton"
|
||||||
import { ScheduleGenerator } from "@/components/ScheduleGenerator"
|
import { ScheduleGenerator } from "@/components/ScheduleGenerator"
|
||||||
|
import { BracketVisualization } from "@/components/BracketVisualization"
|
||||||
import MatchEditor from "@/components/MatchEditor"
|
import MatchEditor from "@/components/MatchEditor"
|
||||||
|
|
||||||
interface PageProps {
|
interface PageProps {
|
||||||
@@ -420,6 +421,11 @@ export default function TournamentDetailPage({ params }: PageProps) {
|
|||||||
</div>
|
</div>
|
||||||
)
|
)
|
||||||
|
|
||||||
|
case "bracket":
|
||||||
|
return (
|
||||||
|
<BracketVisualization rounds={rounds} />
|
||||||
|
)
|
||||||
|
|
||||||
default:
|
default:
|
||||||
return null
|
return null
|
||||||
}
|
}
|
||||||
@@ -555,6 +561,18 @@ export default function TournamentDetailPage({ params }: PageProps) {
|
|||||||
>
|
>
|
||||||
Results
|
Results
|
||||||
</button>
|
</button>
|
||||||
|
{hasSchedule && (
|
||||||
|
<button
|
||||||
|
onClick={() => setActiveTab("bracket")}
|
||||||
|
className={`whitespace-nowrap py-4 px-1 border-b-2 font-medium text-sm ${
|
||||||
|
activeTab === "bracket"
|
||||||
|
? "border-green-500 text-green-600"
|
||||||
|
: "border-transparent text-gray-500 hover:text-gray-700 hover:border-gray-300"
|
||||||
|
}`}
|
||||||
|
>
|
||||||
|
Bracket
|
||||||
|
</button>
|
||||||
|
)}
|
||||||
<span className="border-transparent text-gray-400 whitespace-nowrap py-4 px-1 border-b-2 font-medium text-sm cursor-not-allowed">
|
<span className="border-transparent text-gray-400 whitespace-nowrap py-4 px-1 border-b-2 font-medium text-sm cursor-not-allowed">
|
||||||
Analytics
|
Analytics
|
||||||
</span>
|
</span>
|
||||||
|
|||||||
@@ -89,7 +89,7 @@ export default async function TournamentSchedulePage({ params }: PageProps) {
|
|||||||
|
|
||||||
<div id="schedule-display">
|
<div id="schedule-display">
|
||||||
{existingRounds > 0 ? (
|
{existingRounds > 0 ? (
|
||||||
<ScheduleDisplay rounds={tournament.rounds} />
|
<ScheduleDisplay rounds={tournament.rounds} tournamentId={tournamentId} />
|
||||||
) : (
|
) : (
|
||||||
<p className="text-gray-500 mb-6">
|
<p className="text-gray-500 mb-6">
|
||||||
No schedule has been generated yet. Click "Generate Schedule" to create round matchups.
|
No schedule has been generated yet. Click "Generate Schedule" to create round matchups.
|
||||||
|
|||||||
@@ -0,0 +1,37 @@
|
|||||||
|
import { NextResponse } from "next/server";
|
||||||
|
import { prisma } from "@/lib/prisma";
|
||||||
|
|
||||||
|
export async function POST(request: Request) {
|
||||||
|
try {
|
||||||
|
const body = await request.json();
|
||||||
|
const { email } = body;
|
||||||
|
|
||||||
|
if (!email) {
|
||||||
|
return NextResponse.json(
|
||||||
|
{ error: "Email is required" },
|
||||||
|
{ status: 400 }
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
const user = await prisma.user.findUnique({
|
||||||
|
where: { email: email.toLowerCase() },
|
||||||
|
});
|
||||||
|
|
||||||
|
if (!user) {
|
||||||
|
return NextResponse.json(
|
||||||
|
{ error: "If an account exists with that email, a password reset link will be sent" },
|
||||||
|
{ status: 400 }
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
return NextResponse.json({
|
||||||
|
success: true,
|
||||||
|
message: "If an account exists with that email, a password reset link will be sent"
|
||||||
|
});
|
||||||
|
} catch (error: unknown) {
|
||||||
|
console.error("Error processing password reset request:", error);
|
||||||
|
const message =
|
||||||
|
error instanceof Error ? error.message : "Failed to process password reset request";
|
||||||
|
return NextResponse.json({ error: message }, { status: 500 });
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -175,8 +175,8 @@ export async function POST(_request: Request, { params }: RouteParams) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Calculate expected rounds
|
// Calculate expected rounds
|
||||||
const expectedRounds = expectedRounds(teamCount);
|
const numRounds = expectedRounds(teamCount);
|
||||||
console.log(`[Schedule API] Expected rounds: ${expectedRounds}`);
|
console.log(`[Schedule API] Expected rounds: ${numRounds}`);
|
||||||
|
|
||||||
if (teamDurability === "permanent") {
|
if (teamDurability === "permanent") {
|
||||||
// ============================================
|
// ============================================
|
||||||
@@ -285,7 +285,7 @@ export async function POST(_request: Request, { params }: RouteParams) {
|
|||||||
const schedule = generateVariableRoundRobin(
|
const schedule = generateVariableRoundRobin(
|
||||||
participants,
|
participants,
|
||||||
teamCount,
|
teamCount,
|
||||||
expectedRounds,
|
numRounds,
|
||||||
generateTeamWithRotation
|
generateTeamWithRotation
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|||||||
@@ -15,6 +15,22 @@ export default function PasswordResetPage() {
|
|||||||
setError("")
|
setError("")
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
const response = await fetch("/api/auth/password-reset", {
|
||||||
|
method: "POST",
|
||||||
|
headers: {
|
||||||
|
"Content-Type": "application/json",
|
||||||
|
},
|
||||||
|
body: JSON.stringify({ email }),
|
||||||
|
})
|
||||||
|
|
||||||
|
const data = await response.json()
|
||||||
|
|
||||||
|
if (!response.ok) {
|
||||||
|
setError(data.error || "Failed to send reset link")
|
||||||
|
setLoading(false)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
setSent(true)
|
setSent(true)
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
console.error("Password reset error:", err)
|
console.error("Password reset error:", err)
|
||||||
|
|||||||
+5
-2
@@ -1,6 +1,7 @@
|
|||||||
import type { Metadata } from "next";
|
import type { Metadata } from "next";
|
||||||
import "./globals.css";
|
import "./globals.css";
|
||||||
import { SessionProvider } from "@/components/SessionProvider";
|
import { SessionProvider } from "@/components/SessionProvider";
|
||||||
|
import { RoleSwitcherProvider } from "@/components/RoleSwitcher";
|
||||||
import Footer from "@/components/Footer";
|
import Footer from "@/components/Footer";
|
||||||
|
|
||||||
const inter = {
|
const inter = {
|
||||||
@@ -24,8 +25,10 @@ export default function RootLayout({
|
|||||||
>
|
>
|
||||||
<body className="min-h-full flex flex-col overflow-x-hidden">
|
<body className="min-h-full flex flex-col overflow-x-hidden">
|
||||||
<SessionProvider>
|
<SessionProvider>
|
||||||
{children}
|
<RoleSwitcherProvider>
|
||||||
<Footer />
|
{children}
|
||||||
|
<Footer />
|
||||||
|
</RoleSwitcherProvider>
|
||||||
</SessionProvider>
|
</SessionProvider>
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
|
|||||||
@@ -128,9 +128,10 @@ export default async function PlayerSchedulePage({ params }: PageProps) {
|
|||||||
].filter(Boolean).join(" + ")
|
].filter(Boolean).join(" + ")
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div
|
<Link
|
||||||
|
href={`/matches/${match.id}`}
|
||||||
key={match.id}
|
key={match.id}
|
||||||
className="border border-gray-200 rounded-lg p-4 hover:bg-gray-50"
|
className="block border border-gray-200 rounded-lg p-4 hover:bg-gray-50 cursor-pointer"
|
||||||
>
|
>
|
||||||
<div className="flex justify-between items-center">
|
<div className="flex justify-between items-center">
|
||||||
<div className="flex-1">
|
<div className="flex-1">
|
||||||
@@ -147,7 +148,7 @@ export default async function PlayerSchedulePage({ params }: PageProps) {
|
|||||||
</span>
|
</span>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</Link>
|
||||||
)
|
)
|
||||||
})}
|
})}
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -0,0 +1,168 @@
|
|||||||
|
"use client"
|
||||||
|
|
||||||
|
interface Player {
|
||||||
|
id: number
|
||||||
|
name: string
|
||||||
|
}
|
||||||
|
|
||||||
|
interface BracketMatchup {
|
||||||
|
id: number
|
||||||
|
roundId: number
|
||||||
|
player1P1: Player | null
|
||||||
|
player1P2: Player | null
|
||||||
|
player2P1: Player | null
|
||||||
|
player2P2: Player | null
|
||||||
|
match: { id: number; team1Score: number; team2Score: number } | null
|
||||||
|
bracketPosition: number | null
|
||||||
|
status: string
|
||||||
|
}
|
||||||
|
|
||||||
|
interface TournamentRound {
|
||||||
|
id: number
|
||||||
|
roundNumber: number
|
||||||
|
status: string
|
||||||
|
bracketMatchups: BracketMatchup[]
|
||||||
|
}
|
||||||
|
|
||||||
|
interface BracketVisualizationProps {
|
||||||
|
rounds: TournamentRound[]
|
||||||
|
}
|
||||||
|
|
||||||
|
export function BracketVisualization({ rounds }: BracketVisualizationProps) {
|
||||||
|
if (rounds.length === 0) {
|
||||||
|
return (
|
||||||
|
<div className="bg-white shadow rounded-lg p-6">
|
||||||
|
<p className="text-gray-500">No schedule generated yet. Generate a schedule to see the bracket.</p>
|
||||||
|
</div>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
const currentRoundIdx = rounds.findIndex(r => r.status === "in_progress")
|
||||||
|
const completedRounds = rounds.filter(r => r.status === "completed").length
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div className="bg-white shadow rounded-lg p-6">
|
||||||
|
<div className="flex items-center justify-between mb-6">
|
||||||
|
<h2 className="text-lg font-semibold text-gray-900">Tournament Bracket</h2>
|
||||||
|
<div className="flex items-center space-x-4 text-sm text-gray-500">
|
||||||
|
<span>{rounds.length} rounds</span>
|
||||||
|
<span>{completedRounds} completed</span>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div className="overflow-x-auto pb-4">
|
||||||
|
<div
|
||||||
|
className="inline-grid gap-4"
|
||||||
|
style={{
|
||||||
|
gridTemplateColumns: `repeat(${rounds.length}, minmax(200px, 1fr))`,
|
||||||
|
minWidth: `${rounds.length * 220}px`,
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
{rounds.map((round, roundIdx) => {
|
||||||
|
const isCurrent = roundIdx === currentRoundIdx
|
||||||
|
const isCompleted = round.status === "completed"
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div key={round.id} className="flex flex-col">
|
||||||
|
{/* Round Header */}
|
||||||
|
<div
|
||||||
|
className={`text-center py-2 px-3 rounded-t-lg font-medium text-sm ${
|
||||||
|
isCurrent
|
||||||
|
? "bg-green-100 text-green-800 border border-green-300"
|
||||||
|
: isCompleted
|
||||||
|
? "bg-gray-100 text-gray-600 border border-gray-200"
|
||||||
|
: "bg-gray-50 text-gray-500 border border-gray-200"
|
||||||
|
}`}
|
||||||
|
>
|
||||||
|
Round {round.roundNumber}
|
||||||
|
{isCurrent && (
|
||||||
|
<span className="ml-1 text-xs">(current)</span>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
|
||||||
|
{/* Matchups */}
|
||||||
|
<div className="flex flex-col gap-2 mt-2">
|
||||||
|
{round.bracketMatchups
|
||||||
|
.sort((a, b) => (a.bracketPosition || 0) - (b.bracketPosition || 0))
|
||||||
|
.map((matchup) => (
|
||||||
|
<MatchupCard key={matchup.id} matchup={matchup} isCurrentRound={isCurrent} />
|
||||||
|
))}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
)
|
||||||
|
})}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
function MatchupCard({ matchup, isCurrentRound }: { matchup: BracketMatchup; isCurrentRound: boolean }) {
|
||||||
|
const team1Name = matchup.player1P1 && matchup.player1P2
|
||||||
|
? `${matchup.player1P1.name.split(" ").pop()} & ${matchup.player1P2.name.split(" ").pop()}`
|
||||||
|
: "TBD"
|
||||||
|
const team2Name = matchup.player2P1 && matchup.player2P2
|
||||||
|
? `${matchup.player2P1.name.split(" ").pop()} & ${matchup.player2P2.name.split(" ").pop()}`
|
||||||
|
: "TBD"
|
||||||
|
|
||||||
|
const hasResult = matchup.match !== null
|
||||||
|
const team1Won = hasResult && matchup.match!.team1Score > matchup.match!.team2Score
|
||||||
|
const team2Won = hasResult && matchup.match!.team2Score > matchup.match!.team1Score
|
||||||
|
|
||||||
|
const borderColor = isCurrentRound
|
||||||
|
? "border-green-400"
|
||||||
|
: hasResult
|
||||||
|
? "border-gray-300"
|
||||||
|
: "border-gray-200"
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div
|
||||||
|
className={`border rounded-md p-2 text-xs transition-colors ${borderColor} ${
|
||||||
|
isCurrentRound ? "shadow-sm" : ""
|
||||||
|
}`}
|
||||||
|
data-testid="bracket-matchup"
|
||||||
|
>
|
||||||
|
{/* Team 1 */}
|
||||||
|
<div
|
||||||
|
className={`flex justify-between items-center py-1 px-1 ${
|
||||||
|
team1Won ? "font-semibold" : ""
|
||||||
|
}`}
|
||||||
|
>
|
||||||
|
<span className={`truncate ${team1Won ? "text-green-700" : "text-gray-700"}`}>
|
||||||
|
{team1Name}
|
||||||
|
</span>
|
||||||
|
{hasResult && (
|
||||||
|
<span className={`ml-1 font-mono ${team1Won ? "text-green-700" : "text-gray-500"}`}>
|
||||||
|
{matchup.match!.team1Score}
|
||||||
|
</span>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
|
||||||
|
{/* Divider */}
|
||||||
|
<div className="border-t border-gray-200 my-0.5" />
|
||||||
|
|
||||||
|
{/* Team 2 */}
|
||||||
|
<div
|
||||||
|
className={`flex justify-between items-center py-1 px-1 ${
|
||||||
|
team2Won ? "font-semibold" : ""
|
||||||
|
}`}
|
||||||
|
>
|
||||||
|
<span className={`truncate ${team2Won ? "text-green-700" : "text-gray-700"}`}>
|
||||||
|
{team2Name}
|
||||||
|
</span>
|
||||||
|
{hasResult && (
|
||||||
|
<span className={`ml-1 font-mono ${team2Won ? "text-green-700" : "text-gray-500"}`}>
|
||||||
|
{matchup.match!.team2Score}
|
||||||
|
</span>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
|
||||||
|
{/* Status indicator */}
|
||||||
|
{!hasResult && matchup.status === "pending" && (
|
||||||
|
<div className="text-center text-gray-400 text-[10px] mt-1">
|
||||||
|
pending
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
)
|
||||||
|
}
|
||||||
+138
-96
@@ -4,12 +4,13 @@ import Link from "next/link"
|
|||||||
import { useSession } from "./SessionProvider"
|
import { useSession } from "./SessionProvider"
|
||||||
import { authClient } from "@/lib/auth-client"
|
import { authClient } from "@/lib/auth-client"
|
||||||
import { useEffect, useState } from "react"
|
import { useEffect, useState } from "react"
|
||||||
|
import { useRoleSwitcher } from "./RoleSwitcher"
|
||||||
|
|
||||||
export default function Navigation() {
|
export default function Navigation() {
|
||||||
const { session, loading } = useSession()
|
const { session, loading } = useSession()
|
||||||
const [userRole, setUserRole] = useState<string | null>(null)
|
const [userRole, setUserRole] = useState<string | null>(null)
|
||||||
|
const { viewAsRole, setViewAsRole, effectiveRole } = useRoleSwitcher()
|
||||||
|
|
||||||
// Fetch user role whenever session changes
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
const fetchUserRole = async () => {
|
const fetchUserRole = async () => {
|
||||||
const userId = (session?.user as { id?: string })?.id
|
const userId = (session?.user as { id?: string })?.id
|
||||||
@@ -34,117 +35,158 @@ export default function Navigation() {
|
|||||||
}, [session])
|
}, [session])
|
||||||
|
|
||||||
const handleLogout = async () => {
|
const handleLogout = async () => {
|
||||||
|
setViewAsRole(null)
|
||||||
await authClient.signOut()
|
await authClient.signOut()
|
||||||
window.location.href = '/auth/login'
|
window.location.href = '/auth/login'
|
||||||
}
|
}
|
||||||
|
|
||||||
// Determine wordmark href based on session and role
|
const displayRole = effectiveRole || userRole
|
||||||
// If session exists but role is not yet loaded, use /rankings as default for players
|
const isSiteAdmin = userRole === "site_admin"
|
||||||
const wordmarkHref = session
|
|
||||||
? (userRole === "club_admin" || userRole === "site_admin")
|
const wordmarkHref = session
|
||||||
? "/admin"
|
? (displayRole === "club_admin" || displayRole === "site_admin")
|
||||||
|
? "/admin"
|
||||||
: "/rankings"
|
: "/rankings"
|
||||||
: "/";
|
: "/"
|
||||||
|
|
||||||
|
const roleLabels: Record<string, string> = {
|
||||||
|
player: "Player",
|
||||||
|
tournament_admin: "Tournament Admin",
|
||||||
|
club_admin: "Club Admin",
|
||||||
|
site_admin: "Site Admin",
|
||||||
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<nav className="bg-white shadow-sm">
|
<>
|
||||||
<div className="max-w-7xl mx-auto px-4 sm:px-6 lg:px-8">
|
{viewAsRole && (
|
||||||
<div className="flex justify-between h-16">
|
<div className="bg-yellow-50 border-b border-yellow-200 px-4 py-2">
|
||||||
<div className="flex items-center min-w-0 overflow-hidden">
|
<div className="max-w-7xl mx-auto flex items-center justify-between">
|
||||||
<Link
|
<p className="text-sm text-yellow-800">
|
||||||
href="/"
|
<span className="font-medium">Viewing as {roleLabels[viewAsRole]}</span>
|
||||||
className="text-xl font-bold text-gray-900 no-underline flex-shrink-0"
|
{" "}— you are seeing what a {roleLabels[viewAsRole]?.toLowerCase()} would see.
|
||||||
|
</p>
|
||||||
|
<button
|
||||||
|
onClick={() => setViewAsRole(null)}
|
||||||
|
className="text-sm font-medium text-yellow-800 hover:text-yellow-900 underline"
|
||||||
|
data-testid="reset-view-as"
|
||||||
>
|
>
|
||||||
EuchreCamp
|
Reset to Site Admin
|
||||||
</Link>
|
</button>
|
||||||
<div className="hidden md:ml-6 md:flex md:space-x-8 min-w-0 overflow-hidden">
|
</div>
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
<nav className="bg-white shadow-sm">
|
||||||
|
<div className="max-w-7xl mx-auto px-4 sm:px-6 lg:px-8">
|
||||||
|
<div className="flex justify-between h-16">
|
||||||
|
<div className="flex items-center min-w-0 overflow-hidden">
|
||||||
<Link
|
<Link
|
||||||
href="/rankings"
|
href="/"
|
||||||
className="border-transparent text-gray-500 hover:text-gray-700 inline-flex items-center px-1 pt-1 border-b-2 text-sm font-medium"
|
className="text-xl font-bold text-gray-900 no-underline flex-shrink-0"
|
||||||
>
|
>
|
||||||
Rankings
|
EuchreCamp
|
||||||
</Link>
|
</Link>
|
||||||
{session && (
|
<div className="hidden md:ml-6 md:flex md:space-x-8 min-w-0 overflow-hidden">
|
||||||
<>
|
<Link
|
||||||
<Link
|
href="/rankings"
|
||||||
href="/admin/tournaments"
|
className="border-transparent text-gray-500 hover:text-gray-700 inline-flex items-center px-1 pt-1 border-b-2 text-sm font-medium"
|
||||||
className="border-transparent text-gray-500 hover:text-gray-700 inline-flex items-center px-1 pt-1 border-b-2 text-sm font-medium"
|
>
|
||||||
|
Rankings
|
||||||
|
</Link>
|
||||||
|
{session && (
|
||||||
|
<>
|
||||||
|
<Link
|
||||||
|
href="/admin/tournaments"
|
||||||
|
className="border-transparent text-gray-500 hover:text-gray-700 inline-flex items-center px-1 pt-1 border-b-2 text-sm font-medium"
|
||||||
|
>
|
||||||
|
Tournaments
|
||||||
|
</Link>
|
||||||
|
{(displayRole === "club_admin" || displayRole === "site_admin") && (
|
||||||
|
<>
|
||||||
|
<Link
|
||||||
|
href="/admin"
|
||||||
|
className="border-transparent text-gray-500 hover:text-gray-700 inline-flex items-center px-1 pt-1 border-b-2 text-sm font-medium"
|
||||||
|
>
|
||||||
|
Admin
|
||||||
|
</Link>
|
||||||
|
<Link
|
||||||
|
href="/admin/matches"
|
||||||
|
className="border-transparent text-gray-500 hover:text-gray-700 inline-flex items-center px-1 pt-1 border-b-2 text-sm font-medium"
|
||||||
|
>
|
||||||
|
Matches
|
||||||
|
</Link>
|
||||||
|
<Link
|
||||||
|
href="/admin/players"
|
||||||
|
className="border-transparent text-gray-500 hover:text-gray-700 inline-flex items-center px-1 pt-1 border-b-2 text-sm font-medium"
|
||||||
|
>
|
||||||
|
Players
|
||||||
|
</Link>
|
||||||
|
<Link
|
||||||
|
href="/admin/users"
|
||||||
|
className="border-transparent text-gray-500 hover:text-gray-700 inline-flex items-center px-1 pt-1 border-b-2 text-sm font-medium"
|
||||||
|
>
|
||||||
|
Users
|
||||||
|
</Link>
|
||||||
|
<Link
|
||||||
|
href="/admin/matches/upload"
|
||||||
|
className="border-transparent text-gray-500 hover:text-gray-700 inline-flex items-center px-1 pt-1 border-b-2 text-sm font-medium"
|
||||||
|
>
|
||||||
|
Upload Matches
|
||||||
|
</Link>
|
||||||
|
</>
|
||||||
|
)}
|
||||||
|
</>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div className="flex items-center min-w-0 overflow-hidden space-x-4">
|
||||||
|
{isSiteAdmin && (
|
||||||
|
<select
|
||||||
|
value={viewAsRole || ""}
|
||||||
|
onChange={(e) => setViewAsRole(e.target.value ? e.target.value as "player" | "tournament_admin" | "club_admin" : null)}
|
||||||
|
className="text-sm border border-gray-300 rounded-md px-2 py-1 bg-white text-gray-700 focus:outline-none focus:ring-green-500 focus:border-green-500"
|
||||||
|
data-testid="role-switcher"
|
||||||
|
>
|
||||||
|
<option value="">Viewing as Site Admin</option>
|
||||||
|
<option value="player">View as Player</option>
|
||||||
|
<option value="tournament_admin">View as Tournament Admin</option>
|
||||||
|
<option value="club_admin">View as Club Admin</option>
|
||||||
|
</select>
|
||||||
|
)}
|
||||||
|
{loading ? (
|
||||||
|
<div className="text-gray-500">Loading...</div>
|
||||||
|
) : session ? (
|
||||||
|
<div className="flex items-center space-x-4">
|
||||||
|
<span className="text-gray-700 text-sm font-medium">
|
||||||
|
{(session.user as { name?: string; email?: string })?.name ||
|
||||||
|
(session.user as { name?: string; email?: string })?.email}
|
||||||
|
</span>
|
||||||
|
<button
|
||||||
|
onClick={handleLogout}
|
||||||
|
className="text-gray-500 hover:text-gray-700 text-sm font-medium"
|
||||||
>
|
>
|
||||||
Tournaments
|
Sign out
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
) : (
|
||||||
|
<div className="flex items-center space-x-4">
|
||||||
|
<Link
|
||||||
|
href="/auth/login"
|
||||||
|
className="text-gray-500 hover:text-gray-700 text-sm font-medium"
|
||||||
|
>
|
||||||
|
Sign in
|
||||||
</Link>
|
</Link>
|
||||||
{(userRole === "club_admin" || userRole === "site_admin") && (
|
<Link
|
||||||
<>
|
href="/auth/register"
|
||||||
<Link
|
className="bg-green-600 text-white px-3 py-1 rounded-md text-sm font-medium hover:bg-green-700"
|
||||||
href="/admin"
|
>
|
||||||
className="border-transparent text-gray-500 hover:text-gray-700 inline-flex items-center px-1 pt-1 border-b-2 text-sm font-medium"
|
Sign up
|
||||||
>
|
</Link>
|
||||||
Admin
|
</div>
|
||||||
</Link>
|
|
||||||
<Link
|
|
||||||
href="/admin/matches"
|
|
||||||
className="border-transparent text-gray-500 hover:text-gray-700 inline-flex items-center px-1 pt-1 border-b-2 text-sm font-medium"
|
|
||||||
>
|
|
||||||
Matches
|
|
||||||
</Link>
|
|
||||||
<Link
|
|
||||||
href="/admin/players"
|
|
||||||
className="border-transparent text-gray-500 hover:text-gray-700 inline-flex items-center px-1 pt-1 border-b-2 text-sm font-medium"
|
|
||||||
>
|
|
||||||
Players
|
|
||||||
</Link>
|
|
||||||
<Link
|
|
||||||
href="/admin/users"
|
|
||||||
className="border-transparent text-gray-500 hover:text-gray-700 inline-flex items-center px-1 pt-1 border-b-2 text-sm font-medium"
|
|
||||||
>
|
|
||||||
Users
|
|
||||||
</Link>
|
|
||||||
<Link
|
|
||||||
href="/admin/matches/upload"
|
|
||||||
className="border-transparent text-gray-500 hover:text-gray-700 inline-flex items-center px-1 pt-1 border-b-2 text-sm font-medium"
|
|
||||||
>
|
|
||||||
Upload Matches
|
|
||||||
</Link>
|
|
||||||
</>
|
|
||||||
)}
|
|
||||||
</>
|
|
||||||
)}
|
)}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div className="flex items-center min-w-0 overflow-hidden">
|
|
||||||
{loading ? (
|
|
||||||
<div className="text-gray-500">Loading...</div>
|
|
||||||
) : session ? (
|
|
||||||
<div className="flex items-center space-x-4">
|
|
||||||
<span className="text-gray-700 text-sm font-medium">
|
|
||||||
{(session.user as { name?: string; email?: string })?.name ||
|
|
||||||
(session.user as { name?: string; email?: string })?.email}
|
|
||||||
</span>
|
|
||||||
<button
|
|
||||||
onClick={handleLogout}
|
|
||||||
className="text-gray-500 hover:text-gray-700 text-sm font-medium"
|
|
||||||
>
|
|
||||||
Sign out
|
|
||||||
</button>
|
|
||||||
</div>
|
|
||||||
) : (
|
|
||||||
<div className="flex items-center space-x-4">
|
|
||||||
<Link
|
|
||||||
href="/auth/login"
|
|
||||||
className="text-gray-500 hover:text-gray-700 text-sm font-medium"
|
|
||||||
>
|
|
||||||
Sign in
|
|
||||||
</Link>
|
|
||||||
<Link
|
|
||||||
href="/auth/register"
|
|
||||||
className="bg-green-600 text-white px-3 py-1 rounded-md text-sm font-medium hover:bg-green-700"
|
|
||||||
>
|
|
||||||
Sign up
|
|
||||||
</Link>
|
|
||||||
</div>
|
|
||||||
)}
|
|
||||||
</div>
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</nav>
|
||||||
</nav>
|
</>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,37 @@
|
|||||||
|
"use client"
|
||||||
|
|
||||||
|
import { createContext, useContext, useState, useCallback, ReactNode } from "react"
|
||||||
|
|
||||||
|
type ViewAsRole = "player" | "tournament_admin" | "club_admin" | null
|
||||||
|
|
||||||
|
interface RoleSwitcherContextType {
|
||||||
|
viewAsRole: ViewAsRole
|
||||||
|
setViewAsRole: (role: ViewAsRole) => void
|
||||||
|
effectiveRole: string | null
|
||||||
|
}
|
||||||
|
|
||||||
|
const RoleSwitcherContext = createContext<RoleSwitcherContextType | undefined>(undefined)
|
||||||
|
|
||||||
|
export function RoleSwitcherProvider({ children }: { children: ReactNode }) {
|
||||||
|
const [viewAsRole, setViewAsRole] = useState<ViewAsRole>(null)
|
||||||
|
|
||||||
|
const value = {
|
||||||
|
viewAsRole,
|
||||||
|
setViewAsRole: useCallback((role: ViewAsRole) => setViewAsRole(role), []),
|
||||||
|
effectiveRole: viewAsRole,
|
||||||
|
}
|
||||||
|
|
||||||
|
return (
|
||||||
|
<RoleSwitcherContext.Provider value={value}>
|
||||||
|
{children}
|
||||||
|
</RoleSwitcherContext.Provider>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
export function useRoleSwitcher() {
|
||||||
|
const context = useContext(RoleSwitcherContext)
|
||||||
|
if (!context) {
|
||||||
|
throw new Error("useRoleSwitcher must be used within RoleSwitcherProvider")
|
||||||
|
}
|
||||||
|
return context
|
||||||
|
}
|
||||||
@@ -25,74 +25,56 @@ interface TournamentRound {
|
|||||||
bracketMatchups: BracketMatchup[]
|
bracketMatchups: BracketMatchup[]
|
||||||
}
|
}
|
||||||
|
|
||||||
export function ScheduleDisplay({ rounds }: { rounds: TournamentRound[] }) {
|
interface ScheduleDisplayProps {
|
||||||
|
rounds: TournamentRound[]
|
||||||
|
tournamentId: number
|
||||||
|
}
|
||||||
|
|
||||||
|
export function ScheduleDisplay({ rounds, tournamentId }: ScheduleDisplayProps) {
|
||||||
return (
|
return (
|
||||||
<div className="space-y-6">
|
<div className="space-y-6">
|
||||||
{rounds.map((round) => (
|
{rounds.map((round) => (
|
||||||
<div key={round.id} className="border border-gray-200 rounded-lg p-4">
|
<div key={round.id} className="bg-white rounded-lg shadow p-4">
|
||||||
<h3 className="text-lg font-semibold text-gray-900 mb-3">
|
<div className="flex items-center justify-between mb-4">
|
||||||
Round {round.roundNumber}
|
<h3 className="text-lg font-semibold">Round {round.roundNumber}</h3>
|
||||||
<span className="ml-2 text-sm font-normal text-gray-500">
|
<span className={`text-sm px-2 py-1 rounded ${
|
||||||
({round.status})
|
round.status === 'completed' ? 'bg-green-100 text-green-800' : 'bg-gray-100 text-gray-600'
|
||||||
|
}`}>
|
||||||
|
{round.status}
|
||||||
</span>
|
</span>
|
||||||
</h3>
|
</div>
|
||||||
|
<div className="space-y-2">
|
||||||
<div className="space-y-3">
|
|
||||||
{round.bracketMatchups.map((matchup) => {
|
{round.bracketMatchups.map((matchup) => {
|
||||||
const team1 = [
|
|
||||||
matchup.player1P1?.name,
|
|
||||||
matchup.player1P2?.name,
|
|
||||||
]
|
|
||||||
.filter(Boolean)
|
|
||||||
.join(" + ")
|
|
||||||
|
|
||||||
const team2 = [
|
|
||||||
matchup.player2P1?.name,
|
|
||||||
matchup.player2P2?.name,
|
|
||||||
]
|
|
||||||
.filter(Boolean)
|
|
||||||
.join(" + ")
|
|
||||||
|
|
||||||
const content = (
|
const content = (
|
||||||
<div className="flex items-center justify-between p-3 bg-gray-50 rounded-md">
|
<div className="p-3 border border-gray-200 rounded hover:border-green-500 transition-colors">
|
||||||
<div className="flex-1">
|
<div className="flex justify-between items-center">
|
||||||
<span className="font-medium text-gray-900">
|
<div className="flex-1">
|
||||||
{team1 || "TBD"}
|
<p className="text-sm text-gray-500">
|
||||||
</span>
|
Match {matchup.bracketPosition || matchup.id}
|
||||||
<span className="mx-3 text-gray-400">vs</span>
|
</p>
|
||||||
<span className="font-medium text-gray-900">
|
<p className="font-medium">
|
||||||
{team2 || "TBD"}
|
{matchup.player1P1?.name || 'TBD'} & {matchup.player1P2?.name || 'TBD'}
|
||||||
</span>
|
</p>
|
||||||
</div>
|
<p className="text-sm text-gray-500">vs</p>
|
||||||
<div className="text-sm text-gray-500">
|
<p className="font-medium">
|
||||||
{matchup.status === "pending" ? (
|
{matchup.player2P1?.name || 'TBD'} & {matchup.player2P2?.name || 'TBD'}
|
||||||
<span className="text-gray-400">Pending</span>
|
</p>
|
||||||
) : matchup.match ? (
|
</div>
|
||||||
<span className="text-green-600">Completed</span>
|
<div className="text-right">
|
||||||
) : (
|
{matchup.match ? (
|
||||||
<span className="text-gray-400">{matchup.status}</span>
|
<span className="text-sm text-green-600">Completed</span>
|
||||||
)}
|
) : (
|
||||||
|
<span className="text-sm text-gray-400">Pending</span>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
)
|
)
|
||||||
|
|
||||||
if (matchup.match) {
|
|
||||||
return (
|
|
||||||
<Link
|
|
||||||
key={matchup.id}
|
|
||||||
href={`/matches/${matchup.match.id}`}
|
|
||||||
className="block hover:bg-gray-100 rounded-md transition-colors"
|
|
||||||
data-testid="matchup"
|
|
||||||
>
|
|
||||||
{content}
|
|
||||||
</Link>
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Link
|
<Link
|
||||||
key={matchup.id}
|
key={matchup.id}
|
||||||
href={`/matches/new?matchup=${matchup.id}`}
|
href={`/admin/tournaments/${tournamentId}/entry?matchup=${matchup.id}`}
|
||||||
className="block hover:bg-gray-100 rounded-md transition-colors"
|
className="block hover:bg-gray-100 rounded-md transition-colors"
|
||||||
data-testid="matchup"
|
data-testid="matchup"
|
||||||
>
|
>
|
||||||
|
|||||||
Reference in New Issue
Block a user