Untitled

mail@pastecode.io avatar
unknown
plain_text
23 days ago
13 kB
3
Indexable
Never
using NUnit.Framework;
using OpenQA.Selenium;
using OpenQA.Selenium.Interactions;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Transactions;

namespace MilleDeskTests.PageObjectPattern
{
    public class LoanOtherDetails : BasePage
    {
        private IWebElement transactionDetails => Find(By.XPath("//*[text()='Szczegóły transakcji']/parent::div/parent::div/parent::div"));
        private IWebElement collateralDetails => Find(By.XPath("//*[text()='Szczegóły zabezpieczenia']/parent::div/parent::div/parent::div"));
        private IWebElement historyOfChanges => Find(By.XPath("//*[text()='Historia zmian']/parent::div/parent::div/parent::div"));
        private IWebElement setDetails => Find(By.XPath("//*[text()='Szczegóły zestawu']/parent::div/parent::div/parent::div"));
        private IWebElement transactionFilter => Find(By.XPath("//*[@class='loan-details-transaction-list-filters']//*[@class='Select__value-container']"));
        private IWebElement transactionDatePicker => Find(By.XPath("//*[@class='loan-details-transaction-list-filters']//*[contains(@class, 'DatePickerRangeContainer DatePickerRangeContainer')]"));
        private IWebElement collateralListFilter => Find(By.XPath("//*[text()='Lista zabezpieczeń']/parent::div/parent::div//*[@class='Select__value-container']"));
        private IWebElement changeTypeInput => Find(By.XPath("//*[@id='changeType']"));
        private IWebElement changesList => Find(By.XPath("//*[@class='loan-details-transaction-maintenance-list-filter']//*[@class='DatePickerRangeContainer DatePickerRangeContainer--vertical']"));
        private IWebElement printScheduleButton => Find(By.XPath("//*[@id='print-schedule-button']"));
        private IWebElement scheduleList => Find(By.XPath("//*[@id='schedule-list']"));
        private IWebElement printPaymentSlipsButton => Find(By.XPath("//*[@id='print-payment-slips-button']"));
        private IWebElement overduePaymentsCalender => Find(By.XPath("//*[@class='loan-details-past-due-payments']/parent::div//*[@class='DatePickerRangeContainer__value']"));
        private IWebElement statusFilter => Find(By.XPath("//*[@class='loan-details-memo-log-changes-filter']/*[contains(@class, 'Dropdown')]"));
        private IWebElement memoLogDatePicker => Find(By.XPath("//*[@class='loan-details-memo-log-changes-filter']/*[contains(@class, 'DatePicker')]"));

        private List<IWebElement> subHeaders => FindMany(By.XPath("//*[@id='rc-tabs-1-panel-1']//div[@class='ant-collapse-header']"));
        private List<IWebElement> loanScheduleHeaders => FindMany(By.XPath("//*[@class='loan-details-schedule-list']/div/div/p"));
        private List<IWebElement> transactionListLinks => FindMany(By.XPath("//*[contains(@id,'transaction-list') and contains(@id, 'Link')]"));

        private List<string> overduePaymentsHeaders => FindMany(By.XPath("//*[@class='loan-details-past-due-payments']/parent::div//*[contains(@class,'Typography Typography--dark Typography--normal Typography--bold Typography--sentence Typography--small')]")).Select(e => e.Text).ToList();
        private List<string> loanScheduleDataLabels => FindMany(By.XPath("//*[@class='loan-details-schedule-list']//span")).Select(e => e.Text).ToList();
        private List<string> overduePaymentsLabels => FindMany(By.XPath("//*[@class='loan-details-past-due-payments']/div//p/span")).Select(e => e.Text).ToList();

        private List<CollateralListRows> collateralListRows => FindMany(By.XPath("//*[@id='collateral-list']//*[contains(@class,'ant-table-row ant-table-row-level-0')]")).Select(e => new CollateralListRows(e)).ToList();
        private List<Alert> alerts => FindMany(By.XPath("//*[@id='rc-tabs-1-panel-1']//*[@role='alert']")).Select(e => new Alert(e)).ToList();

        private DetailsModal transactionDetailsModal => new DetailsModal(transactionDetails);
        private DetailsModal collateralDetailsModal => new DetailsModal(collateralDetails);
        private DetailsModal historyOfChangesModal => new DetailsModal(historyOfChanges);
        private DetailsModal setDetailsModal => new DetailsModal(setDetails);

        private DatePicker overduePaymentsDatePicker => new DatePicker(overduePaymentsCalender);

        public LoanOtherDetails(IWebDriver driver, bool validation = true) : base(driver, validation)
        {
        }

        private void CheckTransactionLink()
        {
            foreach (var transaction in transactionListLinks)
            {
                Wait.Until(ExpectedConditions.PageLoaded);
                transaction.Click();
                Wait.Until(ExpectedConditions.LoaderDisappears);
                Assert.Multiple(() =>
                {
                    Wait.Until((e) =>
                    {
                        return transactionDetailsModal.Subheaders.Count > 0;
                    });
                    Assert.That(transactionDetailsModal.Subheaders.Select(e => e.Text).ToList(), Is.EqualTo(new List<string> { "Dane podstawowe", "Dane finansowe", "Dane niefinansowe" }));
                    Assert.That(transactionDetailsModal.SectionContentLabels.Select(e => e.Text).ToList(), Is.SupersetOf(new List<string> { "Typ", "Całkowita kwota transakcji", "Nowy kod/nazwa produktu" }));
                });
                transactionDetailsModal.CloseModal();
            }
        }

        private void CheckCollateralDescriptionLink()
        {
            foreach (var row in collateralListRows)
            {
                collateralListRows.First().Description.Click();
                Wait.Timeout = TimeSpan.FromSeconds(30);
                Wait.Until(ExpectedConditions.LoaderDisappears);
                Assert.Multiple(() =>
                {
                    Wait.Until((e) =>
                    {
                        return collateralDetailsModal.Subheaders.Count > 0;
                    });
                    Assert.That(collateralDetailsModal.Subheaders.Select(e => e.Text).ToList(), Is.EqualTo(new List<string> { "Dane podstawowe", "Dane szczegółowe", "Szczegóły hipoteki", "Data wyceny" }));
                    Assert.That(collateralDetailsModal.SectionContentLabels.Select(e => e.Text).ToList(), Is.SupersetOf(new List<string> { "Wykonane płatności razem", "Numer", "Wartość nominalna", "Data ustanowienia hipoteki", "Typ wyceny" }));
                });
                CheckHistoryOfChanges();
                CheckSetDetails();
                collateralDetailsModal.CloseModal();
                Wait.Until(ExpectedConditions.ElementToBeClickable(collateralListRows.First().Description));
            }
        }

        private void CheckHistoryOfChanges()
        {
            collateralDetailsModal.Buttons.First(e => e.Text == "HISTORIA ZMIAN").Click();
            Wait.Until(ExpectedConditions.LoaderDisappears);
            Assert.Multiple(() =>
            {
                Wait.Until((e) =>
                {
                    return historyOfChangesModal.Subheaders.Count > 0;
                });
                Assert.That(historyOfChangesModal.Subheaders.Select(e => e.Text).ToList(), Is.EqualTo(new List<string> { "Utworzenie/Zamknięcie", "Zmiany" }));
                Assert.That(historyOfChangesModal.DetailsRows.Count, Is.EqualTo(6));
            });
            historyOfChangesModal.ExpandRows();
            historyOfChangesModal.CloseModal();
            Wait.Until(ExpectedConditions.ElementToBeClickable(collateralDetailsModal.Buttons.First()));
        }

        private void CheckSetDetails()
        {
            Wait.Until(ExpectedConditions.ElementToBeClickable(collateralDetailsModal.Buttons.First()));
            collateralDetailsModal.Buttons.First(e => e.Text == "SZCZEGÓŁY ZESTAWU").Click();
            Wait.Until(ExpectedConditions.LoaderDisappears);
            Wait.Until((e) =>
            {
                return setDetailsModal.DetailsRows.Count > 0;
            });
            Assert.That(setDetailsModal.DetailsRows.Count, Is.EqualTo(1));
            setDetailsModal.CloseModal();
            Wait.Until(ExpectedConditions.ElementToBeClickable(collateralDetailsModal.Buttons.First()));
        }

        private void AssertOtherDeatails()
        {
            Assert.Multiple(() =>
            {
                Assert.That(transactionFilter.Displayed);
                Assert.That(transactionDatePicker.Displayed);
                Assert.That(collateralListFilter.Displayed);
                Assert.That(changeTypeInput.Displayed);
                Assert.That(changesList.Displayed);
                Assert.That(loanScheduleHeaders.First().Text, Is.EqualTo("Dane harmonogramu"));
                Assert.That(loanScheduleHeaders.Last().Text, Is.EqualTo("Harmonogram spłaty kredytu"));
                Assert.That(loanScheduleDataLabels, Is.SupersetOf(new List<string> { "Saldo bieżące", "Podstawa roczna naliczania" }));
                Assert.That(overduePaymentsLabels, Is.SupersetOf(new List<string> { "Płatności zaległe razem z odsetkami", "Zaległe odsetki karne" }));
                Assert.That(overduePaymentsCalender.Displayed);
            });
        }
        public void AssertLoanOtherDetails()
        {
            ExpandAllSections(subHeaders);
            Wait.Until(ExpectedConditions.LoaderDisappears);
            AssertOtherDeatails();
            Assert.Multiple(() =>
            {
                Assert.That(collateralListRows.All(e => e.Status == "Aktywne"));
                Assert.That(collateralListRows.Count, Is.EqualTo(3));
                Assert.That(printScheduleButton.Displayed);
                Assert.That(printPaymentSlipsButton.Displayed);
                Assert.That(overduePaymentsHeaders, Is.EqualTo(new List<string> { "Dane o przeterminowanych płatnościach", "Zaległe spłaty kredytu", "Lista zapłaconych i niezapłaconych należności przeterminowanych" }));
            });
        }

        public void AssertMortgageOtherDetails()
        {
            ExpandAllSections(subHeaders);
            Wait.Until(ExpectedConditions.LoaderDisappears);
            AssertOtherDeatails();
            Assert.That(subHeaders.Select(e => e.Text).ToList(), Is.EqualTo(new List<string> { "Transakcje", "Lista zabezpieczeń", "Lista zmian", "Harmonogram spłat kredytu", "Zaległe płatności", "Historia zmian memo – kredyty" }));
            new Actions(Driver).SendKeys(Keys.Home).Perform();
            Wait.Until(ExpectedConditions.PageLoaded);
            CheckTransactionLink();
            CheckCollateralDescriptionLink();
            overduePaymentsDatePicker.ChooseEndDate(new DateTime(2024, 02, 29));
            Assert.Multiple(() =>
            {
                Assert.That(scheduleList.Displayed);
                Assert.That(statusFilter.Displayed);
                Assert.That(memoLogDatePicker.Displayed);
                Assert.That(alerts.FindAll(i => i.GetMessage() == "Brak rekordów.").Count, Is.EqualTo(3).Or.EqualTo(4));
            });
        }
    }

    public class CollateralListRows : BaseElement
    {
        public CollateralListRows(IWebElement element) : base(element)
        {
        }

        public string Status => Find(By.XPath("./*[1]")).Text;
        private string number => Find(By.XPath("./*[2]")).Text;
        private string relations => Find(By.XPath("./*[3]")).Text;
        private string loanAccount => Find(By.XPath("./*[4]")).Text;
        public IWebElement Description => Find(By.XPath("./*[5]"));
        private DateTime expirationDate => DateTime.Parse(Find(By.XPath("./*[6]")).Text);
        private Money amount => new Money(Find(By.XPath("./*[7]")).Text);
    }

    public class DetailsModal : BaseElement
    {
        private IWebElement closeButton => Find(By.XPath(".//span[@class='ant-modal-close-x']"));
        private List<IWebElement> expandIcons => FindMany(By.XPath(".//TD[contains(@class,'row-expand-icon')]"));
        private List<IWebElement> expandedRowsDetails => FindMany(By.XPath(".//*[contains(@class,'CustomExpandedRow')]"));
        public List<IWebElement> Buttons => FindMany(By.XPath(".//*[contains(@class,'Typography--button')]"));
        public List<IWebElement> Subheaders => FindMany(By.XPath(".//*[@class='ant-spin-container']/p"));
        public List<IWebElement> DetailsRows => FindMany(By.XPath(".//*[@class='ant-table-row ant-table-row-level-0']"));
        public List<IWebElement> SectionContentLabels => FindMany(By.XPath(".//*[@class='ant-spin-container']//*[@class='LabelWithParagraph']/p/span"));

        public DetailsModal(IWebElement element) : base(element)
        {
        }

        public void CloseModal() => closeButton.Click();
        public void SelectHistoryOfChanges() => Buttons.First(e => e.Text == "Historia zmian").Click();
        public void ExpandRows()
        {
            for (int i = 0; i < expandIcons.Count; i++)
            {
                expandIcons[i].Click();
                Wait.Until(ExpectedConditions.PageLoaded);
                Assert.That(expandedRowsDetails[i].Displayed);
            }
        }
    }
}
Leave a Comment