From 67626eabf3757114b10731a24908c82ffa4be2f9 Mon Sep 17 00:00:00 2001 From: Cameron Hessler Date: Wed, 21 Sep 2022 19:31:18 -0500 Subject: [PATCH] fix(core): Can() does not work for setting marks Previously, setting marks did no schema validation checks for dry runs (like the `.can()` command). The `setMark` raw command will now properly check if the mark is possible to be set given the editor node/mark schema. --- demos/src/Examples/Default/React/index.jsx | 50 ++++- .../src/Examples/Default/React/index.spec.js | 26 +++ .../src/Examples/Default/Svelte/index.svelte | 18 +- demos/src/Examples/Default/Vue/index.vue | 12 +- packages/core/src/commands/setMark.ts | 46 ++++- tests/cypress/integration/core/can.spec.ts | 173 ++++++++++++++++++ 6 files changed, 313 insertions(+), 12 deletions(-) diff --git a/demos/src/Examples/Default/React/index.jsx b/demos/src/Examples/Default/React/index.jsx index ead2c91bfb..42c168adb7 100644 --- a/demos/src/Examples/Default/React/index.jsx +++ b/demos/src/Examples/Default/React/index.jsx @@ -13,24 +13,52 @@ const MenuBar = ({ editor }) => { <> - - diff --git a/demos/src/Examples/Default/React/index.spec.js b/demos/src/Examples/Default/React/index.spec.js index b6702ded90..0272096213 100644 --- a/demos/src/Examples/Default/React/index.spec.js +++ b/demos/src/Examples/Default/React/index.spec.js @@ -27,6 +27,32 @@ context('/src/Examples/Default/React/', () => { ] buttonMarks.forEach(m => { + it(`should disable ${m.label} when the code tag is enabled for cursor`, () => { + cy.get('.ProseMirror').type('{selectall}Hello world') + cy.get('button').contains('code').click() + cy.get('button').contains(m.label).should('be.disabled') + }) + + it(`should enable ${m.label} when the code tag is disabled for cursor`, () => { + cy.get('.ProseMirror').type('{selectall}Hello world') + cy.get('button').contains('code').click() + cy.get('button').contains('code').click() + cy.get('button').contains(m.label).should('not.be.disabled') + }) + + it(`should disable ${m.label} when the code tag is enabled for selection`, () => { + cy.get('.ProseMirror').type('{selectall}Hello world{selectall}') + cy.get('button').contains('code').click() + cy.get('button').contains(m.label).should('be.disabled') + }) + + it(`should enable ${m.label} when the code tag is disabled for selection`, () => { + cy.get('.ProseMirror').type('{selectall}Hello world{selectall}') + cy.get('button').contains('code').click() + cy.get('button').contains('code').click() + cy.get('button').contains(m.label).should('not.be.disabled') + }) + it(`should apply ${m.label} when the button is pressed`, () => { cy.get('.ProseMirror').type('{selectall}Hello world') cy.get('button').contains('paragraph').click() diff --git a/demos/src/Examples/Default/Svelte/index.svelte b/demos/src/Examples/Default/Svelte/index.svelte index 391f26abfa..d43c0f0e3c 100644 --- a/demos/src/Examples/Default/Svelte/index.svelte +++ b/demos/src/Examples/Default/Svelte/index.svelte @@ -55,24 +55,28 @@
- - + +
{/if} diff --git a/demos/src/Examples/Default/Vue/index.vue b/demos/src/Examples/Default/Vue/index.vue index d47ee9ddd0..6fe89b6397 100644 --- a/demos/src/Examples/Default/Vue/index.vue +++ b/demos/src/Examples/Default/Vue/index.vue @@ -1,15 +1,15 @@