Skip to content

Commit

Permalink
Merge pull request #2173 from Codeinwp/fix/product_review_line_breaks
Browse files Browse the repository at this point in the history
Fix/product review line breaks
  • Loading branch information
vytisbulkevicius authored Apr 10, 2024
2 parents 49d7a34 + 57a7d60 commit 60690c0
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 1 deletion.
2 changes: 1 addition & 1 deletion inc/render/class-review-block.php
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ function() use ( $attributes, $post_id ) {
}

if ( isset( $attributes['description'] ) && ! empty( $attributes['description'] ) ) {
$html .= ' <p>' . esc_html( $attributes['description'] ) . '</p>';
$html .= ' <p>' . wp_kses( $attributes['description'], array( 'br' => array() ) ) . '</p>';
}
$html .= ' </div>';
}
Expand Down
30 changes: 30 additions & 0 deletions src/blocks/test/e2e/blocks/product-review.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -103,4 +103,34 @@ test.describe( 'Product Review Block', () => {
await expect( page.getByRole( 'link', { name: 'Buy Now', exact: true }) ).toHaveAttribute( 'target', '_blank' );

});

test( 'check description new lines preserved', async({ editor, page }) => {
await editor.insertBlock({ name: 'themeisle-blocks/review' });

const title = page.getByRole( 'textbox', { name: 'Name of your product…' });

await title.type( 'Test Product' );

// Check if the value is added in title
expect( await title.innerHTML() ).toBe( 'Test Product' );

// Add a multi line description
await page.getByLabel( 'Product description or a' ).click();
await page.getByLabel( 'Product description or a' ).fill( 'Product description' );
await page.keyboard.press( 'Enter' );
await page.keyboard.type( 'Line 1' );
await page.keyboard.press( 'Enter' );
await page.keyboard.type( 'Line 2' );

// Check if the value is added in description and is multiline
await expect( page.getByLabel( 'Product description or a' ) ).toContainText( 'Product description\nLine 1\nLine 2', { useInnerText: true });

// Publish the post and view the post
await page.getByRole( 'button', { name: 'Publish', exact: true }).click();
await page.getByLabel( 'Editor publish' ).getByRole( 'button', { name: 'Publish', exact: true }).click();
await page.getByLabel( 'Editor publish' ).getByRole( 'link', { name: 'View Post' }).click();

// Check if the value is added in description and multiline is preserved
await expect( page.locator( '.wp-block-themeisle-blocks-review .o-review__header_details' ) ).toContainText( 'Product description\nLine 1\nLine 2', { useInnerText: true });
});
});

0 comments on commit 60690c0

Please sign in to comment.