#---
#This unit test checks the party management screens and processes.
#
# File: user_management.rb
# Created: 18-Dec-2007
# Created by: MM
#
# Test_07_MIPADMIN_party_management
#    - test_01_screen_appears
#    - test_02_create_mktp
#    - test_03_create_user_suppadmin
#    - test_04_create_user_agent
#    - test_05_create_user_cs
#    - test_06_create_user_icu
#
#  Test_08_SUPPADMIN_party_management
#    - test_01_create_user_agent
#
#  Test_09_edit_parties
#    - test_01_edit_parties_screen_appears
#    - test_02_edit_users
#    - test_03_edit_suppliers
#---
class Test_09_MIPADMIN_party_management< Test::Unit::TestCase
  #
  #Test we can logon to the system using the webmip administrator user�s login credentials and check that 
  #all the fields required for creating parties in the system are correctly displayed.
  #
  def test_01_screen_appears
    @@ie.goto(MANAGE_PARTIES)
    #we'll need to login as a MIPADMIN user
    login('advantica','password')
    
    #confirm that there are 2 buttons available
    assert(@@ie.button(:value,'Create New Party').exists?,'Could not find Create New Party button')
    assert(@@ie.button(:value,'Edit Party').exists?,'Could not find Edit Party button')

    #let's create a party
    @@ie.button(:name,'Create New Party').click
    #check the items on the page
    assert(@@ie.select_list(:id,'P61_PRTY_TYPE').exists?,'Could not find P61_PRTY_TYPE select list')
    
    #Check the list of dropdowns is as expected
    party_types = ["- Select Party Type -", "Market Participant", "User", "Manufacturer"]
    assert_equal(party_types,@@ie.select_list(:id, 'P61_PRTY_TYPE').getAllContents ,'List of available party types does not match expected list')
    
    #check the correct fields are displayed when we select party types
    #create Market Participant
    @@ie.select_list(:id,'P61_PRTY_TYPE').set('Market Participant')
    assert(@@ie.button(:value,'Cancel').exists?,'Could not find Cancel button')
    assert(@@ie.button(:value,'Next >').exists?,'Could not find Next > button')
    assert(@@ie.text_field(:id,'P61_NAME').exists?,'Could not find P61_NAME field')
    assert(@@ie.text_field(:id,'P61_SHORTCODE').exists?,'Could not find P61_SHORTCODE field')
    assert(@@ie.text_field(:id,'P61_MKTP_REF').exists?,'Could not find P61_MKTP_REF field')
    assert(@@ie.text_field(:id,'P61_LT_7B_CONTRACT_REF').exists?,'Could not find P61_LT_7B_CONTRACT_REF field')
    assert(@@ie.text_field(:id,'P61_GT_7B_CONTRACT_REF').exists?,'Could not find P61_GT_7B_CONTRACT_REF field')
    assert(@@ie.text_field(:id,'P61_ADV_CONTRACT_REF').exists?,'Could not find P61_ADV_CONTRACT_REF field')
    assert(@@ie.select_list(:id,'P61_TRIPARTITE').exists?,'Could not find P61_TRIPARTITE select list')
    
    #Manufacturer
    @@ie.select_list(:id,'P61_PRTY_TYPE').set('Manufacturer')
    assert(@@ie.button(:value,'Cancel').exists?,'Could not find Cancel button')
    assert(@@ie.button(:value,'Next >').exists?,'Could not find Next > button')
    assert(@@ie.text_field(:id,'P61_NAME').exists?,'Could not find P61_NAME field')
    assert(@@ie.text_field(:id,'P61_MANU_REF').exists?,'Could not find P61_MANU_REF field')
    assert(@@ie.text_field(:id,'P61_DESCRIPTION').exists?,'Could not find P61_DESCRIPTION field')
    
    #create USER
    @@ie.select_list(:id,'P61_PRTY_TYPE').set('User')
    assert(@@ie.button(:value,'Cancel').exists?,'Could not find Cancel button')
    assert(@@ie.button(:value,'Next >').exists?,'Could not find Next > button')
    assert(@@ie.text_field(:id,'P61_USERNAME').exists?,'Could not find P61_USERNAME field')
    assert(@@ie.text_field(:id,'P61_TITLE').exists?,'Could not find P61_TITLE field')
    assert(@@ie.text_field(:id,'P61_FIRST_NAME').exists?,'Could not find P61_FIRST_NAME field')
    assert(@@ie.text_field(:id,'P61_LAST_NAME').exists?,'Could not find P61_LAST_NAME field')
    assert(@@ie.text_field(:id,'P61_COMMENTS').exists?,'Could not find P61_COMMENTS field')
     assert(@@ie.text_field(:id,'P61_PASSWORD').exists?,'Could not find P61_PASSWORD file upload field')
    assert(@@ie.text_field(:id,'P61_REPEAT_PASSWORD').exists?,'Could not find P61_REPEAT_PASSWORD file upload field')
    assert(@@ie.select_list(:id,'P61_EXPIRE_PWORD').exists?,'Could not find P61_EXPIRE_PWORD select list')
    
    #Test the objects on P62
    @@ie.goto(ASSIGN_PARTY_ROLE)
    #we'll need to login as a MIPADMIN user
    login('advantica','password')
    
    assert(@@ie.button(:value,'Cancel').exists?,'Could not find Cancel button')
    assert(@@ie.button(:value,'< Previous').exists?,'Could not find < Previous button')
    assert(@@ie.button(:value,'Next >').exists?,'Could not find Next > button')
    assert(@@ie.select_list(:id,'P62_PRTY_ROLE').exists?,'Could not find P62_PRTY_ROLE select list')
    #assert(@@ie.select_list(:id,'P62_USER_SUPPLIER').exists?,'Could not find P62_USER_SUPPLIER select list')
    #assert(@@ie.select_list(:id,'P62_SUPP_ADMIN').exists?,'Could not find P62_SUPP_ADMIN select list')
    assert(@@ie.text_field(:id,'P62_PHONE').exists?,'Could not find P62_PHONE field')
    assert(@@ie.text_field(:id,'P62_FAX').exists?,'Could not find P62_FAX field')
    assert(@@ie.text_field(:id,'P62_MOBILE').exists?,'Could not find P62_MOBILE field')
    assert(@@ie.text_field(:id,'P62_EMAIL').exists?,'Could not find P62_EMAIL field')
  
    #Test the objects on P63
    @@ie.goto(PARTY_CONTACT_DETAILS)
    #we'll need to login as a MIPADMIN user
    login('advantica','password')
    
    assert(@@ie.button(:value,'Cancel').exists?,'Could not find Cancel button')
    assert(@@ie.button(:value,'< Previous').exists?,'Could not find < Previous button')
    assert(@@ie.button(:value,'Next >').exists?,'Could not find Next > button')
    assert(@@ie.text_field(:id,'P63_SELECT_ADDRESS').exists?,'Could not find P63_SELECT_ADDRESS field')
    assert(@@ie.button(:value,'Copy Address').exists?,'Could not find Copy Address button')
    assert(@@ie.text_field(:id,'P63_OFF_CODE').exists?,'Could not find P63_OFF_CODE field')
    assert(@@ie.text_field(:id,'P63_OFF_SUB_BUILD').exists?,'Could not find P63_OFF_SUB_BUILD field')
    assert(@@ie.text_field(:id,'P63_OFF_BUILDING').exists?,'Could not find P63_OFF_BUILDING field')
    assert(@@ie.text_field(:id,'P63_OFF_STREET').exists?,'Could not find P63_OFF_STREET field')
    assert(@@ie.text_field(:id,'P63_OFF_CITY').exists?,'Could not find P63_OFF_CITY field')
    assert(@@ie.text_field(:id,'P63_OFF_POSTCODE').exists?,'Could not find P63_OFF_POSTCODE field')

    #Test the objects on P64
    @@ie.goto(PARTY_HOME_ADDR)
    #we'll need to login as a MIPADMIN user
    login('advantica','password')
    
    assert(@@ie.button(:value,'Cancel').exists?,'Could not find Cancel button')
    assert(@@ie.button(:value,'< Previous').exists?,'Could not find < Previous button')
    assert(@@ie.button(:value,'Finish').exists?,'Could not find Finish button')
    assert(@@ie.text_field(:id,'P64_SELECT_ADDRESS').exists?,'Could not find P64_SELECT_ADDRESS select list')
    assert(@@ie.button(:value,'Copy Address').exists?,'Could not find Copy Address button')
    assert(@@ie.text_field(:id,'P64_HOME_CODE').exists?,'Could not find P64_HOME_CODE field')
    assert(@@ie.text_field(:id,'P64_HOME_SUB_BUILD').exists?,'Could not find P64_HOME_SUB_BUILD field')
    assert(@@ie.text_field(:id,'P64_HOME_BUILDING').exists?,'Could not find P64_HOME_BUILDING field')
    assert(@@ie.text_field(:id,'P64_HOME_STREET').exists?,'Could not find P64_HOME_STREET field')
    assert(@@ie.text_field(:id,'P64_HOME_CITY').exists?,'Could not find P64_HOME_CITY field')
    assert(@@ie.text_field(:id,'P64_HOME_POSTCODE').exists?,'Could not find P64_HOME_POSTCODE field')
  end
  
  #
  #Test we can create a market participant (SUPPLIER) in the system when logged on as MIPADMIN user.
  #
  def test_02_create_mktp
    @@ie.goto(LOGIN)
    #we'll need to login as a MIPADMIN user
    login('advantica','password')
    
    #Navigate to the page using the menu
    menu('Administration')
    menu('User Management')
    #menu('Create Party')
    
    #create a new party
    @@ie.button(:name,'Create New Party').click
    #select the type of party to create
    @@ie.select_list(:id,'P61_PRTY_TYPE').set('Market Participant')
    
    # set the field values
    #@@ie.text_field(:id,'').set('')
    @@ie.text_field(:id,'P61_NAME').set('Supplier1')
    @@ie.text_field(:id,'P61_SHORTCODE').set('SU1')
    @@ie.text_field(:id,'P61_MKTP_REF').set('Test Supplier1')
    @@ie.text_field(:id,'P61_LT_7B_CONTRACT_REF').set('1')
    @@ie.text_field(:id,'P61_GT_7B_CONTRACT_REF').set('1')
    @@ie.text_field(:id,'P61_ADV_CONTRACT_REF').set('1')
    @@ie.select_list(:id,'P61_TRIPARTITE').set('Yes')
    
    @@ie.button(:value,'Next >').click
    
    #Select a role for the party
    @@ie.select_list(:id,'P62_PRTY_ROLE').set('Gas supplier')
    @@ie.wait
    #fill in the contact details bits and bobs
    @@ie.text_field(:id,'P62_PHONE').set('01234 567890')
    @@ie.text_field(:id,'P62_FAX').set('01234 567890')
    @@ie.text_field(:id,'P62_MOBILE').set('01234 567890')
    @@ie.text_field(:id,'P62_EMAIL').set('supplier@supplier1.org')
    
    @@ie.button(:value,'Next >').click
    
    #create a new address for the supplier
    @@ie.text_field(:id,'P63_OFF_CODE').set('SU1_OFFICE')
    @@ie.text_field(:id,'P63_OFF_SUB_BUILD').set('62')
    @@ie.text_field(:id,'P63_OFF_BUILDING').set('Supplier1')
    @@ie.text_field(:id,'P63_OFF_STREET').set('A Street')
    @@ie.text_field(:id,'P63_OFF_CITY').set('Supplier City')
    @@ie.text_field(:id,'P63_OFF_POSTCODE').set('LE11 3GR')
    
    @@ie.button(:value,'Next >').click
    #wont bother setting a home address as we don't need to so we'll create the supplier
    @@ie.button(:value,'Finish').click
    assert(@@ie.contains_text('created successfully'),'MKTP not created correctly.')
  end
  
  #
  #Test we can create a user (SUPPADMIN) in the system when logged on as MIPADMIN user.
  #
  def test_03_create_user_suppadmin
    #@@ie.goto(LOGIN)
    #we'll need to login as a MIPADMIN user
    #login('advantica','password')
    
    #Navigate to the page using the menu
    #menu('Administration')
    #menu('User Management')
    #menu('Create Party')
    
    #create a new party
    @@ie.button(:name,'CreateAnother').click
    #select the type of party to create
    @@ie.select_list(:id,'P61_PRTY_TYPE').set('User')
    
    # set the field values
    #@@ie.text_field(:id,'').set('')
    @@ie.text_field(:id,'P61_USERNAME').set('SuppAdmin1')
    @@ie.text_field(:id,'P61_TITLE').set('Mr.')
    @@ie.text_field(:id,'P61_FIRST_NAME').set('Supplier1')
    @@ie.text_field(:id,'P61_LAST_NAME').set('Administrator')
    @@ie.text_field(:id,'P61_COMMENTS').set('This is the administrator for Supplier1.  Created for testing.')
    @@ie.text_field(:id,'P61_PASSWORD').set('Passw0rd.')
    @@ie.text_field(:id,'P61_REPEAT_PASSWORD').set('Passw0rd.')
    @@ie.select_list(:id,'P61_EXPIRE_PWORD').set('No') #Leave the user OPEN
    
    @@ie.button(:value,'Next >').click
    @@ie.wait
    
    #Select a role for the party
    @@ie.select_list(:id,'P62_PRTY_ROLE').set('User administrator')
    @@ie.wait
    @@ie.select_list(:id,'P62_USER_SUPPLIER').set('Supplier1 - SU1')
    @@ie.wait
    #fill in the contact details bits and bobs
    @@ie.text_field(:id,'P62_PHONE').set('01234 567891')
    @@ie.text_field(:id,'P62_FAX').set('01234 567891')
    @@ie.text_field(:id,'P62_MOBILE').set('01234 567891')
    @@ie.text_field(:id,'P62_EMAIL').set('supplier_admin@supplier1.org')
    
    @@ie.button(:value,'Next >').click
    @@ie.wait
    
    #use the existing address for the supplier
    @@ie.text_field(:id,'P63_SELECT_ADDRESS').set('SU1_OFFICE')
    @@ie.button(:value,'Copy Address').click
    
    @@ie.button(:value,'Next >').click
    @@ie.wait
    #wont bother setting a home address as we don't need to so we'll create the supplier administrator
    @@ie.button(:value,'Finish').click
    @@ie.wait
    assert(@@ie.contains_text('created successfully'),'SUPPADMIN not created correctly.')
  end
  
  #
  #Test we can create a user (AGENT) in the system when logged on as MIPADMIN user.
  #
  def test_04_create_user_agent
    #@@ie.goto(LOGIN)
    #we'll need to login as a MIPADMIN user
    #login('advantica','password')
    
    #Navigate to the page using the menu
    #menu('Administration')
    #menu('User Management')
    #menu('Create Party')
    
    #create a new party
    @@ie.button(:name,'CreateAnother').click
    #select the type of party to create
    @@ie.select_list(:id,'P61_PRTY_TYPE').set('User')
    
    # set the field values
    #@@ie.text_field(:id,'').set('')
    @@ie.text_field(:id,'P61_USERNAME').set('SuppAgent1')
    @@ie.text_field(:id,'P61_TITLE').set('Mr')
    @@ie.text_field(:id,'P61_FIRST_NAME').set('Agent1')
    @@ie.text_field(:id,'P61_LAST_NAME').set('Test-Agent')
    @@ie.text_field(:id,'P61_COMMENTS').set('This is an agent for Supplier1.  Created for testing.')
    @@ie.text_field(:id,'P61_PASSWORD').set('Passw0rd.')
    @@ie.text_field(:id,'P61_REPEAT_PASSWORD').set('Passw0rd.')
    @@ie.select_list(:id,'P61_EXPIRE_PWORD').set('No') #Leave the user OPEN
    
    @@ie.button(:value,'Next >').click
    @@ie.wait
    #Select a role for the party
    @@ie.select_list(:id,'P62_PRTY_ROLE').set('Agent')
    @@ie.wait
    @@ie.select_list(:id,'P62_USER_SUPPLIER').set('Supplier1 - SU1')
    @@ie.wait
    @@ie.select_list(:id,'P62_SUPP_ADMIN').set('Supplier1 Administrator')
    
    #fill in the contact details bits and bobs
    @@ie.text_field(:id,'P62_PHONE').set('01234 567892')
    @@ie.text_field(:id,'P62_FAX').set('01234 567892')
    @@ie.text_field(:id,'P62_MOBILE').set('01234 567892')
    @@ie.text_field(:id,'P62_EMAIL').set('agent1@supplier1.org')
    
    @@ie.button(:value,'Next >').click
    @@ie.wait    
    #use the existing address for the supplier
    @@ie.text_field(:id,'P63_SELECT_ADDRESS').set('SU1_OFFICE')
    @@ie.button(:value,'Copy Address').click
    @@ie.wait    
    @@ie.button(:value,'Next >').click
    @@ie.wait    
    #wont bother setting a home address as we don't need to so we'll create the supplier administrator
    @@ie.button(:value,'Finish').click
    @@ie.wait    
    assert(@@ie.contains_text('created successfully'),'AGENT not created correctly.')
  end
  
  #
  #Test we can create a user (CS) in the system when logged on as MIPADMIN user.
  #
  def test_05_create_user_cs
    #@@ie.goto(LOGIN)
    #we'll need to login as a MIPADMIN user
    #login('advantica','password')
    
    #Navigate to the page using the menu
    #menu('Administration')
    #menu('User Management')
    #menu('Create Party')
    
    #create a new party
    @@ie.button(:name,'CreateAnother').click
    #select the type of party to create
    @@ie.select_list(:id,'P61_PRTY_TYPE').set('User')
    
    # set the field values
    #@@ie.text_field(:id,'').set('')
    @@ie.text_field(:id,'P61_USERNAME').set('CustServ1')
    @@ie.text_field(:id,'P61_TITLE').set('Miss')
    @@ie.text_field(:id,'P61_FIRST_NAME').set('Customer')
    @@ie.text_field(:id,'P61_LAST_NAME').set('Services')
    @@ie.text_field(:id,'P61_COMMENTS').set('This is a customer service for Supplier1.  Created for testing.')
    @@ie.text_field(:id,'P61_PASSWORD').set('Passw0rd.')
    @@ie.text_field(:id,'P61_REPEAT_PASSWORD').set('Passw0rd.')
    @@ie.select_list(:id,'P61_EXPIRE_PWORD').set('No') #Leave the user OPEN
    
    @@ie.button(:value,'Next >').click
    @@ie.wait    
    #Select a role for the party
    @@ie.select_list(:id,'P62_PRTY_ROLE').set('Customer Service operative')
    @@ie.wait
    #@@ie.select_list(:id,'P62_USER_SUPPLIER').set('Supplier1 - SU1') - no supplier needed for a CS operative
    
    #fill in the contact details bits and bobs
    @@ie.text_field(:id,'P62_PHONE').set('01234 567893')
    @@ie.text_field(:id,'P62_FAX').set('01234 567893')
    @@ie.text_field(:id,'P62_MOBILE').set('01234 567893')
    @@ie.text_field(:id,'P62_EMAIL').set('cs1@metering.ng.co.uk')
    
    @@ie.button(:value,'Next >').click
    @@ie.wait    
    #create a customer services address
    @@ie.text_field(:id,'P63_OFF_CODE').set('CS_OFFICE')
    @@ie.text_field(:id,'P63_OFF_SUB_BUILD').set('1')
    @@ie.text_field(:id,'P63_OFF_BUILDING').set('Metering House')
    @@ie.text_field(:id,'P63_OFF_STREET').set('Meter Road')
    @@ie.text_field(:id,'P63_OFF_CITY').set('Meter City')
    @@ie.text_field(:id,'P63_OFF_POSTCODE').set('LE11 3GR')
    
    @@ie.button(:value,'Next >').click
    @@ie.wait    
    #wont bother setting a home address as we don't need to so we'll create the supplier administrator
    @@ie.button(:value,'Finish').click
    assert(@@ie.contains_text('created successfully'),'CS user not created correctly.')
  end
  
  #
  #Test we can create a user (ICU) in the system when logged on as MIPADMIN user.
  #
  def test_06_create_user_icu
    #@@ie.goto(LOGIN)
    #we'll need to login as a MIPADMIN user
    #login('advantica','password')
    
    #Navigate to the page using the menu
    #menu('Administration')
    #menu('User Management')
    #menu('Create Party')
    
    #create a new party
    @@ie.button(:name,'CreateAnother').click
    #select the type of party to create
    @@ie.select_list(:id,'P61_PRTY_TYPE').set('User')
    
    # set the field values
    #@@ie.text_field(:id,'').set('')
    @@ie.text_field(:id,'P61_USERNAME').set('ICU1')
    @@ie.text_field(:id,'P61_TITLE').set('Mrs')
    @@ie.text_field(:id,'P61_FIRST_NAME').set('ICU')
    @@ie.text_field(:id,'P61_LAST_NAME').set('User')
    @@ie.text_field(:id,'P61_COMMENTS').set('This is an ICU user for Supplier1.  Created for testing.')
    @@ie.text_field(:id,'P61_PASSWORD').set('Passw0rd.')
    @@ie.text_field(:id,'P61_REPEAT_PASSWORD').set('Passw0rd.')
    @@ie.select_list(:id,'P61_EXPIRE_PWORD').set('No') #Leave the user OPEN
    
    @@ie.button(:value,'Next >').click
    @@ie.wait    
    #Select a role for the party
    @@ie.select_list(:id,'P62_PRTY_ROLE').set('Quotation operative')
    @@ie.wait
    #@@ie.select_list(:id,'P62_USER_SUPPLIER').set('Supplier1 - SU1')
    
    #fill in the contact details bits and bobs
    @@ie.text_field(:id,'P62_PHONE').set('01234 567894')
    @@ie.text_field(:id,'P62_FAX').set('01234 567894')
    @@ie.text_field(:id,'P62_MOBILE').set('01234 567894')
    @@ie.text_field(:id,'P62_EMAIL').set('icu1@metering.ng.co.uk')
    
    @@ie.button(:value,'Next >').click
    @@ie.wait    
    #create a customer services address
    @@ie.text_field(:id,'P63_OFF_CODE').set('ICU_OFFICE')
    @@ie.text_field(:id,'P63_OFF_SUB_BUILD').set('2')
    @@ie.text_field(:id,'P63_OFF_BUILDING').set('Metering House')
    @@ie.text_field(:id,'P63_OFF_STREET').set('Meter Road')
    @@ie.text_field(:id,'P63_OFF_CITY').set('Meter City')
    @@ie.text_field(:id,'P63_OFF_POSTCODE').set('LE11 3GR')
    
    @@ie.button(:value,'Next >').click
    @@ie.wait    
    #wont bother setting a home address as we don't need to so we'll create the supplier administrator
    @@ie.button(:value,'Finish').click
    @@ie.wait    
    assert(@@ie.contains_text('created successfully'),'ICU user not created correctly.')
  end
  
  #
  #Test we can create a market participant (SUPPLIER) in the system when logged on as MIPADMIN user.
  #
  def test_07_create_manu
    @@ie.goto(LOGIN)
    #we'll need to login as a MIPADMIN user
    login('advantica','password')
    
    #Navigate to the page using the menu
    menu('Administration')
    menu('User Management')
    #menu('Create Party')
    
    #create a new party
    @@ie.button(:name,'Create New Party').click
    #select the type of party to create
    @@ie.select_list(:id,'P61_PRTY_TYPE').set('Manufacturer')
    
    # set the field values
    #@@ie.text_field(:id,'').set('')
    @@ie.text_field(:id,'P61_NAME').set('Manufacturer1')
    @@ie.text_field(:id,'P61_MANU_REF').set('Manu1')
    @@ie.text_field(:id,'P61_DESCRIPTION').set('Test manufacturer created for testing.')
    @@ie.button(:value,'Next >').click
    @@ie.wait    
    #Select a role for the party
    @@ie.select_list(:id,'P62_PRTY_ROLE').set('External organization')
    @@ie.wait
    @@ie.select_list(:id,'P62_ORG_SUPPLIER').set('Supplier1 - SU1')
    @@ie.wait
    
    #fill in the contact details bits and bobs
    @@ie.text_field(:id,'P62_PHONE').set('01234 567890')
    @@ie.text_field(:id,'P62_FAX').set('01234 567890')
    @@ie.text_field(:id,'P62_MOBILE').set('01234 567890')
    @@ie.text_field(:id,'P62_EMAIL').set('manu1@manufacturer1.org')
    
    @@ie.button(:value,'Next >').click
    @@ie.wait    
    #create a new address for the supplier
    @@ie.text_field(:id,'P63_OFF_CODE').set('MANU1_OFFICE')
    @@ie.text_field(:id,'P63_OFF_SUB_BUILD').set('1')
    @@ie.text_field(:id,'P63_OFF_BUILDING').set('Manufacturer1')
    @@ie.text_field(:id,'P63_OFF_STREET').set('A Street')
    @@ie.text_field(:id,'P63_OFF_CITY').set('Manufacturer City')
    @@ie.text_field(:id,'P63_OFF_POSTCODE').set('LE11 3GR')
    
    @@ie.button(:value,'Next >').click
    @@ie.wait    
    #wont bother setting a home address as we don't need to so we'll create the supplier
    @@ie.button(:value,'Finish').click
    @@ie.wait    
    assert(@@ie.contains_text('created successfully'),'MANU not created correctly.')
  end
end

class Test_10_SUPPADMIN_party_management< Test::Unit::TestCase
  #
  #Test we can create a user (AGENT) in the system when logged on as SUPPADMIN user.
  #
  def test_01_create_user_agent
    @@ie.goto(LOGIN)
    #we'll need to login as a SUPPADMIN user
    #use the one created in test 3 above
    login('SuppAdmin1','Passw0rd.')
    
    #Navigate to the page using the menu
    menu('Administration')
    menu('User Management')
    menu('Create Party')
    
    #select the type of party to create
    #@@ie.select_list(:id,'P61_PRTY_TYPE').set('User')
    #this now should default to the 'User' role so search for that instead
    assert(@@ie.contains_text('User'),'Could not find default User role type display text')
    # set the field values
    #@@ie.text_field(:id,'').set('')
    @@ie.text_field(:id,'P61_USERNAME').set('SuppAgent2')
    @@ie.text_field(:id,'P61_TITLE').set('Mr')
    @@ie.text_field(:id,'P61_FIRST_NAME').set('Agent2')
    @@ie.text_field(:id,'P61_LAST_NAME').set('Test-Agent')
    @@ie.text_field(:id,'P61_COMMENTS').set('This is an agent for Supplier1.  Created for testing by SUPPADMIN user.')
    @@ie.text_field(:id,'P61_PASSWORD').set('Passw0rd.')
    @@ie.text_field(:id,'P61_REPEAT_PASSWORD').set('Passw0rd.')
    @@ie.select_list(:id,'P61_EXPIRE_PWORD').set('No') 
    
    @@ie.button(:value,'Next >').click
    @@ie.wait    
    #Select a role for the party
    @@ie.select_list(:id,'P62_PRTY_ROLE').set('Agent')
    @@ie.wait
    @@ie.select_list(:id,'P62_USER_SUPPLIER').set('Supplier1 - SU1')
    @@ie.wait
    @@ie.select_list(:id,'P62_SUPP_ADMIN').set('Supplier1 Administrator')
    
    #fill in the contact details bits and bobs
    @@ie.text_field(:id,'P62_PHONE').set('01234 567810')
    @@ie.text_field(:id,'P62_FAX').set('01234 567810')
    @@ie.text_field(:id,'P62_MOBILE').set('01234 567810')
    @@ie.text_field(:id,'P62_EMAIL').set('agent2@supplier1.org')
    
    @@ie.button(:value,'Next >').click
    @@ie.wait    
    #use the existing address for the supplier
    @@ie.text_field(:id,'P63_SELECT_ADDRESS').set('SU1_OFFICE')
    @@ie.button(:value,'Copy Address').click
    @@ie.wait    
    @@ie.button(:value,'Next >').click
    @@ie.wait    
    #wont bother setting a home address as we don't need to so we'll create the supplier administrator
    @@ie.button(:value,'Finish').click
    @@ie.wait
    assert(@@ie.contains_text('created successfully'),'AGENT not created correctly.')
  end
end

class Test_11_edit_parties< Test::Unit::TestCase
  #
  #Test we can edit a user (AGENT) in the system when logged on as MIPADMIN user.
  #
  def test_01_edit_parties_screen_appears
    @@ie.goto(LOGIN)
    #we'll need to login as a MIPADMIN user
    login('advantica','password')
    
    #Navigate to the page using the menu
    menu('Administration')
    menu('User Management')
    menu('Edit Parties')
    
    #simple screen, only 1 object
    assert(@@ie.select_list(:id,'P65_PRTY_TYPE').exists?,'Could not find P65_PRTY_TYPE select list')
    
    #check user fields
    @@ie.link(:name,'Edit Current User').click
    assert(@@ie.button(:value,'Cancel').exists?,'Could not find Cancel button(user fields)')
    assert(@@ie.button(:value,'Apply Changes').exists?,'Could not find Apply Changes button')
    #Status is a display only field
    #assert(@@ie.select_list(:id,'P66_STATUS').exists?,'Could not find P66_STATUS select list')
    assert(@@ie.text_field(:id,'P66_FIRST_NAME').exists?,'Could not find P66_FIRST_NAME field')
    assert(@@ie.text_field(:id,'P66_LAST_NAME').exists?,'Could not find P66_LAST_NAME field')
    assert(@@ie.text_field(:id,'P66_PERSONAL_TITLE').exists?,'Could not find P66_PERSONAL_TITLE field')
    assert(@@ie.text_field(:id,'P66_COMMENTS').exists?,'Could not find P66_COMMENTS field')
    assert(@@ie.button(:value,'Add Address').exists?,'Could not find Add Address button')
    assert(@@ie.text_field(:id,'P66_TELEPHONE').exists?,'Could not find P66_TELEPHONE field')
    assert(@@ie.text_field(:id,'P66_MOBILE').exists?,'Could not find P66_MOBILE field')
    assert(@@ie.text_field(:id,'P66_FAX').exists?,'Could not find P66_FAX field')
    assert(@@ie.text_field(:id,'P66_EMAIL').exists?,'Could not find P66_EMAIL field')

    @@ie.button(:value,'Cancel').click
    @@ie.wait    
    #check market participant fields
    @@ie.select_list(:id,'P65_PRTY_TYPE').set('Market Participant')
    @@ie.link(:name,/Edit Supplier1 SU1/).click
    @@ie.wait    
    assert(@@ie.button(:value,'Cancel').exists?,'Could not find Cancel button(mktp fields)')
    assert(@@ie.button(:value,'Delete').exists?,'Could not find Delete button')
    assert(@@ie.button(:value,'Apply Changes').exists?,'Could not find Apply Changes button')
    assert(@@ie.text_field(:id,'P66_SHORTCODE').exists?,'Could not find P66_SHORTCODE field')
    assert(@@ie.text_field(:id,'P66_NAME').exists?,'Could not find P66_NAME field')
    assert(@@ie.text_field(:id,'P66_MKTP_REF').exists?,'Could not find P66_MKTP_REF field')
    assert(@@ie.text_field(:id,'P66_LT_7B_CONTRACT_REF').exists?,'Could not find P66_LT_7B_CONTRACT_REF field')
    assert(@@ie.text_field(:id,'P66_GT_7B_CONTRACT_REF').exists?,'Could not find P66_GT_7B_CONTRACT_REF field')
    assert(@@ie.text_field(:id,'P66_ADVERSARIAL_CONTRACT_REF').exists?,'Could not find P66_ADVERSARIAL_CONTRACT_REF field')
    assert(@@ie.button(:value,'Add Address').exists?,'Could not find Add Address button')
    assert(@@ie.text_field(:id,'P66_TELEPHONE').exists?,'Could not find P66_TELEPHONE field')
    assert(@@ie.text_field(:id,'P66_MOBILE').exists?,'Could not find P66_MOBILE field')
    assert(@@ie.text_field(:id,'P66_FAX').exists?,'Could not find P66_FAX field')
    assert(@@ie.text_field(:id,'P66_EMAIL').exists?,'Could not find P66_EMAIL field')

    @@ie.button(:value,'Cancel').click
    @@ie.wait
    #check manufacturer fields
    @@ie.select_list(:id,'P65_PRTY_TYPE').set('Manufacturer')
    @@ie.link(:name,/Edit Manufacturer1/).click
    @@ie.wait    
    assert(@@ie.button(:value,'Cancel').exists?,'Could not find Cancel button(manu fields)')
    assert(@@ie.button(:value,'Apply Changes').exists?,'Could not find Apply Changes button')
    assert(@@ie.text_field(:id,'P66_MANU_REF').exists?,'Could not find P66_MANU_REF field')
    assert(@@ie.text_field(:id,'P66_NAME').exists?,'Could not find P66_NAME field')
    assert(@@ie.text_field(:id,'P66_DESCRIPTION').exists?,'Could not find P66_DESCRIPTION field')
    assert(@@ie.button(:value,'Add Address').exists?,'Could not find Add Address button')
    assert(@@ie.text_field(:id,'P66_TELEPHONE').exists?,'Could not find P66_TELEPHONE field')
    assert(@@ie.text_field(:id,'P66_MOBILE').exists?,'Could not find P66_MOBILE field')
    assert(@@ie.text_field(:id,'P66_FAX').exists?,'Could not find P66_FAX field')
    assert(@@ie.text_field(:id,'P66_EMAIL').exists?,'Could not find P66_EMAIL field')

    @@ie.button(:value,'Add Address').click
    @@ie.wait    
    assert(@@ie.text_field(:id,'P69_SELECT_ADDRESS').exists?,'Could not find P69_SELECT_ADDRESS select list')
    assert(@@ie.button(:value,'Copy Address').exists?,'Could not find Copy Address button')
    assert(@@ie.text_field(:id,'P69_ADDR_CODE').exists?,'Could not find P69_ADDR_CODE field')
    assert(@@ie.select_list(:id,'P69_ADDR_TYPE').exists?,'Could not find P69_ADDR_TYPE select list')
    assert(@@ie.text_field(:id,'P69_ADDR_SUB_BUILDING').exists?,'Could not find P69_ADDR_SUB_BUILDING field')
    assert(@@ie.text_field(:id,'P69_ADDR_BUILDING').exists?,'Could not find P69_ADDR_BUILDING field')
    assert(@@ie.text_field(:id,'P69_ADDR_STREET').exists?,'Could not find P69_ADDR_STREET field')
    assert(@@ie.text_field(:id,'P69_ADDR_CITY').exists?,'Could not find P69_ADDR_CITY field')
    assert(@@ie.text_field(:id,'P69_ADDR_POSTCODE').exists?,'Could not find P69_ADDR_POSTCODE field')
    assert(@@ie.button(:value,'Save').exists?,'Could not find Save button')

  end
  
  def test_02_edit_users
    @@ie.goto(LOGIN)
    #we'll need to login as a MIPADMIN user
    login('advantica','password')
    
    #Navigate to the page using the menu
    menu('Administration')
    menu('User Management')
    menu('Edit Parties')
  
    @@ie.link(:name,'Edit Current User').click
    @@ie.text_field(:id,'P66_FIRST_NAME').set('Updated')
    @@ie.text_field(:id,'P66_TELEPHONE').set('01234 567899')
    @@ie.button(:value,'Apply Changes').click
    
    assert(@@ie.contains_text('Action Processed.'),'Party not updated correctly')
    
    #edit a different user
    #@@ie.goto(EDIT_PARTIES)
    @@ie.select_list(:id,'P65_PRTY_TYPE').set('User')
    @@ie.link(:text,/Next/).click
    @@ie.wait
    @@ie.link(:name,/Edit SuppAgent1/).click
    @@ie.wait    
    @@ie.text_field(:id,'P66_TELEPHONE').set('01234 567899')
    @@ie.button(:value,'Apply Changes').click
    @@ie.wait    
    assert(@@ie.contains_text('Action Processed.'),'Party not updated correctly')
    
    @@ie.goto(LOGIN)
    #we'll need to login as a SUPPADMIN user
    login('SuppAdmin1','Passw0rd.')
    
    #Navigate to the page using the menu
    menu('Administration')
    menu('User Management')
    menu('Edit Parties')
  
    @@ie.link(:name,'Edit Current User').click
    @@ie.wait
    @@ie.text_field(:id,'P66_FIRST_NAME').set('Updated')
    @@ie.text_field(:id,'P66_TELEPHONE').set('01234 567899')
    @@ie.button(:value,'Apply Changes').click
    @@ie.wait    
    assert(@@ie.contains_text('Action Processed.'),'Party not updated correctly')
    
    @@ie.goto(LOGIN)
    #we'll need to login as a SUPPADMIN user
    login('SuppAdmin1','Passw0rd.')
    
    #Navigate to the page using the menu
    menu('Administration')
    menu('User Management')
    menu('Edit Parties')
  
    @@ie.link(:name,'Edit Current User').click
    @@ie.wait
    @@ie.text_field(:id,'P66_FIRST_NAME').set('Updated')
    @@ie.text_field(:id,'P66_TELEPHONE').set('01234 567800')
    @@ie.button(:value,'Apply Changes').click
    @@ie.wait    
    assert(@@ie.contains_text('Action Processed.'),'Party not updated correctly')
    
    @@ie.link(:name,/Edit SuppAgent1/).click
    @@ie.wait
    @@ie.text_field(:id,'P66_TELEPHONE').set('01234 567809')
    @@ie.button(:value,'Apply Changes').click
    @@ie.wait    
    assert(@@ie.contains_text('Action Processed.'),'Party not updated correctly')
  end
  
  def test_03_edit_supplier
    @@ie.goto(LOGIN)
    #we'll need to login as a MIPADMIN user
    login('advantica','password')
    
    #Navigate to the page using the menu
    menu('Administration')
    menu('User Management')
    menu('Edit Parties')
  
    #edit a supplier, the one created above for ease...
    @@ie.select_list(:id,'P65_PRTY_TYPE').set('Market Participant')
    @@ie.link(:name,/Edit Supplier1 SU1/).click
    #add an address
    @@ie.button(:value,'Add Address').click
    @@ie.text_field(:id,'P69_ADDR_CODE').set('SU1_OFFICE2')
    @@ie.select_list(:id,'P69_ADDR_TYPE').set('OFFICE')
    @@ie.text_field(:id,'P69_ADDR_SUB_BUILDING').set('2')
    @@ie.text_field(:id,'P69_ADDR_BUILDING').set('Building 2')
    @@ie.text_field(:id,'P69_ADDR_STREET').set('Supplier Street')
    @@ie.text_field(:id,'P69_ADDR_CITY').set('Supplierton')
    @@ie.text_field(:id,'P69_ADDR_POSTCODE').set('LE11 3GR')
    @@ie.button(:value,'Save').click
    @@ie.wait    
    @@ie.button(:value,'Apply Changes').click
    @@ie.wait    
    assert(@@ie.contains_text('Action Processed.'),'Party not updated correctly')
  end
end