diff --git a/app/lib/memento.js b/app/lib/memento.js index b4a701b..caa9621 100644 --- a/app/lib/memento.js +++ b/app/lib/memento.js @@ -20,6 +20,14 @@ Ember.Memento = Ember.Mixin.create({ return length - mementoIndex - 1; }.property('_mementoIndex', '_memento.length').cacheable(), + canUndo: function() { + return this.get('undoCount') > 0; + }.property('undoCount').cacheable(), + + canRedo: function() { + return this.get('redoCount') > 0; + }.property('redoCount').cacheable(), + _mementoSizeChanged: function() { this._updateMemento(); }.observes('mementoSize'), diff --git a/app/tests/memento_tests.js b/app/tests/memento_tests.js index e638a96..d484a63 100644 --- a/app/tests/memento_tests.js +++ b/app/tests/memento_tests.js @@ -635,6 +635,57 @@ function() { equal(get(obj, 'redoCount'), 0, 'redoCount stays 0'); }); +module("canUndo AND canRedo", { + teardown: cleanObj +}); + +test("they are true when a undo/redo is possible", +function() { + obj = Ember.Object.create(Ember.Memento, { + mementoProperties: 'str'.w(), + + str: 'frozen' + }); + + equal(get(obj, 'canUndo'), false); + equal(get(obj, 'canRedo'), false); + + set(obj, 'str', 'banana'); + + equal(get(obj, 'canUndo'), true); + equal(get(obj, 'canRedo'), false); + + set(obj, 'str', 'Frozen Banana'); + + equal(get(obj, 'canUndo'), true); + equal(get(obj, 'canRedo'), false); + + obj.undo(); + + equal(get(obj, 'canUndo'), true); + equal(get(obj, 'canRedo'), true); + + obj.undo(); + + equal(get(obj, 'canUndo'), false); + equal(get(obj, 'canRedo'), true); + + obj.redo(); + + equal(get(obj, 'canUndo'), true); + equal(get(obj, 'canRedo'), true); + + obj.redo(); + + equal(get(obj, 'canUndo'), true); + equal(get(obj, 'canRedo'), false); + + obj.redo(); + + equal(get(obj, 'canUndo'), true); + equal(get(obj, 'canRedo'), false); +}); + module("clearHistory", { teardown: cleanObj });