Add automated smoke test and cleanup script initialization#14
Open
DaKongOlta wants to merge 1 commit into
Open
Add automated smoke test and cleanup script initialization#14DaKongOlta wants to merge 1 commit into
DaKongOlta wants to merge 1 commit into
Conversation
Reviewer's GuideThis PR introduces a full end-to-end smoke test powered by Puppeteer, wires it into npm with documentation updates, and significantly refactors script.js by deduplicating DOM initialization, consolidating startup into a single initializeAppState routine, and exposing a diagnostics API for test assertions. Sequence diagram for automated smoke test flowsequenceDiagram
actor Tester
participant Puppeteer
participant SpacerXApp as "Spacer-X App"
Tester->>Puppeteer: Run `npm run smoke`
Puppeteer->>SpacerXApp: Launch in headless Chromium
Puppeteer->>SpacerXApp: Disable broadcast intros
Puppeteer->>SpacerXApp: Start quick race
Puppeteer->>SpacerXApp: Advance Grand Prix
Puppeteer->>SpacerXApp: Simulate manager week
Puppeteer->>SpacerXApp: Query window.spacerxDiagnostics.getControlState()
SpacerXApp-->>Puppeteer: Return UI state
Puppeteer-->>Tester: Report test results
Class diagram for diagnostics API and initialization refactorclassDiagram
class SpacerXDiagnostics {
+getPhaseTimeline()
+getControlState()
+reset()
}
class AppState {
+uiSettings
+raceSettings
+currentTrackType
+totalLaps
+aiLevel
+currentWeather
+startProcedureMode
+activeTrackTraits
+currentVisualTheme
+lastTelemetryOrder
+initializeAppState()
}
SpacerXDiagnostics <.. AppState: uses
class DOMBindings {
+mainMenu
+raceScreen
+teamsScreen
+managerScreen
+bettingScreen
+codexScreen
+settingsScreen
+newRaceBtn
+grandPrixBtn
+resumeGrandPrixBtn
+gpStatusCard
+... (other elements)
}
AppState <.. DOMBindings: uses
File-Level Changes
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
There was a problem hiding this comment.
Hey there - I've reviewed your changes - here's some feedback:
- script.js has grown quite large with intertwined initialization and diagnostics logic—consider splitting it into smaller modules or files to improve readability and maintainability.
- The initializeAppState routine now rebinds event listeners and timers; make sure you clear any existing handlers or intervals so that calling it repeatedly won’t leak or duplicate behavior.
- In full_smoke.mjs the waitForControlState calls are very repetitive—extracting a higher‐level helper or configuration object for common checks could reduce duplication and make the flow clearer.
Prompt for AI Agents
Please address the comments from this code review:
## Overall Comments
- script.js has grown quite large with intertwined initialization and diagnostics logic—consider splitting it into smaller modules or files to improve readability and maintainability.
- The initializeAppState routine now rebinds event listeners and timers; make sure you clear any existing handlers or intervals so that calling it repeatedly won’t leak or duplicate behavior.
- In full_smoke.mjs the waitForControlState calls are very repetitive—extracting a higher‐level helper or configuration object for common checks could reduce duplication and make the flow clearer.
## Individual Comments
### Comment 1
<location> `tests/full_smoke.mjs:125-134` </location>
<code_context>
+async function runQuickRace(page) {
</code_context>
<issue_to_address>
**suggestion (testing):** Consider adding assertions for error states and UI failures during race flow.
Add assertions to verify that error overlays do not appear and that race controls maintain their expected enabled/disabled state throughout the test.
</issue_to_address>
### Comment 2
<location> `script.js:884-894` </location>
<code_context>
</code_context>
<issue_to_address>
**issue (code-quality):** Avoid function declarations, favouring function assignment expressions, inside blocks. ([`avoid-function-declarations-in-blocks`](https://docs.sourcery.ai/Reference/Rules-and-In-Line-Suggestions/JavaScript/Default-Rules/avoid-function-declarations-in-blocks))
<details><summary>Explanation</summary>Function declarations may be hoisted in Javascript, but the behaviour is inconsistent between browsers.
Hoisting is generally confusing and should be avoided. Rather than using function declarations inside blocks, you
should use function expressions, which create functions in-scope.
</details>
</issue_to_address>
### Comment 3
<location> `script.js:6913-6922` </location>
<code_context>
</code_context>
<issue_to_address>
**issue (code-quality):** Avoid function declarations, favouring function assignment expressions, inside blocks. ([`avoid-function-declarations-in-blocks`](https://docs.sourcery.ai/Reference/Rules-and-In-Line-Suggestions/JavaScript/Default-Rules/avoid-function-declarations-in-blocks))
<details><summary>Explanation</summary>Function declarations may be hoisted in Javascript, but the behaviour is inconsistent between browsers.
Hoisting is generally confusing and should be avoided. Rather than using function declarations inside blocks, you
should use function expressions, which create functions in-scope.
</details>
</issue_to_address>
### Comment 4
<location> `script.js:6924-6934` </location>
<code_context>
</code_context>
<issue_to_address>
**issue (code-quality):** Avoid function declarations, favouring function assignment expressions, inside blocks. ([`avoid-function-declarations-in-blocks`](https://docs.sourcery.ai/Reference/Rules-and-In-Line-Suggestions/JavaScript/Default-Rules/avoid-function-declarations-in-blocks))
<details><summary>Explanation</summary>Function declarations may be hoisted in Javascript, but the behaviour is inconsistent between browsers.
Hoisting is generally confusing and should be avoided. Rather than using function declarations inside blocks, you
should use function expressions, which create functions in-scope.
</details>
</issue_to_address>
### Comment 5
<location> `script.js:6936-6960` </location>
<code_context>
</code_context>
<issue_to_address>
**issue (code-quality):** Avoid function declarations, favouring function assignment expressions, inside blocks. ([`avoid-function-declarations-in-blocks`](https://docs.sourcery.ai/Reference/Rules-and-In-Line-Suggestions/JavaScript/Default-Rules/avoid-function-declarations-in-blocks))
<details><summary>Explanation</summary>Function declarations may be hoisted in Javascript, but the behaviour is inconsistent between browsers.
Hoisting is generally confusing and should be avoided. Rather than using function declarations inside blocks, you
should use function expressions, which create functions in-scope.
</details>
</issue_to_address>Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
Comment on lines
+125
to
+134
| async function runQuickRace(page) { | ||
| console.log('▶ Running quick race…'); | ||
| await waitForControlState(page, 'main menu', () => { | ||
| const diagnostics = window.spacerxDiagnostics?.getControlState?.(); | ||
| return diagnostics?.screen === 'mainMenu'; | ||
| }); | ||
|
|
||
| const initialState = await getControlState(page); | ||
| assert(initialState.buttons?.newRace?.enabled, 'Expected "Schnelles Rennen" to be enabled on load'); | ||
|
|
There was a problem hiding this comment.
suggestion (testing): Consider adding assertions for error states and UI failures during race flow.
Add assertions to verify that error overlays do not appear and that race controls maintain their expected enabled/disabled state throughout the test.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Testing
https://chatgpt.com/codex/tasks/task_e_68d0f71a83188324a2e0c8d5a7b5397c
Summary by Sourcery
Add automated end-to-end smoke testing and streamline application initialization to support reliable UI state diagnostics
New Features:
Enhancements:
Documentation:
Tests: