Skip to content

Commit

Permalink
Unit test for PropertiesRowStrategy when item is hidden
Browse files Browse the repository at this point in the history
  • Loading branch information
gpospelov committed Jan 22, 2021
1 parent 4dad984 commit 4175148
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 0 deletions.
24 changes: 24 additions & 0 deletions tests/testviewmodel/TestToyParticleItem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,16 @@ TEST_F(ToyParticleItemTest, TopLevelItems)
EXPECT_EQ(Utils::TopLevelItems(*particle), std::vector<SessionItem*>{});
}

TEST_F(ToyParticleItemTest, TopLevelItemsWhenHidden)
{
ToyItems::SampleModel model;
auto particle = model.insertItem<ToyItems::ParticleItem>();
particle->setVisible(false);

EXPECT_EQ(Utils::TopLevelItems(*model.rootItem()), std::vector<SessionItem*>({}));
EXPECT_EQ(Utils::TopLevelItems(*particle), std::vector<SessionItem*>{});
}

TEST_F(ToyParticleItemTest, SinglePropertyItems)
{
ToyItems::SampleModel model;
Expand All @@ -53,3 +63,17 @@ TEST_F(ToyParticleItemTest, SinglePropertyItems)
particle->getItem(ToyItems::ParticleItem::P_SHAPES)};
EXPECT_EQ(Utils::SinglePropertyItems(*particle), expected);
}

TEST_F(ToyParticleItemTest, SinglePropertyItemsWhenPropertyHidden)
{
ToyItems::SampleModel model;
auto particle = model.insertItem<ToyItems::ParticleItem>();

EXPECT_EQ(Utils::TopLevelItems(*model.rootItem()), std::vector<SessionItem*>({particle}));

EXPECT_EQ(Utils::SinglePropertyItems(*model.rootItem()), std::vector<SessionItem*>{});

particle->getItem(ToyItems::ParticleItem::P_POSITION)->setVisible(false);
std::vector<SessionItem*> expected = {particle->getItem(ToyItems::ParticleItem::P_SHAPES)};
EXPECT_EQ(Utils::SinglePropertyItems(*particle), expected);
}
19 changes: 19 additions & 0 deletions tests/testviewmodel/propertiesrowstrategy.test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -152,3 +152,22 @@ TEST_F(PropertiesRowStrategyTest, vectorItemInModelContext)
auto items = strategy.constructRow(model.rootItem());
EXPECT_EQ(items.size(), 0);
}

//! Checks row construction for vector item when 'y' is hidden.
//! There should be 2 view items looking to 'x' and 'z' properties.

TEST_F(PropertiesRowStrategyTest, vectorItemWhenChildHidden)
{
VectorItem item;
item.getItem(VectorItem::P_Y)->setVisible(false);

PropertiesRowStrategy strategy({"a", "b", "c"});
auto items = strategy.constructRow(&item);

// views should look at 3 property items
auto view_x = items.at(0).get();
EXPECT_EQ(view_x->item(), item.getItem(VectorItem::P_X));

auto view_y = items.at(1).get();
EXPECT_EQ(view_y->item(), item.getItem(VectorItem::P_Z));
}

0 comments on commit 4175148

Please sign in to comment.