Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
1 change: 0 additions & 1 deletion .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
"browser": false,
"es6": true,
"node": true,
"mocha": true,
"jest/globals": true
},
"parserOptions": {
Expand Down
1 change: 1 addition & 0 deletions editor/components/editor-history/redo.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ function EditorHistoryRedo( { hasRedo, redo } ) {
label={ __( 'Redo' ) }
disabled={ ! hasRedo }
onClick={ redo }
className="editor-history__undo"
/>
);
}
Expand Down
1 change: 1 addition & 0 deletions editor/components/editor-history/undo.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ function EditorHistoryUndo( { hasUndo, undo } ) {
label={ __( 'Undo' ) }
disabled={ ! hasUndo }
onClick={ undo }
className="editor-history__undo"
/>
);
}
Expand Down
8 changes: 4 additions & 4 deletions editor/store/effects.js
Original file line number Diff line number Diff line change
Expand Up @@ -305,17 +305,17 @@ export default {
effects.push( resetBlocks( blocks ) );
}

// Resetting post should occur after blocks have been reset, since it's
// the post reset that restarts history (used in dirty detection).
effects.push( resetPost( post ) );

// Include auto draft title in edits while not flagging post as dirty
if ( post.status === 'auto-draft' ) {
effects.push( setupNewPost( {
title: post.title.raw,
} ) );
}

// Resetting post should occur after blocks have been reset, since it's
// the post reset that restarts history (used in dirty detection).
effects.push( resetPost( post ) );

return effects;
},
FETCH_REUSABLE_BLOCKS( action, store ) {
Expand Down
4 changes: 2 additions & 2 deletions editor/store/reducer.js
Original file line number Diff line number Diff line change
Expand Up @@ -114,11 +114,11 @@ export const editor = flow( [
combineReducers,

// Track undo history, starting at editor initialization.
partialRight( withHistory, { resetTypes: [ 'SETUP_EDITOR' ] } ),
partialRight( withHistory, { resetTypes: [ 'SETUP_NEW_POST', 'SETUP_EDITOR' ] } ),

// Track whether changes exist, resetting at each post save. Relies on
// editor initialization firing post reset as an effect.
partialRight( withChangeDetection, { resetTypes: [ 'RESET_POST' ] } ),
partialRight( withChangeDetection, { resetTypes: [ 'SETUP_NEW_POST', 'RESET_POST' ] } ),
] )( {
edits( state = {}, action ) {
switch ( action.type ) {
Expand Down
2 changes: 1 addition & 1 deletion editor/store/test/effects.js
Original file line number Diff line number Diff line change
Expand Up @@ -469,8 +469,8 @@ describe( 'effects', () => {
const result = handler( { post, settings: {} } );

expect( result ).toEqual( [
setupNewPost( { title: 'A History of Pork' } ),
resetPost( post ),
setupNewPost( { title: 'A History of Pork' } ),
] );
} );
} );
Expand Down
181 changes: 181 additions & 0 deletions test/e2e/.eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,181 @@
// For the most part, this file mirrors the same configuration from the root
// `.eslintrc.json`, the exceptions being that since Cypress is preconfigured
// with Mocha & Chai, we need to broadly disable the Jest rules, which is
// otherwise difficult to do. This file could be made more minimal once all of
// the Gutenberg-specific rules are migrated to a common WordPress config.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder if there's a way to override the root config instead of copying it

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed, that would be the best solution. I would leave it as it is. We are going to tackle it together with @ntwb as part of @wordpress/packages soon.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The previous iteration of the configuration file is how to override the root config (i.e. ESLint will look in all parent directories until it finds a config with root: true). The problem is that by opting into many Jest presets, there are many rules and env values we'd need to disable individually.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's more complicated than I would expect.


module.exports = {
"root": true,
"parser": "babel-eslint",
"extends": [
"wordpress"
],
"env": {
"browser": false,
"es6": true,
"node": true,
"mocha": true
},
"parserOptions": {
"sourceType": "module"
},
"globals": {
"cy": true,
"Cypress": true,
"expect": true
},
"plugins": [
"wordpress"
],
"rules": {
"array-bracket-spacing": [ "error", "always" ],
"brace-style": [ "error", "1tbs" ],
"camelcase": [ "error", { "properties": "never" } ],
"comma-dangle": [ "error", "always-multiline" ],
"comma-spacing": "error",
"comma-style": "error",
"computed-property-spacing": [ "error", "always" ],
"constructor-super": "error",
"dot-notation": "error",
"eol-last": "error",
"eqeqeq": "error",
"func-call-spacing": "error",
"indent": [ "error", "tab", { "SwitchCase": 1 } ],
"key-spacing": "error",
"keyword-spacing": "error",
"lines-around-comment": "off",
"no-alert": "error",
"no-bitwise": "error",
"no-caller": "error",
"no-console": "error",
"no-const-assign": "error",
"no-debugger": "error",
"no-dupe-args": "error",
"no-dupe-class-members": "error",
"no-dupe-keys": "error",
"no-duplicate-case": "error",
"no-duplicate-imports": "error",
"no-else-return": "error",
"no-eval": "error",
"no-extra-semi": "error",
"no-fallthrough": "error",
"no-lonely-if": "error",
"no-mixed-operators": "error",
"no-mixed-spaces-and-tabs": "error",
"no-multiple-empty-lines": [ "error", { "max": 1 } ],
"no-multi-spaces": "error",
"no-multi-str": "off",
"no-negated-in-lhs": "error",
"no-nested-ternary": "error",
"no-redeclare": "error",
"no-restricted-syntax": [
"error",
{
"selector": "ImportDeclaration[source.value=/^@wordpress\\u002F.+\\u002F/]",
"message": "Path access on WordPress dependencies is not allowed."
},
{
"selector": "ImportDeclaration[source.value=/^blocks$/]",
"message": "Use @wordpress/blocks as import path instead."
},
{
"selector": "ImportDeclaration[source.value=/^components$/]",
"message": "Use @wordpress/components as import path instead."
},
{
"selector": "ImportDeclaration[source.value=/^date$/]",
"message": "Use @wordpress/date as import path instead."
},
{
"selector": "ImportDeclaration[source.value=/^editor$/]",
"message": "Use @wordpress/editor as import path instead."
},
{
"selector": "ImportDeclaration[source.value=/^element$/]",
"message": "Use @wordpress/element as import path instead."
},
{
"selector": "ImportDeclaration[source.value=/^i18n$/]",
"message": "Use @wordpress/i18n as import path instead."
},
{
"selector": "ImportDeclaration[source.value=/^data$/]",
"message": "Use @wordpress/data as import path instead."
},
{
"selector": "ImportDeclaration[source.value=/^utils$/]",
"message": "Use @wordpress/utils as import path instead."
},
{
"selector": "ImportDeclaration[source.value=/^edit-poost$/]",
"message": "Use @wordpress/edit-post as import path instead."
},
{
"selector": "CallExpression[callee.name=/^__|_n|_x$/]:not([arguments.0.type=/^Literal|BinaryExpression$/])",
"message": "Translate function arguments must be string literals."
},
{
"selector": "CallExpression[callee.name=/^_n|_x$/]:not([arguments.1.type=/^Literal|BinaryExpression$/])",
"message": "Translate function arguments must be string literals."
},
{
"selector": "CallExpression[callee.name=_nx]:not([arguments.2.type=/^Literal|BinaryExpression$/])",
"message": "Translate function arguments must be string literals."
}
],
"no-shadow": "error",
"no-undef": "error",
"no-undef-init": "error",
"no-unreachable": "error",
"no-unsafe-negation": "error",
"no-unused-expressions": "error",
"no-unused-vars": "error",
"no-useless-computed-key": "error",
"no-useless-constructor": "error",
"no-useless-return": "error",
"no-var": "error",
"no-whitespace-before-property": "error",
"object-curly-spacing": [ "error", "always" ],
"padded-blocks": [ "error", "never" ],
"prefer-const": "error",
"quote-props": [ "error", "as-needed" ],
"semi": "error",
"semi-spacing": "error",
"space-before-blocks": [ "error", "always" ],
"space-before-function-paren": [ "error", "never" ],
"space-in-parens": [ "error", "always" ],
"space-infix-ops": [ "error", { "int32Hint": false } ],
"space-unary-ops": [ "error", {
"overrides": {
"!": true
}
} ],
"template-curly-spacing": [ "error", "always" ],
"valid-jsdoc": [ "error", {
"prefer": {
"arg": "param",
"argument": "param",
"extends": "augments",
"returns": "return"
},
"preferType": {
"array": "Array",
"bool": "boolean",
"Boolean": "boolean",
"float": "number",
"Float": "number",
"int": "number",
"integer": "number",
"Integer": "number",
"Number": "number",
"object": "Object",
"String": "string",
"Void": "void"
},
"requireParamDescription": false,
"requireReturn": false
} ],
"valid-typeof": "error",
"yoda": "off"
}
};
6 changes: 0 additions & 6 deletions test/e2e/.eslintrc.json

This file was deleted.

26 changes: 26 additions & 0 deletions test/e2e/integration/001-hello-gutenberg.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,30 @@ describe( 'Hello Gutenberg', () => {
cy.url().should( 'include', 'post-new.php' );
cy.get( '[placeholder="Add title"]' ).should( 'exist' );
} );

it( 'Should have no history', () => {
cy.get( '.editor-history__undo:not( :disabled )' ).should( 'not.exist' );
cy.get( '.editor-history__redo:not( :disabled )' ).should( 'not.exist' );
} );

it( 'Should not prompt to confirm unsaved changes', ( done ) => {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was afraid this was a false positive because I thought Cypress would remove all popovers but confirmed it's breaking correctly when needed.

const timeout = setTimeout( () => {
done( new Error( 'Expected page reload' ) );
}, 5000 );

cy.window().then( ( window ) => {
function verify( event ) {
expect( event.returnValue ).to.equal( '' );

window.removeEventListener( 'beforeunload', verify );
clearTimeout( timeout );

done();
}

window.addEventListener( 'beforeunload', verify );

cy.reload();
} );
} );

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

❤️ Nice test

} );