chore: save WIP before workstation switch
This commit is contained in:
@@ -127,7 +127,7 @@ Given('I am logged in as a tournament admin', async function () {
|
||||
|
||||
// Wait for any redirect away from register page
|
||||
await world.page.waitForURL((url) => !url.toString().includes('/auth/register'), { timeout: 15000 });
|
||||
await world.page.waitForLoadState('networkidle');
|
||||
await world.page.waitForLoadState('domcontentloaded');
|
||||
await world.page.waitForTimeout(1000);
|
||||
|
||||
const currentUrl = world.page.url();
|
||||
@@ -166,7 +166,7 @@ Given('I am logged in as a tournament admin', async function () {
|
||||
|
||||
// Navigate to trigger a fresh role fetch
|
||||
await world.page.goto(`${world.baseURL}/rankings`);
|
||||
await world.page.waitForLoadState('networkidle');
|
||||
await world.page.waitForLoadState('domcontentloaded');
|
||||
await world.page.waitForTimeout(500);
|
||||
} else {
|
||||
console.log(`🌍 WARNING: User not found in DB by email. Trying to find latest user...`);
|
||||
@@ -235,7 +235,7 @@ Given('I am logged in as a site admin', async function () {
|
||||
|
||||
// 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.waitForLoadState('domcontentloaded');
|
||||
await world.page.waitForTimeout(1000);
|
||||
}
|
||||
}
|
||||
@@ -245,35 +245,53 @@ Given('I am logged in as a site admin', async function () {
|
||||
|
||||
/**
|
||||
* Precondition: I am logged in as a club admin
|
||||
* Uses a pre-existing admin user from the database
|
||||
* Creates a new user via UI and assigns club_admin role via Prisma
|
||||
*/
|
||||
Given('I am logged in as a club admin', async function () {
|
||||
console.log('🌍 Logging in as existing club admin...');
|
||||
console.log('🌍 Creating and logging in as a club admin...');
|
||||
|
||||
// Use the admin user created by seed.js
|
||||
const adminEmail = 'david@dhg.lol';
|
||||
const adminPassword = 'adminadmin';
|
||||
const credentials = generateTestCredentials();
|
||||
world.user = credentials;
|
||||
|
||||
world.user = {
|
||||
email: adminEmail,
|
||||
password: adminPassword,
|
||||
name: 'David Admin',
|
||||
};
|
||||
|
||||
await world.page.goto(`${world.baseURL}/auth/login`);
|
||||
await world.page.goto(`${world.baseURL}/auth/register`);
|
||||
await world.page.waitForLoadState('domcontentloaded');
|
||||
|
||||
await world.page.fill('input[name="email"]', adminEmail);
|
||||
await world.page.fill('input[name="password"]', adminPassword);
|
||||
await world.page.click('button[type="submit"]');
|
||||
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);
|
||||
|
||||
// Wait for redirect after login
|
||||
try {
|
||||
await world.page.waitForURL((url) => !url.toString().includes('/auth/login'), { timeout: 10000 });
|
||||
console.log(`🌍 Club admin logged in: ${adminEmail}`);
|
||||
} catch (e) {
|
||||
console.log('🌍 Login redirect timed out, current URL:', world.page.url());
|
||||
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: 'club_admin' }
|
||||
});
|
||||
console.log(`🌍 Assigned club_admin role to user: ${userId}`);
|
||||
|
||||
await world.page.goto(`${world.baseURL}/`);
|
||||
await world.page.waitForLoadState('domcontentloaded');
|
||||
await world.page.waitForTimeout(1000);
|
||||
}
|
||||
}
|
||||
|
||||
console.log(`🌍 Club admin created: ${credentials.email}`);
|
||||
});
|
||||
|
||||
/**
|
||||
@@ -566,7 +584,7 @@ When('I go to the tournament schedule page', async function () {
|
||||
const tournamentId = world.tournament?.id || 1;
|
||||
const url = `${world.baseURL}/admin/tournaments/${tournamentId}/schedule?t=${Date.now()}`;
|
||||
await world.page.goto(url);
|
||||
await world.page.waitForLoadState('networkidle');
|
||||
await world.page.waitForLoadState('domcontentloaded');
|
||||
// Wait for ScheduleDisplay client component to hydrate
|
||||
await world.page.waitForTimeout(2000);
|
||||
});
|
||||
|
||||
@@ -110,7 +110,7 @@ When('I go back', async function () {
|
||||
|
||||
When('I refresh the page', async function () {
|
||||
console.log('🌍 About to refresh page from URL:', world.page.url());
|
||||
await world.page.reload({ waitUntil: 'networkidle' });
|
||||
await world.page.reload({ waitUntil: 'load' });
|
||||
console.log('🌍 Page refreshed, new URL:', world.page.url());
|
||||
// Wait extra time for full render
|
||||
await world.page.waitForTimeout(2000);
|
||||
@@ -191,7 +191,7 @@ When('I click the {string} link', async function (linkText: string) {
|
||||
|
||||
// Wait for navigation to complete
|
||||
try {
|
||||
await world.page.waitForLoadState('networkidle', { timeout: 10000 });
|
||||
await world.page.waitForLoadState('domcontentloaded', { timeout: 10000 });
|
||||
} catch {
|
||||
console.log(`🌍 Networkidle not reached, continuing`);
|
||||
}
|
||||
@@ -653,7 +653,7 @@ Then('I should see round {int} matchups', async function (roundNumber: number) {
|
||||
});
|
||||
|
||||
Then('I should see {int} rounds', async function (expectedRounds: number) {
|
||||
await world.page.waitForLoadState('networkidle');
|
||||
await world.page.waitForLoadState('domcontentloaded');
|
||||
await world.page.waitForTimeout(2000);
|
||||
const roundHeaders = await world.page.locator('h3:has-text("Round")').count();
|
||||
expect(roundHeaders).toBe(expectedRounds);
|
||||
@@ -690,7 +690,7 @@ Then('I should be on the match result entry page', async function () {
|
||||
|
||||
// View As Role Steps
|
||||
When('I view the navigation', async function () {
|
||||
await world.page.waitForLoadState('networkidle');
|
||||
await world.page.waitForLoadState('domcontentloaded');
|
||||
await world.page.waitForTimeout(1000);
|
||||
console.log('🌍 Viewing navigation');
|
||||
});
|
||||
@@ -750,7 +750,7 @@ Then('I should not see the viewing as banner', async function () {
|
||||
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.waitForLoadState('domcontentloaded');
|
||||
await world.page.waitForTimeout(500);
|
||||
console.log(`🌍 Navigated to tournament detail page: ${tournamentId}`);
|
||||
});
|
||||
|
||||
@@ -0,0 +1,73 @@
|
||||
import { Given, After } from '@cucumber/cucumber';
|
||||
import { world } from '../support/world';
|
||||
|
||||
Given('there are top players in the system', async function () {
|
||||
const prisma = await world.getPrisma();
|
||||
const timestamp = Date.now();
|
||||
|
||||
for (let i = 0; i < 3; i++) {
|
||||
await prisma.player.create({
|
||||
data: {
|
||||
name: `Home Test Player ${timestamp} ${i + 1}`,
|
||||
normalizedName: `home_test_player_${timestamp}_${i + 1}`.toLowerCase(),
|
||||
currentElo: 2000 - i * 10,
|
||||
gamesPlayed: 10,
|
||||
wins: 7,
|
||||
},
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
Given('there is a club president', async function () {
|
||||
const prisma = await world.getPrisma();
|
||||
const timestamp = Date.now();
|
||||
|
||||
await prisma.user.create({
|
||||
data: {
|
||||
email: `president-${timestamp}@example.com`,
|
||||
name: `Club President ${timestamp}`,
|
||||
role: 'club_admin',
|
||||
},
|
||||
});
|
||||
});
|
||||
|
||||
Given('there is a recent tournament', async function () {
|
||||
const prisma = await world.getPrisma();
|
||||
const timestamp = Date.now();
|
||||
|
||||
const tournament = await prisma.event.create({
|
||||
data: {
|
||||
name: `Recent Tournament ${timestamp}`,
|
||||
eventType: 'tournament',
|
||||
eventDate: new Date(Date.now() + 86400000),
|
||||
status: 'completed',
|
||||
},
|
||||
});
|
||||
|
||||
const p1 = await prisma.player.create({
|
||||
data: { name: `HP1 ${timestamp}`, normalizedName: `hp1_${timestamp}`.toLowerCase(), currentElo: 1500 },
|
||||
});
|
||||
const p2 = await prisma.player.create({
|
||||
data: { name: `HP2 ${timestamp}`, normalizedName: `hp2_${timestamp}`.toLowerCase(), currentElo: 1480 },
|
||||
});
|
||||
const p3 = await prisma.player.create({
|
||||
data: { name: `HP3 ${timestamp}`, normalizedName: `hp3_${timestamp}`.toLowerCase(), currentElo: 1450 },
|
||||
});
|
||||
const p4 = await prisma.player.create({
|
||||
data: { name: `HP4 ${timestamp}`, normalizedName: `hp4_${timestamp}`.toLowerCase(), currentElo: 1420 },
|
||||
});
|
||||
|
||||
await prisma.match.create({
|
||||
data: {
|
||||
eventId: tournament.id,
|
||||
player1P1Id: p1.id,
|
||||
player1P2Id: p2.id,
|
||||
player2P1Id: p3.id,
|
||||
player2P2Id: p4.id,
|
||||
team1Score: 10,
|
||||
team2Score: 5,
|
||||
status: 'completed',
|
||||
playedAt: new Date(),
|
||||
},
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user