From 17a41da5a7a14879cf490c81914084791c4c494c Mon Sep 17 00:00:00 2001 From: Cameron Hessler Date: Mon, 26 Sep 2022 07:56:25 -0500 Subject: [PATCH] fix(core): Can() does not work for setting marks (#3223) 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. Co-authored-by: Cameron Hessler --- 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 ead2c91b..42c168ad 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 b6702ded..02720962 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 391f26ab..d43c0f0e 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 d47ee9dd..6fe89b63 100644 --- a/demos/src/Examples/Default/Vue/index.vue +++ b/demos/src/Examples/Default/Vue/index.vue @@ -1,15 +1,15 @@