package cz.moneta.test.regression.commercial.auto.smartauto;

import java.util.Date;
import java.text.SimpleDateFormat;

import cz.moneta.test.dsl.Harness;
import cz.moneta.test.dsl.util.DateUtils;
import cz.moneta.test.dsl.util.credentials.Keys.smart;
import cz.moneta.test.dsl.util.task.auto.smartauto.SmartAutoTasks;
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 cz.moneta.test.harness.support.auth.Key;

@TestScenario(name = "Application duplication.")
public class ApplicationDuplicationTest {

    @JiraTestCase(id = "LAMD-T1069")
    @TestCase(name = "Successfully duplicated application.")
    public void tcApplicationDuplicate(Harness harness, @Key(smart.auto.general) Credentials credentials) {
        SmartAutoTasks smartAutoTasks = harness.tasks().auto().smartAuto();

        String duplicateDate = DateUtils.getFormattedTodayDate("dd.MM.yyyy");
        String duplicateTitle = "TestDuplikace-" + new SimpleDateFormat("yyyy.MM.dd.HH.mm.ss").format(new Date());

        harness.withSmartAuto()
                .openLoginPage()
                .then(smartAutoTasks.login().loginWithCredentials(credentials))
                .clickMenuQueue()
                .checkHeadingSendApplication()
                .clickOpenApplication()
                .clickDuplicateApplication()
                .typeCalculationName(duplicateTitle)
                .clickDuplicateApplicationButtonOk()
                .clickMenuSaved()
                .checkSavedCalculationHeading()
                .checkForCalculationTitle(duplicateTitle)
                .checkForCalculationDate(duplicateDate)
                .checkForCalculationStatus();
    }
}
