Skip to content
This repository has been archived by the owner on Jul 1, 2020. It is now read-only.

Commit

Permalink
Add tests for complex example and when mementoSize changes
Browse files Browse the repository at this point in the history
  • Loading branch information
pangratz committed May 16, 2012
1 parent 756cb2e commit e49a842
Showing 1 changed file with 77 additions and 0 deletions.
77 changes: 77 additions & 0 deletions app/tests/memento_tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -558,6 +558,83 @@ function() {
equal(get(obj, 'redoCount'), 1, 'redoCount is 1 after an undo');
});

test("complex example",
function() {
obj = Ember.Object.create(Ember.Memento, {
mementoProperties: 'str'.w(),
str: 'hansi'
});

equal(get(obj, 'undoCount'), 0, 'precond - undoCount is initially 0');
equal(get(obj, 'redoCount'), 0, 'precond - redoCount is initially 0');

set(obj, 'str', 'frozen banana');

equal(get(obj, 'undoCount'), 1, 'undoCount is 1 when a undo can be done');
equal(get(obj, 'redoCount'), 0, 'redoCount stays 0');

set(obj, 'str', 'hubert');

equal(get(obj, 'undoCount'), 2, 'undoCount is increased when a property changes');
equal(get(obj, 'redoCount'), 0, 'redoCount stays 0');

obj.undo();

equal(get(obj, 'undoCount'), 1, 'undoCount is 1 after an undo');
equal(get(obj, 'redoCount'), 1, 'redoCount is 1 after an undo');

obj.undo();

equal(get(obj, 'undoCount'), 0, 'undoCount is 0 after an undo');
equal(get(obj, 'redoCount'), 2, 'redoCount is 2 after an undo');

obj.undo();

equal(get(obj, 'undoCount'), 0, 'undoCount is 0 after an undo');
equal(get(obj, 'redoCount'), 2, 'redoCount is 2 after an undo');

obj.redo();

equal(get(obj, 'undoCount'), 1, 'undoCount is 1 after an undo');
equal(get(obj, 'redoCount'), 1, 'redoCount is 1 after an undo');

obj.redo();

equal(get(obj, 'undoCount'), 2, 'undoCount is 2 after an undo');
equal(get(obj, 'redoCount'), 0, 'redoCount is 0 after an undo');

obj.redo();

equal(get(obj, 'undoCount'), 2, 'undoCount is 2 after an undo');
equal(get(obj, 'redoCount'), 0, 'redoCount is 0 after an undo');
});

test("change when mementoSize is changed",
function() {
obj = Ember.Object.create(Ember.Memento, {
mementoProperties: 'str'.w(),
str: 'hansi'
});

equal(get(obj, 'undoCount'), 0, 'precond - undoCount is initially 0');
equal(get(obj, 'redoCount'), 0, 'precond - redoCount is initially 0');

set(obj, 'str', 'frozen banana');

equal(get(obj, 'undoCount'), 1, 'undoCount is 1 when a undo can be done');
equal(get(obj, 'redoCount'), 0, 'redoCount stays 0');

set(obj, 'str', 'hubert');

equal(get(obj, 'undoCount'), 2, 'undoCount is increased when a property changes');
equal(get(obj, 'redoCount'), 0, 'redoCount stays 0');

set(obj, 'mementoSize', 1);

equal(get(obj, 'undoCount'), 1, 'undoCount is decreased to 1');
equal(get(obj, 'redoCount'), 0, 'redoCount stays 0');
});

module("clearHistory", {
teardown: cleanObj
});
Expand Down

0 comments on commit e49a842

Please sign in to comment.