Skip to content

Commit 79916bd

Browse files
pattonwebzclaude
andcommitted
fix: address code review comments on PR #1805
- Add a unit test verifying the pro flag in edac_script_vars - Wrap DismissPanel's destructured params across multiple lines (line was 200+ chars) - Guard the window reference in IssueDetailsModal's pro check with typeof window !== 'undefined' - Drop the isPro prop passed to DismissPanel since it duplicated the component's own default Co-Authored-By: Claude <noreply@anthropic.com>
1 parent 324f4cb commit 79916bd

3 files changed

Lines changed: 32 additions & 3 deletions

File tree

src/issueModal/components/DismissPanel.js

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,15 @@ import { getDismissReasonOptions } from '../../sidebar/utils/dismissHelpers';
2727
* @param {boolean} props.forceGlobal - When true, the primary dismiss action targets all pages (global dismiss).
2828
* @param {boolean} props.isPro - Whether the current UI is running in Pro.
2929
*/
30-
const DismissPanel = ( { issue, isOpen, onToggle, onIgnore, onCloseModal, forceGlobal = false, isPro = typeof window !== 'undefined' && ( window.edac_editor_app?.pro === '1' || window.edac_script_vars?.pro === '1' ) } ) => {
30+
const DismissPanel = ( {
31+
issue,
32+
isOpen,
33+
onToggle,
34+
onIgnore,
35+
onCloseModal,
36+
forceGlobal = false,
37+
isPro = typeof window !== 'undefined' && ( window.edac_editor_app?.pro === '1' || window.edac_script_vars?.pro === '1' ),
38+
} ) => {
3139
const panelRef = useRef( null );
3240
const [ comment, setComment ] = useState( issue?.ignre_comment ? decodeEntities( issue.ignre_comment ) : '' );
3341
const [ dismissReason, setDismissReason ] = useState( issue?.ignre_reason || 'false_positive' );

src/issueModal/components/IssueDetailsModal.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -328,7 +328,7 @@ export const IssueDetailsModal = ( { issue, rule, onClose, isOpen, focusSection,
328328
) }
329329

330330
{ /* How to Fix - Show detailed info for Pro, or just link for Free */ }
331-
{ ( window.edac_editor_app?.pro === '1' || window.edac_script_vars?.pro === '1' ) ? (
331+
{ ( typeof window !== 'undefined' && ( window.edac_editor_app?.pro === '1' || window.edac_script_vars?.pro === '1' ) ) ? (
332332
<div className="edac-analysis__issue-help-accordion">
333333
<PanelBody
334334
title={ __( 'Show explanation', 'accessibility-checker' ) }
@@ -406,7 +406,6 @@ export const IssueDetailsModal = ( { issue, rule, onClose, isOpen, focusSection,
406406
onToggle={ () => setIsDismissPanelOpen( ! isDismissPanelOpen ) }
407407
onIgnore={ onIgnore }
408408
onCloseModal={ onClose }
409-
isPro={ typeof window !== 'undefined' && ( window.edac_editor_app?.pro === '1' || window.edac_script_vars?.pro === '1' ) }
410409
/>
411410
</div>
412411
</div>

tests/phpunit/Admin/EnqueueAdminTest.php

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,28 @@ public function testLocalizedAdminDataIncludesFixesRestUrl(): void {
125125
$this->assertStringContainsString( 'fixesRestUrl', $localized_data );
126126
}
127127

128+
/**
129+
* The pro flag in edac_script_vars reflects defined( 'EDACP_VERSION' ) && EDAC_KEY_VALID,
130+
* so non-editor admin pages (e.g. the Issues Explorer) can gate pro-only UI without
131+
* relying on window.edac_editor_app, which is only localized on post.php/post-new.php.
132+
*/
133+
public function testLocalizedAdminDataIncludesProFlag(): void {
134+
global $wp_scripts;
135+
136+
$this->enqueue_admin::maybe_enqueue_admin_and_editor_app_scripts();
137+
138+
$localized_data = (string) $wp_scripts->get_data( 'edac', 'data' );
139+
$expected_pro = defined( 'EDACP_VERSION' ) && EDAC_KEY_VALID;
140+
141+
// wp_localize_script() stringifies booleans as "1" / "" (matching the
142+
// === '1' checks on the JS side), not JSON true/false.
143+
$this->assertStringContainsString( '"pro"', $localized_data );
144+
$this->assertMatchesRegularExpression(
145+
'/"pro"\s*:\s*"' . ( $expected_pro ? '1' : '' ) . '"/',
146+
$localized_data
147+
);
148+
}
149+
128150
/**
129151
* FixesRestUrl uses the edac/v1 namespace and matches rest_url().
130152
*/

0 commit comments

Comments
 (0)