ui improvements
This commit is contained in:
220
tests/debug.spec.ts
Normal file
220
tests/debug.spec.ts
Normal file
@@ -0,0 +1,220 @@
|
||||
import { test, expect } from '@playwright/test';
|
||||
import { DP2FormPage } from './utils/page-objects';
|
||||
import { TestDataFactory } from './utils/test-data';
|
||||
|
||||
/**
|
||||
* Debug test to help identify issues with the DP2 calculator
|
||||
* This test captures screenshots and detailed logs for debugging
|
||||
*/
|
||||
test.describe('DP2 Calculator - Debug Tests', () => {
|
||||
let formPage: DP2FormPage;
|
||||
|
||||
test.beforeEach(async ({ page }) => {
|
||||
formPage = new DP2FormPage(page);
|
||||
await formPage.goto();
|
||||
await page.screenshot({ path: `debug-screenshots/initial-load.png` });
|
||||
});
|
||||
|
||||
test('debug theft calculation - step by step', async ({ page }) => {
|
||||
console.log('=== Starting Theft Debug Test ===');
|
||||
|
||||
// Fill basic info
|
||||
await formPage.fillPlayerInfo('DebugPlayer', 0);
|
||||
await page.screenshot({ path: `debug-screenshots/01-basic-info-filled.png` });
|
||||
|
||||
// Select theft
|
||||
await formPage.selectCrimeCategory('item');
|
||||
await formPage.selectSpecificOffense('theft');
|
||||
await page.screenshot({ path: `debug-screenshots/02-theft-selected.png` });
|
||||
|
||||
// Check if special items section is visible
|
||||
const specialItemsVisible = await formPage.specialItems.elytra.isVisible();
|
||||
console.log('Special items section visible:', specialItemsVisible);
|
||||
|
||||
// Fill special items
|
||||
await formPage.fillSpecialItems({
|
||||
elytra: 1,
|
||||
netherStar: 0,
|
||||
beacon: 0,
|
||||
netheriteBlock: 0,
|
||||
diamondBlock: 0
|
||||
});
|
||||
await page.screenshot({ path: `debug-screenshots/03-special-items-filled.png` });
|
||||
|
||||
// Add additional items
|
||||
await formPage.addAdditionalItem('diamond', 10);
|
||||
await page.screenshot({ path: `debug-screenshots/04-additional-items-added.png` });
|
||||
|
||||
// Calculate
|
||||
await formPage.calculatePunishment();
|
||||
await page.screenshot({ path: `debug-screenshots/05-calculate-clicked.png` });
|
||||
|
||||
// Wait for results and capture them
|
||||
try {
|
||||
await formPage.waitForResults();
|
||||
await page.screenshot({ path: `debug-screenshots/06-results-shown.png` });
|
||||
|
||||
const results = await formPage.getResults();
|
||||
const summary = await formPage.getSummaryValues();
|
||||
|
||||
console.log('=== RESULTS ===');
|
||||
console.log('Commands:', results.commands);
|
||||
console.log('Summary:', summary);
|
||||
console.log('Explanation:', results.explanation);
|
||||
|
||||
// Save results to file for analysis
|
||||
await page.evaluate((results) => {
|
||||
console.log('Detailed Results:', results);
|
||||
}, { commands: results.commands, summary, explanation: results.explanation });
|
||||
|
||||
} catch (error) {
|
||||
console.error('Failed to get results:', error);
|
||||
await page.screenshot({ path: `debug-screenshots/06-no-results-error.png` });
|
||||
|
||||
// Check if there are any console errors
|
||||
const consoleMessages: string[] = [];
|
||||
page.on('console', msg => consoleMessages.push(msg.text()));
|
||||
await page.waitForTimeout(1000);
|
||||
console.log('Console messages:', consoleMessages);
|
||||
}
|
||||
});
|
||||
|
||||
test('debug grief calculation - step by step', async ({ page }) => {
|
||||
console.log('=== Starting Grief Debug Test ===');
|
||||
|
||||
// Fill basic info
|
||||
await formPage.fillPlayerInfo('DebugPlayer2', 0);
|
||||
await page.screenshot({ path: `debug-screenshots/grief-01-basic-info.png` });
|
||||
|
||||
// Select grief
|
||||
await formPage.selectCrimeCategory('block');
|
||||
await formPage.selectSpecificOffense('grief');
|
||||
await page.screenshot({ path: `debug-screenshots/grief-02-grief-selected.png` });
|
||||
|
||||
// Fill block count
|
||||
await formPage.fillBlockCount(500);
|
||||
await page.screenshot({ path: `debug-screenshots/grief-03-block-count-filled.png` });
|
||||
|
||||
// Calculate
|
||||
await formPage.calculatePunishment();
|
||||
await page.screenshot({ path: `debug-screenshots/grief-04-calculate-clicked.png` });
|
||||
|
||||
// Wait for results
|
||||
try {
|
||||
await formPage.waitForResults();
|
||||
await page.screenshot({ path: `debug-screenshots/grief-05-results-shown.png` });
|
||||
|
||||
const results = await formPage.getResults();
|
||||
const summary = await formPage.getSummaryValues();
|
||||
|
||||
console.log('=== GRIEF RESULTS ===');
|
||||
console.log('Commands:', results.commands);
|
||||
console.log('Summary:', summary);
|
||||
console.log('Explanation:', results.explanation);
|
||||
|
||||
} catch (error) {
|
||||
console.error('Failed to get grief results:', error);
|
||||
await page.screenshot({ path: `debug-screenshots/grief-05-no-results-error.png` });
|
||||
}
|
||||
});
|
||||
|
||||
test('debug all crime types - quick check', async ({ page }) => {
|
||||
const scenarios = TestDataFactory.getAllScenarios().slice(0, 5); // Just test first 5
|
||||
|
||||
for (let i = 0; i < scenarios.length; i++) {
|
||||
const scenario = scenarios[i];
|
||||
console.log(`\n=== Testing ${scenario.offense.crimeId} ===`);
|
||||
|
||||
// Reset form
|
||||
await formPage.resetForm();
|
||||
await page.waitForTimeout(500);
|
||||
|
||||
// Fill player info
|
||||
await formPage.fillPlayerInfo(scenario.player.name, scenario.player.currentPoints);
|
||||
|
||||
// Select category and crime
|
||||
const category = getCrimeCategory(scenario.offense.crimeId);
|
||||
await formPage.selectCrimeCategory(category);
|
||||
await formPage.selectSpecificOffense(scenario.offense.crimeId);
|
||||
|
||||
// Fill specific details
|
||||
if (scenario.offense.specialItems) {
|
||||
await formPage.fillSpecialItems(scenario.offense.specialItems);
|
||||
}
|
||||
if (scenario.offense.itemDetails) {
|
||||
for (const item of scenario.offense.itemDetails) {
|
||||
await formPage.addAdditionalItem(item.type, item.quantity);
|
||||
}
|
||||
}
|
||||
if (scenario.offense.blockCount !== undefined) {
|
||||
await formPage.fillBlockCount(scenario.offense.blockCount);
|
||||
}
|
||||
if (scenario.offense.entityCount !== undefined) {
|
||||
await formPage.fillEntityCount(scenario.offense.entityCount);
|
||||
}
|
||||
if (scenario.offense.isSPP !== undefined) {
|
||||
await formPage.setSPP(scenario.offense.isSPP);
|
||||
}
|
||||
|
||||
// Calculate
|
||||
await formPage.calculatePunishment();
|
||||
|
||||
// Check if results appear
|
||||
try {
|
||||
await formPage.waitForResults();
|
||||
console.log(`✅ ${scenario.offense.crimeId} - Results generated`);
|
||||
} catch (error) {
|
||||
console.log(`❌ ${scenario.offense.crimeId} - No results generated`);
|
||||
await page.screenshot({ path: `debug-screenshots/error-${scenario.offense.crimeId}.png` });
|
||||
}
|
||||
|
||||
await page.waitForTimeout(1000); // Brief pause between tests
|
||||
}
|
||||
});
|
||||
|
||||
test('capture form HTML for debugging', async ({ page }) => {
|
||||
await formPage.fillPlayerInfo('HTMLDebug', 0);
|
||||
await formPage.selectCrimeCategory('item');
|
||||
await formPage.selectSpecificOffense('theft');
|
||||
|
||||
// Get the form HTML
|
||||
const formHtml = await page.locator('form').innerHTML();
|
||||
console.log('Form HTML:', formHtml);
|
||||
|
||||
// Also check for any error messages in the DOM
|
||||
const errorMessages = await page.locator('.text-red-500').allTextContents();
|
||||
console.log('Error messages:', errorMessages);
|
||||
});
|
||||
});
|
||||
|
||||
// Helper function to determine crime category
|
||||
function getCrimeCategory(crimeId: string): 'all' | 'item' | 'block' | 'hacking' | 'communication' {
|
||||
const categoryMap: { [key: string]: 'item' | 'block' | 'hacking' | 'communication' } = {
|
||||
'theft': 'item',
|
||||
'unconsensual_killing': 'item',
|
||||
'illegal_item_use': 'item',
|
||||
'inappropriate_item_names': 'item',
|
||||
'inappropriate_book_contents': 'item',
|
||||
'vandalism': 'block',
|
||||
'grief': 'block',
|
||||
'theft_grief': 'block',
|
||||
'vandalism_infrastructure': 'block',
|
||||
'trespassing': 'block',
|
||||
'trespassing_staff': 'block',
|
||||
'x_raying': 'hacking',
|
||||
'hacking_client': 'hacking',
|
||||
'lagging_server': 'hacking',
|
||||
'worldedit_misuse': 'hacking',
|
||||
'exploit_abuse': 'hacking',
|
||||
'abusive_chat': 'communication',
|
||||
'inciting_verbal_conflict': 'communication',
|
||||
'abusive_vc': 'communication',
|
||||
'lying_to_staff': 'communication',
|
||||
'manipulation': 'communication',
|
||||
'grand_manipulation': 'communication',
|
||||
'slander': 'communication',
|
||||
'violation_nca': 'communication',
|
||||
};
|
||||
|
||||
return categoryMap[crimeId] || 'all';
|
||||
}
|
||||
Reference in New Issue
Block a user