<commit_before>*** Settings ***
Documentation     INFUND-3970 As a partner I want a spend profile page in Project setup so that I can access and share Spend profile information within my partner organisation before submitting to the Project Manager
...
...               INFUND-3764 As a partner I want to view a Spend Profile showing my partner organisation's eligible project costs divided equally over the duration of our project to begin review our project costs before submitting to the Project Manager
...
...               INFUND-3765 As a partner I want to be able to edit my Spend profile so I can prepare an updated profile for my organisation before submission to the Project Manager
...
...               INFUND-3971 As a partner I want to be able to view my spend profile in a summary table so that I can review my spend profile by financial year
...
...               INFUND-2638 As a Competitions team member I want to view a page providing a link to each partners' submitted spend profile so that I can confirm these have been approved by the Technical Lead
...
...               INFUND-3766 As a project manager I want a summary page so I can review of all partners’ spend profiles that are marked as complete
...
...               INFUND-5194 As a partner I want to be see the project costs that were input during Finance Checks showing in the default spend profile so that I can begin to review my spend profile using the approved figures
...
...               INFUND-4819 As an academic partner I want to be given an alternative view of the Spend Profile in Project Setup so that I can submit information approriate to an academic organisation
...
...               INFUND-5609 PM can see partners' spend profiles before they are marked as complete, and can see buttons to edit and mark as complete
...
...               INFUND-5911 Internal users should not have access to external users' pages
...
...               INFUND-3973 As a Project Finance team member I want to be able to export submitted spend profile tables so that these may be distributed offline to Lead Technologists and Monitoring Officers
...
...               INFUND-5846 As a partner in an acedemic organisation I want to be able to edit my Spend profile so I can prepare an updated profile for my organisation before submission to the Project Manager
...
...               INFUND-5441 As a Project Finance team member I want to be able to export submitted spend profile tables from academic organisations so that these may be distributed offline to Lead Technologists and Monitoring Officers
...
...               INFUND-6046 Spend Profile should have a link when Done
...
...               INFUND-6350 As a lead partner I want to be able to return edit rights to a non-lead partner so that they can further amend their Spend Profile if requested by the lead
...
...               INFUND-6146 Saving blank fields on the spend profile results in an internal server error (null pointer exception)
...
...               INFUND-6225 External user status indicator for spend profile should show as 'waiting' once submitted
...
...               INFUND-6226 Comp admin user (non project finance) not able to view the spend profile page
...
...               INFUND-6881 Non-lead External User should see Green Check once he submits SP
...
...               INFUND-7119 GOL status for Internal user
Suite Setup       all previous sections of the project are completed
Suite Teardown    the user closes the browser
Force Tags        Project Setup
Resource          ../../resources/defaultResources.robot
Resource          PS_Variables.robot

*** Variables ***
${project_overview}    ${server}/project-setup/project/${PS_SP_APPLICATION_PROJECT}
${external_spendprofile_summary}    ${server}/project-setup/project/${PS_SP_APPLICATION_PROJECT}/partner-organisation/${Katz_Id}/spend-profile
${project_duration}    36

*** Test Cases ***
Project Finance user generates the Spend Profile
    [Documentation]    INFUND-5194
    [Tags]    HappyPath
    [Setup]    log in as user               &{internal_finance_credentials}
    Given the user navigates to the page    ${server}/project-setup-management/project/${PS_SP_APPLICATION_PROJECT}/finance-check
    Then the user should see the element    jQuery=a.eligibility-0:contains("Approved")
    And the user should see the element     jQuery=a.eligibility-1:contains("Approved")
    And the user should see the element     jQuery=a.eligibility-2:contains("Approved")
    Then the user should see the element    jQuery=.generate-spend-profile-main-button

Project Finance cancels the generation of the Spend Profile
    [Documentation]    INFUND-5194
    [Tags]
    When the user clicks the button/link    jQuery=.generate-spend-profile-main-button
    Then the user should see the text in the page    This will generate a flat profile spend for all project partners.
    When the user clicks the button/link    jQuery=.button:contains("Cancel")

Project Finance generates the Spend Profile
    [Documentation]    INFUND-5194, INFUND-5987
    [Tags]    HappyPath
    When the user clicks the button/link    jQuery=.generate-spend-profile-main-button
    And the user clicks the button/link     jQuery=#generate-spend-profile-modal-button
    Then the user should see the element    jQuery=.success-alert p:contains("The finance checks have been approved and profiles generated.")
    When the user navigates to the page     ${server}/project-setup-management/competition/${PS_SP_Competition_Id}/status
    Then the user should see the element    jQuery=#table-project-status tr:nth-of-type(3) td:nth-of-type(4).ok

Lead partner can view spend profile page
    [Documentation]    INFUND-3970
    [Tags]    HappyPath
    [Setup]    Log in as a different user    ${PS_SP_APPLICATION_LEAD_PARTNER_EMAIL}    ${short_password}
    Given the user clicks the button/link    link=${PS_SP_APPLICATION_HEADER}
    When the user clicks the button/link     link=Spend profile
    And the user clicks the button/link      link=${Katz_Name}
    Then the user should not see an error in the page
    And the user should see the text in the page    We have reviewed and confirmed your project costs.
    And the user should see the text in the page    ${Katz_Name} - Spend profile

Lead partner can see correct project start date and duration
    [Documentation]    INFUND-3970
    [Tags]
    Then the user should see the text in the page    1
    And the user should see the text in the page     June 2017
    And the user should see the text in the page     ${project_duration} months

Calculations in the spend profile table
    [Documentation]    INFUND-3764
    [Tags]    HappyPath
    Given the user should see the element    jQuery=div.spend-profile-table
    Then element should contain    css=.spend-profile-table tbody tr:nth-child(1) td:nth-last-child(2)    £ 8,000     #Labour
    Then element should contain    css=.spend-profile-table tbody tr:nth-child(2) td:nth-last-child(2)    £ 2,000     #Overheads
    Then element should contain    css=.spend-profile-table tbody tr:nth-child(3) td:nth-last-child(2)    £ 10,000    #Materials
    Then element should contain    css=.spend-profile-table tbody tr:nth-child(4) td:nth-last-child(2)    £ 10,000    #Capital usage
    Then element should contain    css=.spend-profile-table tbody tr:nth-child(5) td:nth-last-child(2)    £ 10,000    #Subcontracting
    Then element should contain    css=.spend-profile-table tbody tr:nth-child(6) td:nth-last-child(2)    £ 10,000    #Travel & subsistence
    Then element should contain    css=.spend-profile-table tbody tr:nth-child(7) td:nth-last-child(2)    £ 10,000    #Other costs
    #${duration} is No of Months + 1, due to header
    And the sum of tds equals the total    div.spend-profile-table    1    38    8000     # Labour
    And the sum of tds equals the total    div.spend-profile-table    3    38    10000    # Materials
    And the sum of tds equals the total    div.spend-profile-table    5    38    10000    # Subcontracting
    And the sum of tds equals the total    div.spend-profile-table    6    38    10000    # Travel & subsistence
    And the sum of tds equals the total    div.spend-profile-table    7    38    10000    # Other Costs

Lead Partner can see Spend profile summary
    [Documentation]    INFUND-3971
    [Tags]    Failing
    #TODO this test case needs to be moved, to another project where the PM != Lead partner.
    Given the user navigates to the page            ${external_spendprofile_summary}/review
    And the user should see the text in the page    Project costs for financial year
    And the user moves focus to the element         jQuery=.grid-container table
    Then the user sees the text in the element      jQuery=.grid-container table tr:nth-child(1) td:nth-child(2)    £ 16,632

Lead partner can edit his spend profile with invalid values
    [Documentation]    INFUND-3765
    [Tags]    #HappyPath
    When the user clicks the button/link               jQuery=.button:contains("Edit spend profile")
    Then the text box should be editable               css=#row-24-0  # Labour-June17
    When the user enters text to a text field          css=#row-24-0    2899
    And the user moves focus to the element            css=#row-24-2
    Then the user should see the text in the page      Unable to submit spend profile.
    And the user should see the text in the page       Your total costs are higher than your eligible costs
    Then the field has value                           css=#row-total-24    £ 10,669
    And the user should see the element                jQuery=.cell-error #row-total-24
    And the user clicks the button/link                jQuery=.button:contains("Save and return to spend profile overview")
    When the user clicks the button/link               link=${Katz_Name}
    Then the user should see the text in the page      You cannot submit your spend profile. Your total costs are higher than the eligible project costs.
    And the user should see the element                jQuery=.error-summary-list li:contains("24")  #TODO this will change due to INFUND-6801
    When the user clicks the button/link               jQuery=.button:contains("Edit spend profile")
    Then the user enters text to a text field          css=#row-24-0    222
    And the user should not see the element            jQuery=.cell-error #row-total-24
    When the user enters text to a text field          css=#row-26-2    -55  # Materials-Aug17
    And the user moves focus to the element            css=#row-26-1
    Then the user should see the element               jQuery=.error-summary-list li:contains("This field should be 0 or higher")
    When the user enters text to a text field          css=#row-24-2    35.25
    And the user moves focus to the element            css=#row-25-2
    Then the user should see the text in the page      This field can only accept whole numbers
    When the user enters text to a text field          css=#row-26-2    200
    And the user moves focus to the element            css=#row-26-1
    And the user should not see the element            jQuery=.error-summary-list li:contains("This field should be 0 or higher")
    When the user enters text to a text field          css=#row-26-2    278
    And the user moves focus to the element            css=#row-26-1
    Then the user should not see the element           jQuery=.error-summary-list li:contains("This field should be 0 or higher")
    And the user should not see the element            jQuery=.cell-error #row-total-24
    Then the user clicks the button/link               jQuery=.button:contains("Save and return to spend profile overview")


Lead partner can submit empty cells and this is handled gracefully<commit_msg>Made expected change in robot tests to see new validation message<commit_after>*** Settings ***
Documentation     INFUND-3970 As a partner I want a spend profile page in Project setup so that I can access and share Spend profile information within my partner organisation before submitting to the Project Manager
...
...               INFUND-3764 As a partner I want to view a Spend Profile showing my partner organisation's eligible project costs divided equally over the duration of our project to begin review our project costs before submitting to the Project Manager
...
...               INFUND-3765 As a partner I want to be able to edit my Spend profile so I can prepare an updated profile for my organisation before submission to the Project Manager
...
...               INFUND-3971 As a partner I want to be able to view my spend profile in a summary table so that I can review my spend profile by financial year
...
...               INFUND-2638 As a Competitions team member I want to view a page providing a link to each partners' submitted spend profile so that I can confirm these have been approved by the Technical Lead
...
...               INFUND-3766 As a project manager I want a summary page so I can review of all partners’ spend profiles that are marked as complete
...
...               INFUND-5194 As a partner I want to be see the project costs that were input during Finance Checks showing in the default spend profile so that I can begin to review my spend profile using the approved figures
...
...               INFUND-4819 As an academic partner I want to be given an alternative view of the Spend Profile in Project Setup so that I can submit information approriate to an academic organisation
...
...               INFUND-5609 PM can see partners' spend profiles before they are marked as complete, and can see buttons to edit and mark as complete
...
...               INFUND-5911 Internal users should not have access to external users' pages
...
...               INFUND-3973 As a Project Finance team member I want to be able to export submitted spend profile tables so that these may be distributed offline to Lead Technologists and Monitoring Officers
...
...               INFUND-5846 As a partner in an acedemic organisation I want to be able to edit my Spend profile so I can prepare an updated profile for my organisation before submission to the Project Manager
...
...               INFUND-5441 As a Project Finance team member I want to be able to export submitted spend profile tables from academic organisations so that these may be distributed offline to Lead Technologists and Monitoring Officers
...
...               INFUND-6046 Spend Profile should have a link when Done
...
...               INFUND-6350 As a lead partner I want to be able to return edit rights to a non-lead partner so that they can further amend their Spend Profile if requested by the lead
...
...               INFUND-6146 Saving blank fields on the spend profile results in an internal server error (null pointer exception)
...
...               INFUND-6225 External user status indicator for spend profile should show as 'waiting' once submitted
...
...               INFUND-6226 Comp admin user (non project finance) not able to view the spend profile page
...
...               INFUND-6881 Non-lead External User should see Green Check once he submits SP
...
...               INFUND-7119 GOL status for Internal user
Suite Setup       all previous sections of the project are completed
Suite Teardown    the user closes the browser
Force Tags        Project Setup
Resource          ../../resources/defaultResources.robot
Resource          PS_Variables.robot

*** Variables ***
${project_overview}    ${server}/project-setup/project/${PS_SP_APPLICATION_PROJECT}
${external_spendprofile_summary}    ${server}/project-setup/project/${PS_SP_APPLICATION_PROJECT}/partner-organisation/${Katz_Id}/spend-profile
${project_duration}    36

*** Test Cases ***
Project Finance user generates the Spend Profile
    [Documentation]    INFUND-5194
    [Tags]    HappyPath
    [Setup]    log in as user               &{internal_finance_credentials}
    Given the user navigates to the page    ${server}/project-setup-management/project/${PS_SP_APPLICATION_PROJECT}/finance-check
    Then the user should see the element    jQuery=a.eligibility-0:contains("Approved")
    And the user should see the element     jQuery=a.eligibility-1:contains("Approved")
    And the user should see the element     jQuery=a.eligibility-2:contains("Approved")
    Then the user should see the element    jQuery=.generate-spend-profile-main-button

Project Finance cancels the generation of the Spend Profile
    [Documentation]    INFUND-5194
    [Tags]
    When the user clicks the button/link    jQuery=.generate-spend-profile-main-button
    Then the user should see the text in the page    This will generate a flat profile spend for all project partners.
    When the user clicks the button/link    jQuery=.button:contains("Cancel")

Project Finance generates the Spend Profile
    [Documentation]    INFUND-5194, INFUND-5987
    [Tags]    HappyPath
    When the user clicks the button/link    jQuery=.generate-spend-profile-main-button
    And the user clicks the button/link     jQuery=#generate-spend-profile-modal-button
    Then the user should see the element    jQuery=.success-alert p:contains("The finance checks have been approved and profiles generated.")
    When the user navigates to the page     ${server}/project-setup-management/competition/${PS_SP_Competition_Id}/status
    Then the user should see the element    jQuery=#table-project-status tr:nth-of-type(3) td:nth-of-type(4).ok

Lead partner can view spend profile page
    [Documentation]    INFUND-3970
    [Tags]    HappyPath
    [Setup]    Log in as a different user    ${PS_SP_APPLICATION_LEAD_PARTNER_EMAIL}    ${short_password}
    Given the user clicks the button/link    link=${PS_SP_APPLICATION_HEADER}
    When the user clicks the button/link     link=Spend profile
    And the user clicks the button/link      link=${Katz_Name}
    Then the user should not see an error in the page
    And the user should see the text in the page    We have reviewed and confirmed your project costs.
    And the user should see the text in the page    ${Katz_Name} - Spend profile

Lead partner can see correct project start date and duration
    [Documentation]    INFUND-3970
    [Tags]
    Then the user should see the text in the page    1
    And the user should see the text in the page     June 2017
    And the user should see the text in the page     ${project_duration} months

Calculations in the spend profile table
    [Documentation]    INFUND-3764
    [Tags]    HappyPath
    Given the user should see the element    jQuery=div.spend-profile-table
    Then element should contain    css=.spend-profile-table tbody tr:nth-child(1) td:nth-last-child(2)    £ 8,000     #Labour
    Then element should contain    css=.spend-profile-table tbody tr:nth-child(2) td:nth-last-child(2)    £ 2,000     #Overheads
    Then element should contain    css=.spend-profile-table tbody tr:nth-child(3) td:nth-last-child(2)    £ 10,000    #Materials
    Then element should contain    css=.spend-profile-table tbody tr:nth-child(4) td:nth-last-child(2)    £ 10,000    #Capital usage
    Then element should contain    css=.spend-profile-table tbody tr:nth-child(5) td:nth-last-child(2)    £ 10,000    #Subcontracting
    Then element should contain    css=.spend-profile-table tbody tr:nth-child(6) td:nth-last-child(2)    £ 10,000    #Travel & subsistence
    Then element should contain    css=.spend-profile-table tbody tr:nth-child(7) td:nth-last-child(2)    £ 10,000    #Other costs
    #${duration} is No of Months + 1, due to header
    And the sum of tds equals the total    div.spend-profile-table    1    38    8000     # Labour
    And the sum of tds equals the total    div.spend-profile-table    3    38    10000    # Materials
    And the sum of tds equals the total    div.spend-profile-table    5    38    10000    # Subcontracting
    And the sum of tds equals the total    div.spend-profile-table    6    38    10000    # Travel & subsistence
    And the sum of tds equals the total    div.spend-profile-table    7    38    10000    # Other Costs

Lead Partner can see Spend profile summary
    [Documentation]    INFUND-3971
    [Tags]    Failing
    #TODO this test case needs to be moved, to another project where the PM != Lead partner.
    Given the user navigates to the page            ${external_spendprofile_summary}/review
    And the user should see the text in the page    Project costs for financial year
    And the user moves focus to the element         jQuery=.grid-container table
    Then the user sees the text in the element      jQuery=.grid-container table tr:nth-child(1) td:nth-child(2)    £ 16,632

Lead partner can edit his spend profile with invalid values
    [Documentation]    INFUND-3765
    [Tags]    #HappyPath
    When the user clicks the button/link               jQuery=.button:contains("Edit spend profile")
    Then the text box should be editable               css=#row-24-0  # Labour-June17
    When the user enters text to a text field          css=#row-24-0    2899
    And the user moves focus to the element            css=#row-24-2
    Then the user should see the text in the page      Unable to submit spend profile.
    And the user should see the text in the page       Your total costs are higher than your eligible costs
    Then the field has value                           css=#row-total-24    £ 10,669
    And the user should see the element                jQuery=.cell-error #row-total-24
    And the user clicks the button/link                jQuery=.button:contains("Save and return to spend profile overview")
    When the user clicks the button/link               link=${Katz_Name}
    Then the user should see the text in the page      You cannot submit your spend profile. Your total costs are higher than the eligible project costs.
    And the user should see the element                jQuery=.error-summary-list li:contains("Labour")
    When the user clicks the button/link               jQuery=.button:contains("Edit spend profile")
    Then the user enters text to a text field          css=#row-24-0    222
    And the user should not see the element            jQuery=.cell-error #row-total-24
    When the user enters text to a text field          css=#row-26-2    -55  # Materials-Aug17
    And the user moves focus to the element            css=#row-26-1
    Then the user should see the element               jQuery=.error-summary-list li:contains("This field should be 0 or higher")
    When the user enters text to a text field          css=#row-24-2    35.25
    And the user moves focus to the element            css=#row-25-2
    Then the user should see the text in the page      This field can only accept whole numbers
    When the user enters text to a text field          css=#row-26-2    200
    And the user moves focus to the element            css=#row-26-1
    And the user should not see the element            jQuery=.error-summary-list li:contains("This field should be 0 or higher")
    When the user enters text to a text field          css=#row-26-2    278
    And the user moves focus to the element            css=#row-26-1
    Then the user should not see the element           jQuery=.error-summary-list li:contains("This field should be 0 or higher")
    And the user should not see the element            jQuery=.cell-error #row-total-24
    Then the user clicks the button/link               jQuery=.button:contains("Save and return to spend profile overview")


Lead partner can submit empty cells and this is handled gracefully
{'fraction_non_alphanumeric': 0.0612702576905175, 'fraction_numerical': 0.025388228324800068, 'mean_word_length': 2.6824555936428793, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '143000', 'n_tokens_mistral': 6522, 'n_tokens_neox': 6028, 'n_words': 2906}