Skip to content

Commit

Permalink
Better checking for default image for the RSS Block (#929)
Browse files Browse the repository at this point in the history
fix: hide default image when `thumb` is set to `auto` for Feedzy RSS Block
  • Loading branch information
Soare-Robert-Daniel authored Apr 18, 2024
1 parent cc9d025 commit 510d320
Show file tree
Hide file tree
Showing 3 changed files with 79 additions and 2 deletions.
66 changes: 66 additions & 0 deletions cypress/e2e/gutenberg/gutenberg_free.js
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -207,4 +207,70 @@ describe('Test Free - gutenberg', function() {
cy.verify_feedzy_frontend(gutenberg.results);
});

it('Check if fallback image is hidden on feeds without image when thumnail set to "auto"', function() {

cy.visit('/wp-admin/post-new.php');

cy.wait( 1000 );
// get rid of that irritating popup
cy.get('body').then((body) => {
if (body.find('.edit-post-welcome-guide .components-modal__header button').length > 0) {
cy.get('.edit-post-welcome-guide .components-modal__header button').click({force:true});
}
});

cy.get('.edit-post-visual-editor__post-title-wrapper .editor-post-title__input').type(PREFIX);

// Insert a Feedzy block.
cy.window().then(window => {
// Create a Feedzy block
const block = window.wp.blocks.createBlock('feedzy-rss-feeds/feedzy-block', {
feeds: 'https://themeisle.com/blog/feed/',
max: 2,
});
window.wp.data.dispatch( 'core/block-editor' ).insertBlock(block)
});

// If we have image displayed, check if the image is not the fallback image.
cy.get('body').then((body) => {
if (body.find('.feedzy-rss .rss_image').length > 0) {
cy.get('.feedzy-rss .rss_image').each(($el) => {
const imgContainer = cy.get($el).get('a span');
const img = imgContainer.invoke('css', 'background-image');

// The URL should not contain 'feedzy.svg' which is the fallback image since fallback is hidden by `thumb: auto`.
expect(img).not.to.include('feedzy.svg');
});
}
});
});

it('Check if images are showed on feeds when thumnail is set to "yes"', function() {

cy.visit('/wp-admin/post-new.php');

cy.wait( 1000 );
// get rid of that irritating popup
cy.get('body').then((body) => {
if (body.find('.edit-post-welcome-guide .components-modal__header button').length > 0) {
cy.get('.edit-post-welcome-guide .components-modal__header button').click({force:true});
}
});

cy.get('.edit-post-visual-editor__post-title-wrapper .editor-post-title__input').type(PREFIX);

// Insert a Feedzy block.
cy.window().then(window => {
// Create a Feedzy block
const block = window.wp.blocks.createBlock('feedzy-rss-feeds/feedzy-block', {
feeds: 'https://themeisle.com/blog/feed/',
max: 2,
thumb: 'yes',
});
window.wp.data.dispatch( 'core/block-editor' ).insertBlock(block)
});

cy.get('.feedzy-rss .rss_image').should('have.length', 2);
});

})
8 changes: 7 additions & 1 deletion includes/abstract/feedzy-rss-feeds-admin-abstract.php
Original file line number Diff line number Diff line change
Expand Up @@ -1438,7 +1438,13 @@ private function get_feed_item_filter( $sc, $sizes, $item, $feed_url, $index, $i
}
if ( 'yes' === $sc['thumb'] || 'auto' === $sc['thumb'] ) {
$content_thumb = '';
if ( ( ! empty( $the_thumbnail ) && 'auto' === $sc['thumb'] ) || 'yes' === $sc['thumb'] ) {
if ( (
! empty( $the_thumbnail ) &&
'auto' === $sc['thumb'] &&
! strpos( $the_thumbnail, 'img/feedzy.svg' )
) ||
'yes' === $sc['thumb']
) {
if ( ! empty( $the_thumbnail ) ) {
$the_thumbnail = $this->feedzy_image_encode( $the_thumbnail );
$content_thumb .= '<span class="fetched" style="background-image: url(\'' . $the_thumbnail . '\');" title="' . esc_html( $item->get_title() ) . '"></span>';
Expand Down
7 changes: 6 additions & 1 deletion includes/gutenberg/src/Editor.js
Original file line number Diff line number Diff line change
Expand Up @@ -462,9 +462,14 @@ class Editor extends Component {
}
}

if ( item['thumbnail'] === '' && this.props.attributes.thumb === 'auto' ) {
if (
item['thumbnail'] === '' &&
this.props.attributes.thumb === 'auto' &&
! item['default_img']?.endsWith( 'img/feedzy.svg' )
) {
item['thumbnail'] = item['default_img'];
}

let meta_values = new Object();
meta_values['author'] = __( 'by' ) + ' ' + author;
meta_values['date'] = __( 'on' ) + ' ' + unescapeHTML( itemDate );
Expand Down

0 comments on commit 510d320

Please sign in to comment.