Skip to content

Commit fa199f5

Browse files
Tests: Verify View intent blocks suggestion overlay and commit bar
Add a unit test confirming the HOC passes through in View intent (no overlay diversion — real setAttributes is invoked) and an e2e test verifying that switching from Suggest to View hides the commit bar and prevents suggestion leakage into post content. Both validate that isPreviewMode + intent gating work together correctly. Refs #73411
1 parent 35e784a commit fa199f5

2 files changed

Lines changed: 69 additions & 0 deletions

File tree

packages/editor/src/components/suggestion-mode/test/with-suggestion-overlay.js

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,4 +131,31 @@ describe( 'withSuggestionOverlay', () => {
131131
'proposed'
132132
);
133133
} );
134+
135+
it( 'passes through in View intent — no overlay, no diversion', () => {
136+
const setAttributes = jest.fn();
137+
renderWithProviders(
138+
<Wrapped
139+
clientId="a"
140+
name="core/paragraph"
141+
attributes={ { content: 'Untouched' } }
142+
setAttributes={ setAttributes }
143+
/>,
144+
{ intent: 'view' }
145+
);
146+
147+
expect( screen.getByTestId( 'content' ) ).toHaveTextContent(
148+
'Untouched'
149+
);
150+
151+
act( () => {
152+
screen.getByRole( 'button', { name: 'edit' } ).click();
153+
} );
154+
155+
// In view intent the HOC is a pass-through, so the real
156+
// setAttributes is invoked and the overlay is never used.
157+
expect( setAttributes ).toHaveBeenCalledWith( {
158+
content: 'proposed',
159+
} );
160+
} );
134161
} );

test/e2e/specs/editor/various/editor-intent-switcher.spec.js

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,4 +95,46 @@ test.describe( 'Editor intent switcher', () => {
9595
} )
9696
).toHaveAttribute( 'aria-checked', 'true' );
9797
} );
98+
99+
test( 'View intent prevents suggestion overlay and commit bar', async ( {
100+
editor,
101+
page,
102+
} ) => {
103+
await editor.insertBlock( {
104+
name: 'core/paragraph',
105+
attributes: { content: 'Protected content' },
106+
} );
107+
108+
// First enter Suggest mode and type to create an overlay.
109+
await openIntentSwitcher( page );
110+
await page.getByRole( 'menuitemradio', { name: /^Suggest/ } ).click();
111+
112+
const paragraph = editor.canvas
113+
.getByRole( 'document', { name: 'Block: Paragraph' } )
114+
.first();
115+
await paragraph.click();
116+
await page.keyboard.press( 'End' );
117+
await page.keyboard.type( ' added' );
118+
await expect( paragraph ).toContainText( 'Protected content added' );
119+
120+
// Submit suggestion button should be visible in Suggest mode.
121+
const submitButton = page
122+
.getByRole( 'toolbar', { name: 'Block tools' } )
123+
.getByRole( 'button', { name: 'Submit suggestion' } );
124+
await expect( submitButton ).toBeVisible();
125+
126+
// Switch to View — the editor becomes read-only and the commit
127+
// bar should disappear because isSuggestMode === false.
128+
await openIntentSwitcher( page );
129+
await page
130+
.getByRole( 'menuitemradio', { name: /^View\s+Read-only/ } )
131+
.click();
132+
133+
await expect( submitButton ).toBeHidden();
134+
135+
// The serialized content is unchanged — no suggestion leaked.
136+
const serialized = await editor.getEditedPostContent();
137+
expect( serialized ).toContain( 'Protected content' );
138+
expect( serialized ).not.toContain( 'added' );
139+
} );
98140
} );

0 commit comments

Comments
 (0)