UiElement: add unit test to cover the doRevealYourself functionality

...which is now kind-of specified and we're providing a default implementation,
so it should be documented in AbstractTangible_test
This commit is contained in:
Fischlurch 2018-09-01 15:42:36 +02:00
parent 026049a13c
commit 1ab42b298d

View file

@ -179,8 +179,9 @@ namespace test {
verify_mockManipulation();
invokeCommand();
markState();
notify();
mutate();
revealer();
// notify();
// mutate();
}
@ -362,10 +363,6 @@ namespace test {
*
* The second part of this test _replays_ such a state mark, which causes
* the`doMark()` operation on the UI element to be invoked.
* @todo maybe we'll even provide a default implementation for expand/collapse
* which then means that, by replaying the mentioned state marks, the
* `doExpand()` or `doCollapse()` should be re-invoked, of course
* without issuing a further notification
* @note this test does not cover or even emulate the operation of the
* "state manager", since the goal is to cover the _UI element_
* protocol. We'll just listen at the bus and replay messages.
@ -473,6 +470,80 @@ namespace test {
}
/** @test configure a handler for the (optional) "revealYourself" functionality.
* We install a lambda to supply the actual implementation action, which can then
* either be triggered by a signal/slot invocation, or by sending a "state mark".
*/
void
revealer ()
{
MARK_TEST_FUN
EventLog nexusLog = gui::test::Nexus::startNewLog();
MockElm mock("target");
ID targetID = mock.getID();
sigc::signal<void> trigger_reveal;
trigger_reveal.connect (sigc::mem_fun(mock, &Tangible::slotReveal));
CHECK (not mock.isTouched());
CHECK (not mock.isExpanded());
CHECK (mock.ensureNot("reveal"));
CHECK (mock.ensureNot("expanded"));
CHECK (nexusLog.ensureNot("state-mark"));
bool revealed = false;
mock.installRevealer([&]()
{ // NOTE: our mock "implementation" of the revealYourself functionality
mock.slotExpand(); // explicitly prompts the element to expand itself,
revealed = true; // and then via closure sets a flag we can verify.
});
trigger_reveal();
CHECK (true == revealed);
CHECK (mock.isExpanded());
CHECK (mock.verifyEvent("create","target")
.beforeCall("revealYourself")
.beforeCall("expand").arg(true)
.beforeEvent("expanded"));
// invoking the slotExpand() also emitted a state mark to persist that expansion state...
CHECK (nexusLog.verifyCall("note").arg(targetID, GenNode{"expand", true})
.before("handling state-mark"));
// second test: the same can be achieved via UI-Bus message...
revealed = false;
auto stateMark = GenNode{"revealYourself", 47}; // (payload argument irrelevant)
auto& uiBus = gui::test::Nexus::testUI();
CHECK (nexusLog.ensureNot("revealYourself"));
uiBus.mark (targetID, stateMark); // send the state mark message to reveal the element
CHECK (true == revealed);
CHECK (mock.verifyMark("revealYourself", 47)
.afterEvent("expanded")
.beforeCall("revealYourself")
.beforeCall("expand").arg(true));
CHECK (nexusLog.verifyCall("mark").arg(targetID, stateMark)
.after("handling state-mark")
.before("revealYourself")
.beforeEvent("delivered mark"));
cout << "____Event-Log_________________\n"
<< util::join(mock.getLog(), "\n")
<< "\n───╼━━━━━━━━━╾────────────────"<<endl;
cout << "____Nexus-Log_________________\n"
<< util::join(nexusLog, "\n")
<< "\n───╼━━━━━━━━━╾────────────────"<<endl;
}
/** @test receive various kinds of notifications.
* Send message, error and flash messages via Bus to the element
* and verify the doMsg, doErr or doFlash handlers were invoked.