package cz.moneta.test.regression.channels.digital.ib.newib.login.fon;

import cz.moneta.test.dsl.Harness;
import cz.moneta.test.dsl.newib.tasks.NewIbTasks;
import cz.moneta.test.harness.annotations.Environment;
import cz.moneta.test.harness.annotations.JiraTestCase;
import cz.moneta.test.harness.annotations.TestCase;
import cz.moneta.test.harness.annotations.TestScenario;
import cz.moneta.test.harness.support.auth.Credentials;
import org.junit.jupiter.api.BeforeAll;

@TestScenario(name = "Test to login and logout to new IB Fon")
public class LoginLogoutNibFonTest {
    Credentials clientCredentials;

    @BeforeAll
    public void getCredentials(Harness harness) {
        String clientBirthNumber = harness.getConfig("nib.rc.login-logout");

        clientCredentials = harness.tasks()
                .udebs()
                .findCredentialsByRC(clientBirthNumber);
    }

    @TestCase(name = "Login to new IB and logout Fon", environments = {Environment.TST1, Environment.PPE})
    @JiraTestCase(id = "SB-T9268")
    public void loginAndLogoutInNewIbFon(Harness harness) {
        NewIbTasks newIbTasks = harness.tasks().newIb();

        harness.withNewIb()
                .openLoginPage()
                .then(newIbTasks.loginWithUsernamePasswordAndDefaultMobKey(clientCredentials.getUsername(), clientCredentials.getPassword()))
                .then(newIbTasks.loginLogoutNewIb());
    }

    @TestCase(name = "Login to new IB and wait to session timeout Fon", environments = {Environment.TST1, Environment.PPE})
    @JiraTestCase(id = "SB-T9959")
    public void loginAndLogoutAfterFiveMinutesFon(Harness harness) {
        NewIbTasks newIbTasks = harness.tasks().newIb();

        harness.withNewIb()
                .openLoginPage()
                .then(newIbTasks.loginWithUsernamePasswordAndDefaultMobKey(clientCredentials.getUsername(), clientCredentials.getPassword()))
                .then(newIbTasks.loginLogoutAfterSessionTimeoutNewIb())
                .then(newIbTasks.loginWithUsernamePasswordAndDefaultMobKey(clientCredentials.getUsername(), clientCredentials.getPassword()))
                .waitFiveMinutesToLogout()
                .checkLogoutSessionTimeoutText();
    }
}
