#include "WidgetTest.hpp"

#include <eedb/widgets/DefaultNavigationBar.hpp>

#include <Wt/WMenuItem>
#include <Wt/WNavigationBar>

struct SimpleCallback {
    MOCK_METHOD0(callback, void());
};

class DefaultNavigationBarTests : public WidgetTest {
  public:
    DefaultNavigationBarTests() : WidgetTest(), sut(std::make_unique< eedb::DefaultNavigationBar >()) {
        sut->attachTo(app.root());
    }

    auto find_logoutItem() {
        return ut_find< Wt::WMenuItem >("navigation_bar.session_menu.logout");
    }

    auto find_homeItem() {
        return ut_find< Wt::WMenuItem >("navigation_bar.home_menu");
    }

    auto find_navigationBar() {
        return ut_find< Wt::WNavigationBar >("navigation_bar");
    }

  protected:
    std::unique_ptr< eedb::DefaultNavigationBar > sut;
};

TEST_F(DefaultNavigationBarTests, hasAllNeededElements) {
    find_logoutItem();
    find_homeItem();
    find_navigationBar();
}

TEST_F(DefaultNavigationBarTests, loginAction) {
    SimpleCallback cb;
    EXPECT_CALL(cb, callback());
    sut->registerLogoutAction([&]() { cb.callback(); });

    auto logoutItem = find_logoutItem();
    logoutItem->triggered().emit(logoutItem);
}
