Skip to content

Commit

Permalink
chore: e2e test & default behaviour
Browse files Browse the repository at this point in the history
  • Loading branch information
Soare-Robert-Daniel committed Sep 1, 2023
1 parent 0b6f3c2 commit 1664bc1
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 15 deletions.
2 changes: 1 addition & 1 deletion inc/render/class-review-block.php
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ function() use ( $attributes, $post_id ) {

foreach ( $attributes['links'] as $link ) {
$rel = ( isset( $link['isSponsored'] ) && true === $link['isSponsored'] ) ? 'sponsored' : 'nofollow';
$html .= ' <a href="' . esc_url( $link['href'] ) . '" rel="' . $rel . '" target="' . $link['target'] . '">' . esc_html( $link['label'] ) . '</a>';
$html .= ' <a href="' . esc_url( $link['href'] ) . '" rel="' . $rel . '" target="' . ( empty( $link['target'] ) ? '_blank' : $link['target'] ) . '">' . esc_html( $link['label'] ) . '</a>';
}
$html .= ' </div>';
$html .= ' </div>';
Expand Down
24 changes: 12 additions & 12 deletions src/blocks/blocks/review/block.json
Original file line number Diff line number Diff line change
Expand Up @@ -70,18 +70,18 @@
"links": {
"type": "array",
"default": [
{
"label": "Buy on Amazon",
"href": "",
"isSponsored": false,
"target": "_blank"
},
{
"label": "Buy on eBay",
"href": "",
"isSponsored": false,
"target": "_blank"
}
{
"label": "Buy on Amazon",
"href": "",
"isSponsored": false,
"target": "_blank"
},
{
"label": "Buy on eBay",
"href": "",
"isSponsored": false,
"target": "_blank"
}
]
},
"prosLabel": {
Expand Down
4 changes: 2 additions & 2 deletions src/blocks/blocks/review/inspector.js
Original file line number Diff line number Diff line change
Expand Up @@ -639,8 +639,8 @@ const Inspector = ({

<ToggleControl
label={ __( 'Open in New Tab', 'otter-blocks' ) }
checked={ '_blank' === link.target }
onChange={ () => onChangeLink({ action: 'update', index, value: { target: '_blank' === link.target ? '_self' : '_blank' }}) }
checked={ undefined === link.target || '_blank' === link.target }
onChange={ () => onChangeLink({ action: 'update', index, value: { target: '_blank' === link.target || undefined === link.target ? '_self' : '_blank' }}) }
/>
</PanelItem>
) ) }
Expand Down
21 changes: 21 additions & 0 deletions src/blocks/test/e2e/blocks/product-review.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -81,5 +81,26 @@ test.describe( 'Product Review Block', () => {
await expect( await page.getByRole( 'document', { name: 'Block: Product Review' }).getByText( FEATURE_DESCRIPTION, { exact: true }) ).toBeVisible();
});

test( 'open in new tab', async({ editor, page }) => {
await editor.insertBlock({ name: 'themeisle-blocks/review' });

await page.getByRole( 'button', { name: 'Buttons' }).click({ clickCount: 1 });

await page.getByRole( 'button', { name: 'Add Links' }).click();

await page.getByRole( 'button', { name: 'Buy Now' }).click();

await page.getByPlaceholder( 'Button label' ).fill( 'Buy Now in same tab' );
await page.getByLabel( 'Open in New Tab' ).click();

await page.getByRole( 'button', { name: 'Add Links' }).click();

const postId = await editor.publishPost();

await page.goto( `/?p=${postId}` );

await expect( page.getByRole( 'link', { name: 'Buy Now in same tab' }) ).toHaveAttribute( 'target', '_self' );
await expect( page.getByRole( 'link', { name: 'Buy Now', exact: true }) ).toHaveAttribute( 'target', '_blank' );

});
});

0 comments on commit 1664bc1

Please sign in to comment.