<commit_before>#include <gtest/gtest.h>
#include <gmock/gmock.h>
#include <QWebSocket>
#include <QtTest/QtTest>

#include <LoginDialog.hpp>
#include <LoginVerificatorMock.hpp>
#include <ui_LoginDialog.h> // to get loginDialog UI definition

using namespace testing;

struct LoginDialogTestSuite : public ::testing::Test
{
    LoginDialogTestSuite();
    StrictMock<LoginVerificatorMock> loginVerificatorMock;
    StrictMock<QWebSocket> webSocketMock;
    LoginDialog m_sut;
};

LoginDialogTestSuite::LoginDialogTestSuite()
    : loginVerificatorMock{},
      webSocketMock{},
      m_sut(loginVerificatorMock, webSocketMock)
{}

TEST_F(LoginDialogTestSuite, InvokeMainWindowAfterSuccesfullServerConnection)
{
    m_sut.getUi()->userLogin->setText("login");
    m_sut.getUi()->userPassword->setText("<PASSWORD>");
    EXPECT_CALL(loginVerificatorMock, tryLogin(m_sut.getUi()->userPassword->text().toStdString(),
                                               m_sut.getUi()->userLogin->text().toStdString())).WillOnce(Return(true));
    QSignalSpy buttonSpy(m_sut.getUi()->login, SIGNAL(clicked(bool)));
    QTest::mouseClick(m_sut.getUi()->login, Qt::LeftButton);

    //QSignalSpy spy(m_sut.getUi(), SIGNAL(loginSucces()));
    //QCOMPARE(spy.count(), 1);

    emit webSocketMock.connected();
    EXPECT_EQ(1, buttonSpy.count());
}

TEST_F(LoginDialogTestSuite, DontInvokeMainWindowAfterSuccesfullServerConnection)
{
    m_sut.getUi()->userLogin->setText("login");
    m_sut.getUi()->userPassword->setText("<PASSWORD>");
    EXPECT_CALL(loginVerificatorMock, tryLogin(m_sut.getUi()->userPassword->text().toStdString(),
                                               m_sut.getUi()->userLogin->text().toStdString())).WillOnce(Return(false));
    QSignalSpy buttonSpy(m_sut.getUi()->login, SIGNAL(clicked(bool)));
    QTest::mouseClick(m_sut.getUi()->login, Qt::LeftButton);

    emit webSocketMock.connected();
    EXPECT_EQ(1, buttonSpy.count());
}

//TEST_F(LoginDialogTestSuite, SuccesServerConnection)
//{
//    m_sut.getUi()->userLogin->setText("login");
//    m_sut.getUi()->userPassword->setText("<PASSWORD>");
//    EXPECT_CALL(loginVerificatorMock, tryLogin(m_sut.getUi()->userPassword->text().toStdString(),
//                                               m_sut.getUi()->userLogin->text().toStdString())).WillOnce(Return(false));
//    QSignalSpy buttonSpy(m_sut.getUi()->login, SIGNAL(clicked(bool)));
//    QTest::mouseClick(m_sut.getUi()->login, Qt::LeftButton);

//    emit webSocketMock.connected();
//    EXPECT_EQ(1, buttonSpy.count());
//}

//TEST_F(LoginDialogTestSuite, SuccesAfterStateChangeServerConnection)
//{
//    QSignalSpy buttonSpy(m_sut.getUi()->login, SIGNAL(clicked(bool)));
//    QTest::mouseClick(m_sut.getUi()->login, Qt::LeftButton);

//    EXPECT_CALL(communicationManagerMock, handle());
//    emit webSocketMock.stateChanged(QAbstractSocket::ConnectedState);
//    EXPECT_EQ(1, buttonSpy.count());
//}

//TEST_F(LoginDialogTestSuite, FailAfterStateChangeServerConnection)
//{
//    QSignalSpy buttonSpy(m_sut.getUi()->login, SIGNAL(clicked(bool)));
//    QTest::mouseClick(m_sut.getUi()->login, Qt::LeftButton);

//    emit webSocketMock.stateChanged(QAbstractSocket::ConnectingState);
//    EXPECT_EQ(1, buttonSpy.count());
//}

//TEST_F(LoginDialogTestSuite, FailServerConnection)
//{
//    QSignalSpy buttonSpy(m_sut.getUi()->login, SIGNAL(clicked(bool)));
//    QTest::mouseClick(m_sut.getUi()->login, Qt::LeftButton);

//    EXPECT_EQ(1, buttonSpy.count());
//}

//#include "LoginDialogTestSuite.moc"<commit_msg>LogindialogTestSuite fix<commit_after>#include <gtest/gtest.h>
#include <gmock/gmock.h>
#include <QWebSocket>
#include <QtTest/QtTest>

#include <LoginDialog.hpp>
#include <LoginVerificatorMock.hpp>
#include <ui_LoginDialog.h> // to get loginDialog UI definition

using namespace testing;

struct LoginDialogTestSuite : public ::testing::Test
{
    LoginDialogTestSuite();
    StrictMock<LoginVerificatorMock> loginVerificatorMock;
    StrictMock<QWebSocket> webSocketMock;
    LoginDialog m_sut;
};

LoginDialogTestSuite::LoginDialogTestSuite()
    : loginVerificatorMock{},
      webSocketMock{},
      m_sut(loginVerificatorMock, webSocketMock)
{}

TEST_F(LoginDialogTestSuite, InvokeMainWindowAfterSuccesfullServerConnection)
{
    QSignalSpy buttonSpy(m_sut.getUi()->login, SIGNAL(clicked(bool)));
    QSignalSpy spy(&m_sut, SIGNAL(loginSucces()));

    m_sut.getUi()->userLogin->setText("login");
    m_sut.getUi()->userPassword->setText("<PASSWORD>");
    EXPECT_CALL(loginVerificatorMock, tryLogin(m_sut.getUi()->userPassword->text().toStdString(),
                                               m_sut.getUi()->userLogin->text().toStdString())).WillOnce(Return(true));
    emit webSocketMock.connected();
    QTest::mouseClick(m_sut.getUi()->login, Qt::LeftButton);

    EXPECT_EQ(1, buttonSpy.count());
    //QVERIFY(buttonSpy.wait(10));
    EXPECT_EQ(1, spy.count());
}

TEST_F(LoginDialogTestSuite, DontInvokeMainWindowAfterSuccesfullServerConnection)
{
    QSignalSpy buttonSpy(m_sut.getUi()->login, SIGNAL(clicked(bool)));
    QSignalSpy spy(&m_sut, SIGNAL(loginSucces()));

    m_sut.getUi()->userLogin->setText("login");
    m_sut.getUi()->userPassword->setText("<PASSWORD>");
    EXPECT_CALL(loginVerificatorMock, tryLogin(m_sut.getUi()->userPassword->text().toStdString(),
                                               m_sut.getUi()->userLogin->text().toStdString())).WillOnce(Return(false));
    emit webSocketMock.connected();
    QTest::mouseClick(m_sut.getUi()->login, Qt::LeftButton);

    EXPECT_EQ(1, buttonSpy.count());
    EXPECT_EQ(0, spy.count());
}

#include "LoginDialogTestSuite.moc"
{'fraction_non_alphanumeric': 0.16331569664902998, 'fraction_numerical': 0.002292768959435626, 'mean_word_length': 4.659680638722555, 'pattern_counts': {'":': 0, '<': 26, '<?xml version=': 0, '>': 82, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 10, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3307101', 'n_tokens_mistral': 1901, 'n_tokens_neox': 1897, 'n_words': 209}