-
-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(block-tunes): enter keydown problems (#2650)
* debug enter press * fix sync set caret * fix enter keydown problems + tests addedd * Update search-input.ts * add changelog * add useful log to cypress custom comand * Update commands.ts
- Loading branch information
Showing
11 changed files
with
170 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,3 +17,4 @@ dist/ | |
|
||
coverage/ | ||
.nyc_output/ | ||
.vscode/launch.json |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
/** | ||
* Debounce timeout for selection change event | ||
* {@link modules/ui.ts} | ||
*/ | ||
export const selectionChangeDebounceTimeout = 180; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,107 @@ | ||
import { selectionChangeDebounceTimeout } from '../../../../src/components/constants'; | ||
|
||
describe('BlockTunes', function () { | ||
describe('Search', () => { | ||
it('should be focused after popover opened', () => { | ||
cy.createEditor({ | ||
data: { | ||
blocks: [ | ||
{ | ||
type: 'paragraph', | ||
data: { | ||
text: 'Some text', | ||
}, | ||
}, | ||
], | ||
}, | ||
}); | ||
|
||
cy.get('[data-cy=editorjs]') | ||
.find('.ce-paragraph') | ||
.click() | ||
.type('{cmd}/') | ||
.wait(selectionChangeDebounceTimeout); | ||
|
||
/** | ||
* Caret is set to the search input | ||
*/ | ||
cy.window() | ||
.then((window) => { | ||
const selection = window.getSelection(); | ||
|
||
expect(selection.rangeCount).to.be.equal(1); | ||
|
||
const range = selection.getRangeAt(0); | ||
|
||
cy.get('[data-cy=editorjs]') | ||
.find('[data-cy="block-tunes"] .cdx-search-field') | ||
.should(($block) => { | ||
expect($block[0].contains(range.startContainer)).to.be.true; | ||
}); | ||
}); | ||
}); | ||
}); | ||
|
||
describe('Keyboard only', function () { | ||
it('should not delete the currently selected block when Enter pressed on a search input (or any block tune)', function () { | ||
const ENTER_KEY_CODE = 13; | ||
|
||
cy.createEditor({ | ||
data: { | ||
blocks: [ | ||
{ | ||
type: 'paragraph', | ||
data: { | ||
text: 'Some text', | ||
}, | ||
}, | ||
], | ||
}, | ||
}); | ||
|
||
cy.get('[data-cy=editorjs]') | ||
.find('.ce-paragraph') | ||
.click() | ||
.type('{cmd}/') | ||
.wait(selectionChangeDebounceTimeout) | ||
.keydown(ENTER_KEY_CODE); | ||
|
||
/** | ||
* Block should have same text | ||
*/ | ||
cy.get('[data-cy="block-wrapper"') | ||
.should('have.text', 'Some text'); | ||
}); | ||
|
||
it('should not unselect currently selected block when Enter pressed on a block tune', function () { | ||
const ENTER_KEY_CODE = 13; | ||
|
||
cy.createEditor({ | ||
data: { | ||
blocks: [ | ||
{ | ||
type: 'paragraph', | ||
data: { | ||
text: 'Some text', | ||
}, | ||
}, | ||
], | ||
}, | ||
}); | ||
|
||
cy.get('[data-cy=editorjs]') | ||
.find('.ce-paragraph') | ||
.click() | ||
.type('{cmd}/') | ||
.wait(selectionChangeDebounceTimeout) | ||
.keydown(ENTER_KEY_CODE); | ||
|
||
/** | ||
* Block should not be selected | ||
*/ | ||
cy.get('[data-cy="block-wrapper"') | ||
.first() | ||
.should('have.class', 'ce-block--selected'); | ||
}); | ||
}); | ||
}); |