Fix readOnly.isEnabled getter (#1831)

* Fix readOnly.isEnabled getter

* Add tests

* Update CHANGELOG.md

Co-authored-by: Peter Savchenko <specc.dev@gmail.com>
This commit is contained in:
George Berezhnoy 2022-04-25 20:40:29 +01:00 committed by GitHub
parent 8f156a87ea
commit 6cd6bd5de3
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 58 additions and 2 deletions

View file

@ -5,8 +5,9 @@
- `New`*UI* — The Toolbox became vertical 🥳
- `Improvement`*UI* — the Plus button will always be shown (previously, it appears only for empty blocks)
- `Improvement`*Dev Example Page* - Server added to allow opening example page on other devices in network.
- `Fix` - `UI` - the Toolbar won't move on hover at mobile viewports. Resolves [#1972](https://github.com/codex-team/editor.js/issues/1972)
- `Fix` `UI` the Toolbar won't move on hover at mobile viewports. Resolves [#1972](https://github.com/codex-team/editor.js/issues/1972)
- `Fix``OnChange` event invocation after block insertion. [#1997](https://github.com/codex-team/editor.js/issues/1997)
- `Fix``ReadOnly` — the `readonly.isEnabled` API getter now works correctly after `readonly.toggle()` calling. Resolves [#1822](https://github.com/codex-team/editor.js/issues/1822)
### 2.23.2

View file

@ -10,9 +10,14 @@ export default class ReadOnlyAPI extends Module {
* Available methods
*/
public get methods(): ReadOnly {
const getIsEnabled = (): boolean => this.isEnabled;
// eslint-disable-next-line @typescript-eslint/no-this-alias
return {
toggle: (state): Promise<boolean> => this.toggle(state),
isEnabled: this.isEnabled,
get isEnabled(): boolean {
return getIsEnabled();
},
};
}

View file

@ -0,0 +1,50 @@
import EditorJS, { EditorConfig } from '../../../types';
describe('ReadOnly API spec', () => {
function createEditor(config?: EditorConfig): void {
const editorConfig = Object.assign({}, config || {});
cy.createEditor(editorConfig).as('editorInstance');
}
it('should return correct value for readOnly.isEnabled when editor initialized in normal mode', () => {
createEditor();
cy
.get<EditorJS>('@editorInstance')
.then(editor => {
expect(editor.readOnly.isEnabled).to.be.false;
});
});
it('should return correct value for readOnly.isEnabled when editor initialized in read-only mode', () => {
createEditor({
readOnly: true,
});
cy
.get<EditorJS>('@editorInstance')
.then(editor => {
expect(editor.readOnly.isEnabled).to.be.true;
});
});
it('should return correct value for readOnly.isEnabled when read-only mode toggled', () => {
createEditor();
cy
.get<EditorJS>('@editorInstance')
.then(async editor => {
expect(editor.readOnly.isEnabled).to.be.false;
editor.readOnly.toggle()
.then(() => {
expect(editor.readOnly.isEnabled).to.be.true;
})
.then(() => editor.readOnly.toggle())
.then(() => {
expect(editor.readOnly.isEnabled).to.be.false;
});
});
});
});