During unit testing, I want to test that specific methods did not affect UndoManager state. How to test for this?
In other words: How can I reliably check from UndoManager, if someone used it so that its undo/redo history was changed in any way?
During unit testing, I want to test that specific methods did not affect UndoManager state. How to test for this?
In other words: How can I reliably check from UndoManager, if someone used it so that its undo/redo history was changed in any way?
You could clear it at the start of the test and check to see if itâs got any entries in afterwards?
That could work. If the UndoManager is completely empty, then calling Undo wonât leave any traceable proof that it happened. So I probably also need to put some âdebug-test-eventsâ into the UndoManager before running the tests, so I can observe if anything called Undo during the test.
UndoManager doesnât seem to return expected values:
node = juce::ValueTree(juce::Identifier("XYZW"));
undoManager.clearUndoHistory();
undoManager.beginNewTransaction("Transaction 1");
node.setProperty(PROPERTY_ID, 1, &undoManager);
// undoManager.getNumActionsInCurrentTransaction() returns 1 at this point as expected
undoManager.beginNewTransaction("Transaction 2");
node.setProperty(PROPERTY_ID, 2, &undoManager);
// undoManager.getNumActionsInCurrentTransaction() again returns 1 at this point as expected
undoManager.undo();
juce::String transactionName = undoManager.getCurrentTransactionName();
int property = node[PROPERTY_ID];
int actionCount = undoManager.getNumActionsInCurrentTransaction();
// Returned values:
// transactionName = "Transaction 1"
// property = 1
// actionCount = 0 !!!!!!!!
I would assume that the returned actionCount would be 1 at the end, but the returned value is 0. How can that be? I would assume that actionCount would indicate how many actions there are to be handled by Undo in the current transaction. That number would be 1 (the single property change).
Well, I agree. Youâd have to trace into that maybe?
I think it works like it should. With one call to undo youâre now at Transaction 1 which has one action in it. After a second call to undo getNumActionsInCurrentTransaction should return zero.
But thatâs not what is happening:
I did only one Undo.
The name is correct: âTransaction 1â.
But the number of actions in it is said to be 0, which is wrong. It should be 1.
The property value was reverted back to 1, which is correct.
I think you are mixing up actions and transactions
The manager also uses the concept of âtransactionsâ to group the actions together - all actions performed between calls to beginNewTransaction() are grouped together and are all undone/redone as a group.
However, if you want to simply check if âsomethingâ has changed in your undo manager, you can get a grasp of its current state by calling getUndoDescriptions() and getRedoDescriptions(): any addition to the undo manager or navigation through its transactions, should change whatâs returned by those functions.