Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ensure blocks are present before processing #173

Merged
merged 4 commits into from
Feb 6, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion .wp-env.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
{
"plugins": [".", "./tests/cypress/test-plugin"],
"plugins": [
".",
"./tests/cypress/test-plugin/e2e-test-plugin.php",
"./tests/cypress/test-plugin/e2e-test-plugin-optimizer.php"
],
"env": {
"tests": {
"mappings": {
Expand Down
4 changes: 4 additions & 0 deletions assets/js/admin/admin.js
Original file line number Diff line number Diff line change
Expand Up @@ -246,6 +246,10 @@ import {select, subscribe} from '@wordpress/data';
subscribe(() => {
if (editorStore.isSavingPost()) {
const changes = editorStore.getPostEdits();
// maske sure we have blocks to process
dkotter marked this conversation as resolved.
Show resolved Hide resolved
if (!Array.isArray(changes.blocks) || !changes.blocks.length) {
return;
}
for (const changedBlock of changes.blocks) {
const blockName = changedBlock?.name ?? '';
const innerBlocks = changedBlock?.innerBlocks ?? [];
Expand Down
9 changes: 9 additions & 0 deletions tests/cypress/e2e/safe-svg.cy.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,4 +72,13 @@ describe('Safe SVG Tests', () => {

cy.get('.media-item .error-div.error').should('exist').contains('has failed to upload');
});


// Test plugin doesn't break the block editor when no blocks are added
it('Plugin should not break the block editor when optimizer enabled', () => {
// Activate Test Plugin
cy.deactivatePlugin('safe-svg-cypress-test-plugin');
cy.activatePlugin('safe-svg-cypress-optimizer-test-plugin');
cy.createPost('Hello World');
});
});
12 changes: 12 additions & 0 deletions tests/cypress/test-plugin/e2e-test-plugin-optimizer.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<?php
/**
* Plugin name: Safe SVG Cypress Optimizer Test plugin
* Description: Test plugin for Safe SVG to test the optimizer.
*
* @package safe-svg
*/

/**
* Optimizer and allowed attributes can't be mutually enabled, hence the secondary testing plugin.
*/
add_filter('safe_svg_optimizer_enabled', '__return_true');
Loading