Skip to content

Commit

Permalink
Add unit test for simple entity spawnarg change
Browse files Browse the repository at this point in the history
Test undoing and redoing a value change to a single spawnarg.
  • Loading branch information
Matthew Mott committed Nov 26, 2021
1 parent 325b69a commit 58d7ce5
Showing 1 changed file with 26 additions and 0 deletions.
26 changes: 26 additions & 0 deletions test/Entity.cpp
Expand Up @@ -370,6 +370,32 @@ TEST_F(EntityTest, CopySpawnargs)
EXPECT_EQ(overlap.size(), 0);
}

TEST_F(EntityTest, UndoRedoSpawnargValueChange)
{
// Create entity with initial default args. Note that we must add the node
// to the global map in order for undo to work.
auto cls = GlobalEntityClassManager().findClass("bucket_metal");
auto bucketNode = GlobalEntityModule().createEntity(cls);
scene::addNodeToContainer(bucketNode, GlobalMapModule().getRoot());
Entity& spawnArgs = bucketNode->getEntity();

// Make a simple value change
EXPECT_EQ(spawnArgs.getKeyValue("name"), "bucket_metal_1");
{
UndoableCommand cmd("changeKeyValue");
spawnArgs.setKeyValue("name", "another_bucket");
}

// Confirm we can undo this change
EXPECT_EQ(spawnArgs.getKeyValue("name"), "another_bucket");
GlobalUndoSystem().undo();
EXPECT_EQ(spawnArgs.getKeyValue("name"), "bucket_metal_1");

// Confirm we can redo the change
GlobalUndoSystem().redo();
EXPECT_EQ(spawnArgs.getKeyValue("name"), "another_bucket");
}

TEST_F(EntityTest, SelectEntity)
{
auto light = createByClassName("light");
Expand Down

0 comments on commit 58d7ce5

Please sign in to comment.