tengri/Content/Debug/Tests/FT_DebugPageManagement.ts

262 lines
11 KiB
TypeScript

// Debug/Tests/FT_DebugPageManagement.ts
import { AC_DebugHUD } from '#root/Debug/Components/AC_DebugHUD.ts';
import { AC_InputDevice } from '#root/Input/Components/AC_InputDevice.ts';
import { AC_ToastSystem } from '#root/Toasts/Components/AC_ToastSystem.ts';
import { EFunctionalTestResult } from '#root/UE/EFunctionalTestResult.ts';
import { FunctionalTest } from '#root/UE/FunctionalTest.ts';
import { SystemLibrary } from '#root/UE/SystemLibrary.ts';
/**
* Functional Test: Debug Page Management
* Tests dynamic page registration, content updates, and lifecycle operations
*/
export class FT_DebugPageManagement extends FunctionalTest {
// ════════════════════════════════════════════════════════════════════════════════════════
// GRAPHS
// ════════════════════════════════════════════════════════════════════════════════════════
// ────────────────────────────────────────────────────────────────────────────────────────
// EventGraph
// ────────────────────────────────────────────────────────────────────────────────────────
/**
* Test entry point - validates all page management operations
* Tests: Add, Update, ShouldUpdate, Visibility, Remove
*/
EventStartTest(): void {
this.DebugHUDComponent.InitializeDebugHUD(
this.ToastSystemComponent,
this.InputDeviceComponent
);
this.DebugHUDComponent.AddDebugPage('TestPage1', 'Test Page 1', 30, true);
const pageCount = this.DebugHUDComponent.GetTestData().DebugPages.length;
if (pageCount === 1) {
const testContent = 'Test Content 123';
this.DebugHUDComponent.UpdatePageContent('TestPage1', testContent);
const page = this.DebugHUDComponent.GetTestData().DebugPages.Get(0);
const contentMatches = page.Content === testContent;
if (contentMatches) {
const currentTime = SystemLibrary.GetGameTimeInSeconds();
// First call should return true (no previous update)
const firstCall = this.DebugHUDComponent.ShouldUpdatePage(
'TestPage1',
currentTime
);
// Immediate second call should return false (just updated)
const secondCall = this.DebugHUDComponent.ShouldUpdatePage(
'TestPage1',
currentTime
);
if (firstCall && !secondCall) {
this.DebugHUDComponent.AddDebugPage(
'TestPage2',
'Test Page 2',
60,
true
);
const pageCount =
this.DebugHUDComponent.GetTestData().DebugPages.length;
const visibleCount =
this.DebugHUDComponent.GetTestData().VisiblePagesLength;
if (pageCount === 2 && visibleCount === 2) {
// Hide second page
this.DebugHUDComponent.SetPageVisibility('TestPage2', false);
const totalCount =
this.DebugHUDComponent.GetTestData().DebugPages.length;
const visibleCount =
this.DebugHUDComponent.GetTestData().VisiblePagesLength;
if (totalCount === 2 && visibleCount === 1) {
// Remove first page
this.DebugHUDComponent.RemoveDebugPage('TestPage1');
const totalCount =
this.DebugHUDComponent.GetTestData().DebugPages.length;
const currentIndex =
this.DebugHUDComponent.GetTestData().CurrentPageIndex;
if (totalCount === 1 && currentIndex === 0) {
// Re-add page with same ID but different settings
this.DebugHUDComponent.AddDebugPage(
'TestPage2',
'Updated Title',
120,
true
);
const totalCount =
this.DebugHUDComponent.GetTestData().DebugPages.length;
const visibleCount =
this.DebugHUDComponent.GetTestData().VisiblePagesLength;
const page =
this.DebugHUDComponent.GetTestData().DebugPages.Get(0);
const titleMatches = page.Title === 'Updated Title';
const refreshRateMatches = page.RefreshRate === 120;
if (
totalCount === 1 &&
visibleCount === 1 &&
titleMatches &&
refreshRateMatches
) {
// Add pages with different refresh rates
this.DebugHUDComponent.AddDebugPage(
'FastPage',
'Fast Page',
120,
true
);
this.DebugHUDComponent.AddDebugPage(
'SlowPage',
'Slow Page',
10,
true
);
const currentTime = SystemLibrary.GetGameTimeInSeconds();
// Both should update on first call
const fastShouldUpdate =
this.DebugHUDComponent.ShouldUpdatePage(
'FastPage',
currentTime
);
const slowShouldUpdate =
this.DebugHUDComponent.ShouldUpdatePage(
'SlowPage',
currentTime
);
// Wait for fast page interval (1/120 = 0.0083s) but not slow (1/10 = 0.1s)
const fastUpdateTime = currentTime + 0.01;
const fastShouldUpdateAgain =
this.DebugHUDComponent.ShouldUpdatePage(
'FastPage',
fastUpdateTime
);
const slowShouldNotUpdate =
this.DebugHUDComponent.ShouldUpdatePage(
'SlowPage',
fastUpdateTime
);
if (
fastShouldUpdate &&
slowShouldUpdate &&
fastShouldUpdateAgain &&
!slowShouldNotUpdate
) {
// Try to update non-existent page (should not crash)
this.DebugHUDComponent.UpdatePageContent(
'NonExistentPage',
'Test'
);
// Try to remove non-existent page (should not crash)
this.DebugHUDComponent.RemoveDebugPage('NonExistentPage');
// Try to check non-existent page (should return false)
const currentTime = SystemLibrary.GetGameTimeInSeconds();
const shouldUpdate =
this.DebugHUDComponent.ShouldUpdatePage(
'NonExistentPage',
currentTime
);
if (!shouldUpdate) {
this.FinishTest(EFunctionalTestResult.Succeeded);
} else {
this.FinishTest(
EFunctionalTestResult.Failed,
'Test 9 Failed: ShouldUpdatePage returned true for non-existent page'
);
}
} else {
this.FinishTest(
EFunctionalTestResult.Failed,
`Test 8 Failed: Refresh rates incorrect (fast1: ${fastShouldUpdate}, slow1: ${slowShouldUpdate}, fast2: ${fastShouldUpdateAgain}, slow2: ${slowShouldNotUpdate})`
);
}
} else {
this.FinishTest(
EFunctionalTestResult.Failed,
`Test 7 Failed: Update registration incorrect (count: ${totalCount}, title: ${titleMatches}, rate: ${refreshRateMatches})`
);
}
} else {
this.FinishTest(
EFunctionalTestResult.Failed,
`Test 6 Failed: Remove incorrect (count: ${totalCount}, index: ${currentIndex})`
);
}
} else {
this.FinishTest(
EFunctionalTestResult.Failed,
`Test 5 Failed: Visibility incorrect (total: ${totalCount}, visible: ${visibleCount})`
);
}
} else {
this.FinishTest(
EFunctionalTestResult.Failed,
`Test 4 Failed: Expected 2 pages (total: ${pageCount}, visible: ${visibleCount})`
);
}
} else {
this.FinishTest(
EFunctionalTestResult.Failed,
`Test 3 Failed: ShouldUpdatePage timing incorrect (first: ${firstCall}, second: ${secondCall})`
);
}
} else {
this.FinishTest(
EFunctionalTestResult.Failed,
'Test 2 Failed: Content did not update correctly'
);
}
} else {
this.FinishTest(
EFunctionalTestResult.Failed,
`Test 1 Failed: Expected 1 page, got ${pageCount}`
);
}
}
// ════════════════════════════════════════════════════════════════════════════════════════
// VARIABLES
// ════════════════════════════════════════════════════════════════════════════════════════
/**
* Debug HUD system - primary component under test
* Tests all page management operations
* @category Components
*/
DebugHUDComponent = new AC_DebugHUD();
/**
* Toast notification system - required for debug HUD initialization
* @category Components
*/
ToastSystemComponent = new AC_ToastSystem();
/**
* Input device detection system - required for debug HUD initialization
* @category Components
*/
InputDeviceComponent = new AC_InputDevice();
}