Protractor tests. Loan product tests.
diff --git a/Pages/CustomerLoans.js b/Pages/CustomerLoans.js
index 7ee4eff..3f23c2b 100644
--- a/Pages/CustomerLoans.js
+++ b/Pages/CustomerLoans.js
@@ -13,7 +13,7 @@
 var termInput = $("fims-text-input[controlname='term'] input");
 var termSelect = $("mat-select[formcontrolname='termTemporalUnit'] .mat-select-trigger");
 var paymentPeriod = $("fims-text-input[controlname='paymentPeriod'] input");
-var paymentPeriodSelect = $("mat-select[formcontrolname='termTemporalUnit'] .mat-select-trigger");
+var paymentPeriodSelect = $("mat-select[formcontrolname='paymentTemporalUnit'] .mat-select-trigger");
 var depositAccountSelect = $("mat-select[formcontrolname='depositAccountIdentifier'] .mat-select-trigger");
 //if "Repay every" is set to "months"
 var radioMonthSetting1 = $$("mat-radio-group[formcontrolname='monthSetting'] mat-radio-button").get(0);
@@ -40,6 +40,10 @@
 
 //Co-signer
 var memberSelect = $("fims-customer-select[formcontrolname='customerIdentifier'] input");
+var descriptionInputsDebtCosigner = $$("fims-case-credit-factor-form").get(2).$$("fims-text-input[controlname='description'] input");
+var amountInputsDebtCosigner = $$("fims-case-credit-factor-form").get(2).$$("fims-text-input[controlname='amount'] input");
+var descriptionInputsIncomeCosigner = $$("fims-case-credit-factor-form").get(3).$$("fims-text-input[controlname='description'] input");
+var amountInputsIncomeCosigner = $$("fims-case-credit-factor-form").get(3).$$("fims-text-input[controlname='amount'] input");
 
 //Documents
 var descriptionInputsDocs = $$("fims-case-documents-form fims-text-input[controlname='description'] input");
@@ -114,6 +118,10 @@
         interestRateInput.sendKeys(protractor.Key.BACK_SPACE);
         interestRateInput.sendKeys(text);
     },
+    verifyInterestRateInputFieldIsDisabledAndHasText: function (text) {
+        expect(interestRateInput.isEnabled()).toBe(false);
+        expect(interestRateInput.getAttribute("value")).toEqual(text);
+    },
     verifyLoanAccountNotOfferedForSelection: function(accountIdentifier){
         browser.wait(EC.elementToBeClickable(productSelect), 3000);
         productSelect.click();
@@ -250,6 +258,7 @@
         browser.sleep(100);
         browser.wait(EC.elementToBeClickable($$(".td-step-label").get(2)), 3000);
         $$(".td-step-label").get(2).click();
+        browser.sleep(1000);
     },
     goToStepDocuments: function(){
         browser.sleep(100);
@@ -290,7 +299,7 @@
             return elem.$("span").getText().then(function(text) {
                 return text === "ADD DEBT";
             });
-        }).click();
+        }).first().click();
     },
     clickButtonAddIncome: function(){
         browser.sleep(200);
@@ -298,7 +307,7 @@
             return elem.$("span").getText().then(function(text) {
                 return text === "ADD INCOME";
             });
-        }).click();
+        }).first().click();
     },
     removeDebtAtPosition: function(position){
         buttons.filter(function(elem, index) {
@@ -343,6 +352,22 @@
         browser.wait(EC.elementToBeClickable(memberSelect), 5000);
         memberSelect.click().clear().sendKeys(text);
     },
+    enterTextDescriptionInputFieldForDebtCosigner: function(text, number) {
+        browser.wait(EC.visibilityOf(descriptionInputsDebtCosigner.get(number-1)), 2000)
+        descriptionInputsDebtCosigner.get(number-1).clear().click().sendKeys(text);
+    },
+    enterTextIntoAmountInputFieldForDebtCosigner: function(text, number) {
+        browser.wait(EC.visibilityOf(amountInputsDebtCosigner.get(number-1)), 2000)
+        amountInputsDebtCosigner.get(number-1).clear().click().sendKeys(text);
+    },
+    enterTextIntoDescriptionInputFieldForIncomeCosigner: function(text, number) {
+        browser.wait(EC.visibilityOf(descriptionInputsIncomeCosigner.get(number-1)), 2000)
+        descriptionInputsIncomeCosigner.get(number-1).clear().click().sendKeys(text);
+    },
+    enterTextIntoAmountInputFieldForIncomeCosigner: function(text, number) {
+        browser.wait(EC.visibilityOf(amountInputsIncomeCosigner.get(number-1)), 2000)
+        amountInputsIncomeCosigner.get(number-1).clear().click().sendKeys(text);
+    },
     clickButtonAddDocument: function(){
         browser.sleep(200);
         buttons.filter(function(elem, index) {
@@ -369,6 +394,7 @@
         $('a[href="' + link + '"]').click();
         browser.wait(EC.visibilityOf($("fims-layout-card-over")), 2000);
     },
+    //table
     verifyPrincipalForLoanAccountInRow: function(principalAmount, row){
         browser.wait(EC.visibilityOf($("table tbody")), 3000);
         expect($$("table tbody tr").get(row - 1).$$(".td-data-table-cell").get(1).getText()).toEqual(principalAmount);
@@ -381,10 +407,110 @@
         browser.wait(EC.visibilityOf($("table tbody")), 3000);
         expect($$("table tbody tr").get(row - 1).$$(".td-data-table-cell").get(3).getText()).toEqual(status);
     },
+    //details single loan
+    verifyLoanStatusIs: function(expectedStatus){
+        browser.wait(EC.visibilityOf($("fims-state-display")), 5000);
+        status = $("fims-state-display .mat-list-text .mat-line").getText();
+        expect(status).toEqual(expectedStatus);
+    },
+    verifyPrincipalAmountForLoan: function(principalAmount) {
+        expect($$("fims-layout-card-over .mat-list-text").filter(function (elem, index) {
+            return elem.$("h3").getText().then(function (text) {
+                return text === "Principal amount";
+            });
+        }).first().$("p").getText().then(function (text) {
+            return text === principalAmount;
+        })).toBe(true);
+    },
+    verifyInterestForLoan: function(interest) {
+        expect($$("fims-layout-card-over .mat-list-text").filter(function (elem, index) {
+            return elem.$("h3").getText().then(function (text) {
+                return text === "Interest";
+            });
+        }).first().$("p").getText().then(function (text) {
+            return text === interest;
+        })).toBe(true);
+    },
+    verifyPaymentCycleForLoan: function(cycle) {
+        expect($$("fims-layout-card-over .mat-list-text").filter(function (elem, index) {
+            return elem.$("h3").getText().then(function (text) {
+                return text === "Payment cycle";
+            });
+        }).first().$("p").getText().then(function (text) {
+            return text === cycle;
+        })).toBe(true);
+    },
+    verifyTermForLoan: function(term) {
+        expect($$("fims-layout-card-over .mat-list-text").filter(function (elem, index) {
+            return elem.$("h3").getText().then(function (text) {
+                return text === "Term";
+            });
+        }).first().$("p").getText().then(function (text) {
+            return text === term;
+        })).toBe(true);
+    },
+    verifyMemberDepositAccountForLoan: function(account) {
+        expect($$("fims-layout-card-over .mat-list-text").filter(function (elem, index) {
+            return elem.$("h3").getText().then(function (text) {
+                return text === "Member deposit account";
+            });
+        }).first().$("p").getText().then(function (text) {
+            return text === account;
+        })).toBe(true);
+    },
+    verifyCreatedByForLoanIs: function(createdBy){
+        expect($$("fims-layout-card-over .mat-list-text").filter(function (elem, index) {
+            return elem.$("h3").getText().then(function (text) {
+                return text === "Created by";
+            });
+        }).first().$("p").getText().then(function (text) {
+            return text.indexOf(createdBy) >= 0;
+        })).toBe(true);
+    },
+    verifyLastModifiedByForLoanIs: function(modifiedBy){
+        expect($$("fims-layout-card-over .mat-list-text").filter(function (elem, index) {
+            return elem.$("h3").getText().then(function (text) {
+                return text === "Last modified by";
+            });
+        }).first().$("p").getText().then(function (text) {
+            return text.indexOf(modifiedBy) >= 0;
+        })).toBe(true);
+    },
     verifyMemberRatioIs:function (text){
         expect($$("mat-tab-header div[role='tab']").get(0).getText()).toMatch("Member(Ratio: " + text + ")");
     },
     verifyCoSignerRatioIs:function (text){
         expect($$("mat-tab-header div[role='tab']").get(1).getText()).toEqual("Co-signer(Ratio: " + text + ")");
+    },
+    verifyPrincipalInputFieldHasError: function(errorMessage) {
+        $("fims-case-detail-form").click();
+        browser.wait(EC.textToBePresentInElement($("mat-error"), errorMessage), 2000);
+        expect(principalAmountInput.element(by.xpath("..")).element(by.xpath("..")).element(by.xpath("..")).$("mat-error").getText()).toMatch(errorMessage);
+    },
+    verifyInterestRateInputFieldHasError: function(errorMessage) {
+        $("fims-case-detail-form").click();
+        browser.wait(EC.textToBePresentInElement($("mat-error"), errorMessage), 2000);
+        expect(interestRateInput.element(by.xpath("..")).element(by.xpath("..")).element(by.xpath("..")).$("div div mat-error").getText()).toEqual(errorMessage);
+    },
+    verifyTermInputFieldHasErrorForInvalidTerm: function(errorMessage) {
+        $("fims-case-detail-form").click();
+        browser.wait(EC.textToBePresentInElement($(".tc-red-600"), errorMessage), 2000);
+    },
+    verifyTermInputFieldHasError: function(errorMessage) {
+        $("fims-case-detail-form").click();
+        browser.wait(EC.textToBePresentInElement($("mat-error"), errorMessage), 2000);
+        expect(termInput.element(by.xpath("..")).element(by.xpath("..")).element(by.xpath("..")).$("mat-error").getText()).toEqual(errorMessage);
+    },
+    verifyRepayEveryFieldHasErrorForInvalidTerm: function(errorMessage) {
+        $("fims-case-detail-form").click();
+        browser.wait(EC.textToBePresentInElement($(".tc-red-600"), errorMessage), 2000);
+    },
+    verifyCreateLoanButtonIsNotDisplayed: function(){
+        expect($("a[title='Create new loan for member ']").isPresent()).toBe(false);
+    },
+    verifyMessagesAreDisplayed: function(message, message2){
+        browser.wait(EC.visibilityOf($("td-message")), 2500);
+        expect($("td-message .td-message-label").getText()).toEqual(message);
+        expect($("td-message .td-message-sublabel").getText()).toEqual(message2);
     }
 };
diff --git a/Pages/Customers.js b/Pages/Customers.js
index cbb8e88..60135f6 100644
--- a/Pages/Customers.js
+++ b/Pages/Customers.js
@@ -275,6 +275,10 @@
     verifyIsMemberCheckboxSelected: function () {
         expect(memberCheckbox.getAttribute("class")).toMatch("mat-checkbox-checked");
     },
+    uncheckMemberCheckbox: function (){
+        expect(memberCheckbox.getAttribute("class")).toMatch("mat-checkbox-checked");
+        memberCheckbox.click();
+    },
     enterTextIntoShortNameInputField: function (text) {
         browser.wait(EC.elementToBeClickable(shortNameInput), 5000);
         shortNameInput.click().sendKeys(text);
diff --git a/Pages/Loans.js b/Pages/Loans.js
index 9753a60..46e41fd 100644
--- a/Pages/Loans.js
+++ b/Pages/Loans.js
@@ -318,6 +318,7 @@
         expect($("a[title='Edit product']").isPresent()).toBe(true);
     },
     verifyEditLoanProductButtonIsNotDisplayed: function(){
+        browser.sleep(500);
         expect($("a[title='Edit product']").isPresent()).toBe(false);
     }
 };
\ No newline at end of file
diff --git a/Specs/loans1_creation&assignment.js b/Specs/loans1_creation&assignment.js
index 05ab8aa..32d3c36 100644
--- a/Specs/loans1_creation&assignment.js
+++ b/Specs/loans1_creation&assignment.js
@@ -18,6 +18,7 @@
     officeIdentifier = helper.getRandomString(6);
     tellerIdentifier = helper.getRandomString(4);
     customerAccount = helper.getRandomString(5);
+    customerAccount2 = helper.getRandomString(5);
     depositIdentifier = helper.getRandomString(4);
     depositName = helper.getRandomString(8);
     chequeReceivablesAccount = helper.getRandomString(4);
@@ -157,17 +158,41 @@
         Common.verifyFirstRowOfSearchResultHasTextAsId(customerAccount);
     });
     it('should not be possible to create loan account for pending customer', function () {
-
+        Common.clickLinkShowForFirstRowInTable();
+        Customers.clickManageLoanAccountsForMember(customerAccount);
+        CustomerLoans.verifyCreateLoanButtonIsNotDisplayed();
     });
     it('should activate the customer', function () {
-        Common.clickLinkShowForFirstRowInTable();
+        Common.clickBackButtonInTitleBar();
         Customers.verifyMemberHasStatusInactive();
         Customers.clickButtonGoToTasks();
         Customers.clickButtonActivate();
         Common.verifyMessagePopupIsDisplayed("Command is going to be executed");
         Customers.verifyMemberHasStatusActive();
     });
-    it('should create a deposit account - Checking with opening charge', function () {
+    it('should create another customer - co-signer', function () {
+        Common.clickBackButtonInTitleBar();
+        Common.verifyCardHasTitle("Manage members");
+        Customers.clickButtonOrLinkCreateNewMember();
+        Common.verifyCardHasTitle("Create new member");
+        Customers.enterTextIntoAccountInputField(customerAccount2);
+        Customers.enterTextIntoFirstNameInputField("Bob");
+        Customers.enterTextIntoLastNameInputField("Dylan");
+        Customers.enterTextIntoDayOfBirthInputField("9211978");
+        Customers.uncheckMemberCheckbox();
+        Customers.clickEnabledContinueButtonForMemberDetails();
+        Customers.enterTextIntoStreetInputField("800 Chatham Road #326");
+        Customers.enterTextIntoCityInputField("Winston-Salem");
+        Customers.selectCountryByName("Germany");
+        Customers.clickEnabledContinueButtonForMemberAddress();
+        Customers.clickEnabledCreateMemberButton();
+        Common.verifyMessagePopupIsDisplayed("Member is going to be saved");
+        Common.verifyCardHasTitle("Manage members");
+        Common.clickSearchButtonToMakeSearchInputFieldAppear();
+        Common.enterTextInSearchInputFieldAndApplySearch(customerAccount2);
+        Common.verifyFirstRowOfSearchResultHasTextAsId(customerAccount2);
+    });
+    it('should create a deposit account - Checking with opening charge of 0', function () {
         Deposits.goToDepositsViaSidePanel();
         Common.verifyCardHasTitle("Manage deposit products");
         Deposits.clickButtonCreateDepositAccount();
@@ -212,7 +237,7 @@
         Customers.clickEnabledButtonCreateDepositAccount();
         Common.verifyMessagePopupIsDisplayed("Deposit account is going to be saved");
     });
-    it('create first loan product', function () {
+    it('create first loan product - interest range, max term 5 years, no fees/tasks', function () {
         Loans.goToLoanProductsViaSidePanel();
         Loans.clickButtonCreateLoanProduct();
         //product details
@@ -229,9 +254,9 @@
         Loans.selectRadioButtonYears();
         Loans.clickEnabledContinueButtonForProductDetails();
         //ledger and account settings
-        //asset account only
+        //ToDo: asset account only
         Loans.enterTextIntoCashAccountInputField(tellerAccount);
-        //asset ledger only
+        //ToDo: asset ledger only
         Loans.enterTextIntoCustomerLoanLedgerInputField("7900");
         Loans.clickEnabledContinueButtonForLedgerAndAccountSettings();
         //interest settings
@@ -242,9 +267,9 @@
         Loans.verifyInterestRangeInputFieldsHaveError("Must be greater than minimum");
         Loans.enterTextIntoInterestRangeMinInputField("0.80");
         Loans.enterTextIntoInterestRangeMaxInputField("3.60");
-        //revenue account only
+        //ToDo: revenue account only
         Loans.enterTextIntoIncomeAccountAccountInputField("1101");
-        //asset account only
+        //ToDo: asset account only
         Loans.enterTextIntoAccrualAccountInputField("7810");
         Loans.clickEnabledContinueButtonForInterestSettings();
         //fee income accounts
@@ -260,12 +285,12 @@
         Common.verifyMessagePopupIsDisplayed("Product is going to be saved");
     });
     it('should enable the first loan product', function () {
-        //message
         Common.clickLinkShowForRowWithId(loanShortName);
+        CustomerLoans.verifyMessagesAreDisplayed("Product not enabled", "To assign this product to a member it needs to be enabled first");
         Loans.clickButtonEnableProduct();
         Common.verifyMessagePopupIsDisplayed("Product is going to be enabled");
     });
-    it('create second loan product', function () {
+    it('create second loan product - interest rate, max term 52 weeks, no fees/tasks', function () {
         Loans.goToLoanProductsViaSidePanel();
         Loans.clickButtonCreateLoanProduct();
         //product details
@@ -362,28 +387,38 @@
         CustomerLoans.enterTextIntoShortNameInputField(loanAccountShortName);
         CustomerLoans.enterTextIntoPrincipalAmountInputField("9999.99");
         //invalid input, error
+        CustomerLoans.verifyPrincipalInputFieldHasError("Value must be greater than or equal to 10000");
         CustomerLoans.enterTextIntoPrincipalAmountInputField("50,000.01");
         //invalid input, error
+        CustomerLoans.verifyPrincipalInputFieldHasError("Value must be smaller than or equal to 50000");
         CustomerLoans.enterTextIntoPrincipalAmountInputField("10,000");
         CustomerLoans.enterTextIntoInterestRateInputField("3.65");
         //invalid input, error
+        CustomerLoans.verifyInterestRateInputFieldHasError("Value must be smaller than or equal to 3.6");
         CustomerLoans.enterTextIntoInterestRateInputField("0.79");
         //invalid input, error
+        CustomerLoans.verifyInterestRateInputFieldHasError("Value must be greater than or equal to 0.8");
         CustomerLoans.enterTextIntoInterestRateInputField("3.60");
         CustomerLoans.enterTextIntoTermInputField("62");
-        //invalid input, error
+        //invalid input, error: Invalid term. Maximum allowed are 260 week(s), 60 month(s) or 5 year(s).
+        CustomerLoans.verifyTermInputFieldHasErrorForInvalidTerm("Invalid term. Maximum allowed are 260 week(s), 60 month(s) or 5 year(s).");
+        CustomerLoans.enterTextIntoTermInputField("59.9");
+        //invalid input, error: Value scale must be smaller than or equal to 0
+        CustomerLoans.verifyTermInputFieldHasError("Value scale must be smaller than or equal to 0");
         CustomerLoans.enterTextIntoTermInputField("60");
-        //valid input, no error
         CustomerLoans.selectTemporalUnitForTerm("years");
         //invalid input, error
+        CustomerLoans.verifyTermInputFieldHasErrorForInvalidTerm("Invalid term. Maximum allowed are 260 week(s), 60 month(s) or 5 year(s).");
         CustomerLoans.enterTextIntoTermInputField("5");
         //valid input, no error
         CustomerLoans.enterTextIntoPaymentPeriodInputField("62");
         //invalid input, error: Invalid payment period. Maximum allowed are 260 week(s), 60 month(s) or 5 year(s).
+        CustomerLoans.verifyRepayEveryFieldHasErrorForInvalidTerm("Invalid payment period. Maximum allowed are 260 week(s), 60 month(s) or 5 year(s).");
         CustomerLoans.enterTextIntoPaymentPeriodInputField("6");
         //valid input, no error
         CustomerLoans.selectPaymentPeriod("years");
         //invalid input, error
+        CustomerLoans.verifyRepayEveryFieldHasErrorForInvalidTerm("Invalid payment period. Maximum allowed are 260 week(s), 60 month(s) or 5 year(s).");
         CustomerLoans.selectPaymentPeriod("months");
         //valid input, no error
         CustomerLoans.selectSecondRadioOptionForMonthlyRepayment();
@@ -391,11 +426,12 @@
         CustomerLoans.selectDepositAccount(customerAccount + ".9100.00001(" + depositIdentifier + ")");
         //change loan product to the other one
         CustomerLoans.selectProduct(loanShortName2);
-        //error for principal: Value must be smaller than or equal to 1500
+        CustomerLoans.verifyPrincipalInputFieldHasError("Value must be smaller than or equal to 1500");
         CustomerLoans.enterTextIntoPrincipalAmountInputField("1500");
-        //interest rate input is disabled and shows 15%
-        //error for payment period: Invalid payment period. Maximum allowed are 21 week(s), 5 month(s) or 0 year(s).
-        CustomerLoans.selectPaymentPeriod("months");
+        CustomerLoans.verifyInterestRateInputFieldIsDisabledAndHasText("15.00");
+        CustomerLoans.verifyTermInputFieldHasErrorForInvalidTerm("Invalid term. Maximum allowed are 52 week(s), 12 month(s) or 1 year(s).");
+        CustomerLoans.selectTemporalUnitForTerm("months");
+        CustomerLoans.verifyRepayEveryFieldHasErrorForInvalidTerm("Invalid payment period. Maximum allowed are 21 week(s), 5 month(s) or 0 year(s).");
         //debt to income ratio
         CustomerLoans.goToStepDebtToIncomeRatio();
         CustomerLoans.clickButtonAddDebt();
@@ -416,12 +452,16 @@
         CustomerLoans.enterTextIntoAmountInputFieldForIncome("5000",2);
         CustomerLoans.verifyIncomeTotalIs("10,000.00");
         CustomerLoans.verifyDebtIncomeRatioIs("01.50");
-        //browser.pause();
         CustomerLoans.goToStepCoSigner();
         //co-signer, need another member
-        //CustomerLoans.enterTextIntoMemberInputField();
-        //documents, cannot do much since I cannot upload documents via test
-        CustomerLoans.goToStepDocuments();
+        //ToDo: cannot select same member to be co-signer
+        CustomerLoans.enterTextIntoMemberInputField(customerAccount2);
+        CustomerLoans.clickButtonAddDebt();
+        CustomerLoans.enterTextDescriptionInputFieldForDebtCosigner("Co-signer debt", 1);
+        CustomerLoans.enterTextIntoAmountInputFieldForDebtCosigner("500", 1);
+        CustomerLoans.clickButtonAddIncome();
+        CustomerLoans.enterTextIntoDescriptionInputFieldForIncomeCosigner("Co-signer income", 1);
+        CustomerLoans.enterTextIntoAmountInputFieldForIncomeCosigner("1200", 1);
         //still error for payment period
         CustomerLoans.verifyButtonCreateMemberLoanDisabled();
         CustomerLoans.goToStepLoanDetails();
@@ -436,6 +476,13 @@
         CustomerLoans.verifyCurrentStatusForLoanAccountInRow("CREATED", 1);
         Common.clickLinkShowForRowWithId(loanAccountShortName);
         //details
+        CustomerLoans.verifyLoanStatusIs("CREATED");
+        CustomerLoans.verifyPrincipalAmountForLoan("1,500.00");
+        CustomerLoans.verifyInterestForLoan("15.00");
+        CustomerLoans.verifyPaymentCycleForLoan("Repay every 5 months on the last Friday");
+        CustomerLoans.verifyTermForLoan("5 MONTHS");
+        CustomerLoans.verifyMemberDepositAccountForLoan(customerAccount + ".9100.00001");
+        CustomerLoans.verifyCreatedByForLoanIs(employeeIdentifier);
     });
     it('planned payment', function () {
         CustomerLoans.viewPlannedPaymentForCustomerLoan(customerAccount, loanShortName, loanAccountShortName);
@@ -444,7 +491,7 @@
     it('debt/income ratio', function () {
         CustomerLoans.viewDebtIncomeReportForCustomerLoan(customerAccount, loanShortName2, loanAccountShortName);
         CustomerLoans.verifyMemberRatioIs("01.50");
-        CustomerLoans.verifyCoSignerRatioIs(" -");
+        CustomerLoans.verifyCoSignerRatioIs("00.42");
         Common.clickBackButtonInTitleBar();
     });
     it('should be able to edit loan account until it has been approved', function () {