Skip to content

ui::testing::TestNotifier

Header: winui/testing/TestNotifier.hpp.

Derives from ui::Notifier.

Notifier test double: shows nothing, keeps every notification it was handed, and clicks one on request.

Install it with set_notifier(); ui::notify() then reaches it. It uninstalls itself when destroyed.

Example:

ui::testing::TestNotifier notifier;
ui::testing::set_notifier(&notifier);
bool opened = false;

ui::notify({.title = "Export finished", .on_click = [&] { opened = true; }});
REQUIRE(notifier.shown.size() == 1);
REQUIRE(notifier.shown[0].title == "Export finished");
notifier.click(0);
REQUIRE(opened);

shown

std::vector<Notification> shown

Every notification shown so far, oldest first.

TestNotifier

TestNotifier() = default

~TestNotifier

~TestNotifier() override

Uninstalls it if it is still the installed notifier.

TestNotifier

TestNotifier(const TestNotifier&) = delete

operator=

TestNotifier& operator=(const TestNotifier&) = delete

notify

void notify(Notification notification) override

Appends notification to shown.

click

void click(std::size_t index)

What a user's click on shown[index] does: runs its on_click, if it has one.