diff --git a/tests/javascript/form_editor/store/selectors.spec.js b/tests/javascript/form_editor/store/selectors.spec.js index 65fbbf8527..e5dc5818b1 100644 --- a/tests/javascript/form_editor/store/selectors.spec.js +++ b/tests/javascript/form_editor/store/selectors.spec.js @@ -59,4 +59,68 @@ describe('Selectors', () => { expect(result).to.equal('Hello 2'); }); }); + + describe('hasEditorUndo', () => { + it('Should return false for empty history', () => { + const state = { + editorHistory: [], + editorHistoryOffset: 0, + }; + expect(selectors.hasEditorUndo(state)).to.equal(false); + }); + + it('Should return true for one record in history', () => { + const state = { + editorHistory: [ + { data: 'some data' }, + ], + editorHistoryOffset: 0, + }; + expect(selectors.hasEditorUndo(state)).to.equal(true); + }); + + it('Should return false for two records in history on offset one', () => { + const state = { + editorHistory: [ + { data: 'some data 1' }, + { data: 'some data 2' }, + ], + editorHistoryOffset: 1, + }; + expect(selectors.hasEditorUndo(state)).to.equal(false); + }); + + it('Should return true for three records in history on offset one', () => { + const state = { + editorHistory: [ + { data: 'some data 1' }, + { data: 'some data 2' }, + { data: 'some data 3' }, + ], + editorHistoryOffset: 1, + }; + expect(selectors.hasEditorUndo(state)).to.equal(true); + }); + }); + + describe('hasEditorRedo', () => { + it('Should return false for empty history', () => { + const state = { + editorHistory: [], + editorHistoryOffset: 0, + }; + expect(selectors.hasEditorRedo(state)).to.equal(false); + }); + + it('Should return true for two records in history on offset one', () => { + const state = { + editorHistory: [ + { data: 'some data 1' }, + { data: 'some data 2' }, + ], + editorHistoryOffset: 1, + }; + expect(selectors.hasEditorRedo(state)).to.equal(true); + }); + }); });