#---
#This unit test checks the addon screen.
#---
class Test_06_addon_screen < Test::Unit::TestCase
  #
  #Test we can logon to the system using the webmip administrator user’s login credentials and check that 
  #all the columns required for the report appears with the button to create a new add-on record
  #
  def test_01_addon_screen_appears
    @@ie.goto(ADDON)
    #we'll need to login
    login(DEFAULT, DEFAULT_PWD)
    assert(@@ie.contains_text('Additional Items'),'The additional items screen did not appear')
    assert(@@ie.contains_text('Code'),'The additional item code column did not appear')
    assert(@@ie.contains_text('Description'),'The additional item description column did not appear')
    assert(@@ie.contains_text('Lead Time'),'The lead time column did not appear')
    assert(@@ie.button(:id, 'create').exists?,'The create button was not available')        
  end
  #
  #Check that the Create/Edit Additional Item form can be accessed using the Create button on the report, 
  #all the required data entry fields appears on the screen along with create and cancel buttons 
  #
   def test_02_create_addon_screen_appears
     @@ie.button(:id, 'create').click
     @@ie.wait
     assert(@@ie.contains_text('Create/Edit Additional Item'),'The create/edit additional item screen did not appear')
     assert(@@ie.text_field(:id, 'P24_CODE').exists?,'The code field is not available')
     assert(@@ie.text_field(:id, 'P24_DESCRIPTION').exists?,'The description field is not available')
     assert(@@ie.text_field(:id, 'P24_LEAD_TIME').exists?,'The lead time field is not available')
     assert(@@ie.button(:id, 'create').exists?,'The create button was not available') 
     assert(@@ie.button(:id, 'cancel').exists?,'The cancel button was not available') 
   end
  #~ def test_03_correct_lists_of_values_displayed
    #~ listofhousingtypes= W%[LIFT OFF
    #~ WALK IN
    #~ WALK THOUGH]
    #~ assert_equal(listofhousingtypes,@@ie.select_list(:id, 'P19_HOTY_CODE').getAllContents ,'The expected list of additional item types was not found')
    #~ listofmanufacturers= W%[ACTARIS,
                                        #~ DRESSER,
                                        #~ QUINSHIELD]
    #~ assert_equal(listofmanufacturers,@@ie.select_list(:id, 'P19_PRTY_ID').getAllContents,'The expected list of manufacturers was not found')
  #~ end
  #
  #Check that the Create/Edit Additional Item form allows data to be inserted to create a new add-on
  #Check that the new add-on record appears in the report
  #
   def test_03_create_addon
     @@ie.text_field(:id, 'P24_CODE').set('ADDON1')
     @@ie.text_field(:id, 'P24_DESCRIPTION').set('Add-on for meter M1')
     @@ie.text_field(:id, 'P24_LEAD_TIME').set('20')
     @@ie.button(:id, 'create').click
     @@ie.wait
     assert(@@ie.contains_text('Additional Items'),'The additional item screen did not appear')
     assert(@@ie.contains_text('ADDON1'),'The new record with additional item code 1765BH1 did not appear')
     assert(@@ie.contains_text('Add-on for meter M1'),'The description for additional item did not appear')
     assert(@@ie.contains_text('20'),'The value 20 for lead time did not appear')
     @@ie.button(:id, 'create').click
     @@ie.wait
     @@ie.text_field(:id, 'P24_CODE').set('ADDON2')
     @@ie.text_field(:id, 'P24_DESCRIPTION').set('Add-on for meter M2')
     @@ie.text_field(:id, 'P24_LEAD_TIME').set('20')
     @@ie.button(:id, 'create').click
     @@ie.wait
     assert(@@ie.contains_text('Additional Items'),'The additional item screen did not appear')
     assert(@@ie.contains_text('ADDON1'),'The new record with additional item code 1765BH2 did not appear')
     assert(@@ie.contains_text('Add-on for meter M2'),'The description for additional item did not appear')
     assert(@@ie.contains_text('20'),'The value 20 for lead time did not appear')
   end
  #
  #Check that the code ADDON2  links to the Create/Edit Additional Item form and the form appears with the correct data 
  #in the fields. Check that the description can be updated and the updated record appears in the Additional Items report.
  #
  #~ def test_04_update_addon
    #~ @@ie.link(:text, 'ADDON2').click
    #~ @@ie.wait
    #~ assert(@@ie.contains_text('Create/Edit Additional Item'),'The Create/Edit Additional Item screen did not appear')
    #~ assert(@@ie.text_field(:id, 'P24_CODE').verify_contains('ADDON2'), 'The additional item code field did not contain value ADDON2')
    #~ assert(@@ie.text_field(:id, 'P24_DESCRIPTION').verify_contains('Add-on for meter M2'), 'The description is not Add-on for meter M2')
    #~ assert(@@ie.text_field(:id, 'P24_LEAD_TIME').verify_contains('20'), 'Lead time is not 20')
    #~ assert(@@ie.button(:id, 'cancel').exists?,'The cancel button was not available') 
    #~ assert(@@ie.button(:id, 'delete').exists?,'The delete button was not available') 
    #~ assert(@@ie.button(:id, 'apply_changes').exists?,'The Apply Changes button was not available') 
    #~ @@ie.text_field(:id, 'P24_DESCRIPTION').set('Add-on for meter M3')
    #~ @@ie.button(:id, 'apply_changes').click
    #~ @@ie.wait
    #~ assert(@@ie.contains_text('Additional Items'),'The additional item screen did not appear')
    #~ assert(@@ie.contains_text('ADDON2'),'The new record with additional item code 1765BH1 did not appear')
    #~ assert(@@ie.contains_text('Add-on for meter M3'),'The updated description Base for slamshut valves did not appear')
    #~ assert(@@ie.contains_text('20'),'The lead time 20 for the add-on did not appear')
  #~ end
  #
  #Check that the LOGGER record can be deleted and that the record is no longer displayed in the report
  #
  #Can't test delete due to the javascript pop-up
#  def test_05_delete_addon
#    @@ie.link(:text, 'LOGGER').click
#    @@ie.wait
#    assert(@@ie.contains_text('Create/Edit Additional Item'),'The Create/Edit Additional Item screen did not appear')
#    assert(@@ie.text_field(:id, 'P24_CODE').verify_contains('LOGGER'), 'The additional item code field did not contain value LOGGER')
#    assert(@@ie.text_field(:id, 'P24_DESCRIPTION').verify_contains('Data Logger'), 'The description is not logger')
#    assert(@@ie.text_field(:id, 'P24_LEAD_TIME').verify_contains('15'), 'Lead time is not 15')
#    assert(@@ie.button(:id, 'cancel').exists?,'The cancel button was not available') 
#    assert(@@ie.button(:id, 'delete').exists?,'The delete button was not available') 
#    assert(@@ie.button(:id, 'apply_changes').exists?,'The Apply Changes button was not available') 
#    startClicker("OK", 1)
#    @@ie.button(:id, 'delete').click
#
#    #@@ie.wait
#    assert_nil(@@ie.contains_text('LOGGER'),'The additional item record with code LOGGER appears on screen')
#  end
  #
  #~ Check that the additional item code cannot be updated 
  #
  def test_06_update_addon_code
    @@ie.link(:text, 'LOGGER').click
    @@ie.wait
    assert(@@ie.contains_text('Create/Edit Additional Item '),'The Create/Edit Additional Item screen did not appear')
    assert(@@ie.contains_text('LOGGER'), 'The additional item code field did not contain value ADDON2')
    assert(@@ie.text_field(:id, 'P24_DESCRIPTION').verify_contains('Data Logger'), 'The description is not Add-on for meter M3')
    assert(@@ie.text_field(:id, 'P24_LEAD_TIME').verify_contains('15'), 'Lead time is not 15')
    assert(@@ie.button(:id, 'cancel').exists?,'The cancel button was not available') 
    assert(@@ie.button(:id, 'delete').exists?,'The delete button was not available') 
    assert(@@ie.button(:id, 'apply_changes').exists?,'The Apply Changes button was not available') 
    assert(@@ie.hidden(:id, 'P24_CODE').exists?,'The CODE field was not hidden') 
    assert(@@ie.contains_text('Create/Edit Additional Item'),'The additional item screen did not appear')
  end
  #
  #Check that an additional item record with child records cannot be deleted
  #
#  def test_07_delete_addon_child
#    assert(@@ie.contains_text('Create/Edit Additional Item'),'The Create/Edit Additional Item screen did not appear')
#    assert(@@ie.text_field(:id, 'P24_CODE').verify_contains('1765BH2'), 'The additional item code field did not contain value 3811H')
#    assert(@@ie.text_field(:id, 'P24_DESCRIPTION').verify_contains('Base for regulators'), 'The description is not additional item for meters')
#    assert(@@ie.text_field(:id, 'P24_LEAD_TIME').verify_contains('20'), 'Lead time is not 20')
#    assert(@@ie.button(:id, 'cancel').exists?,'The cancel button was not available') 
#    assert(@@ie.button(:id, 'delete').exists?,'The delete button was not available') 
#    assert(@@ie.button(:id, 'apply_changes').exists?,'The Apply Changes button was not available') 
#    @@ie.button(:id, 'delete').click
#    @@ie.wait
#    assert(@@ie.contains_text('1765BH2'),'The additional item code field did not contain value 1765BH2')
#  end
  #
  #Check that a duplicate additional item record cannot be recorded
  #
  #~ def test_08_create_duplicate_base
    #~ assert(@@ie.button(:id, 'create').exists?,'The create button was not available') 
    #~ @@ie.button(:id, 'create').click
    #~ @@ie.wait
    #~ assert(@@ie.contains_text('Create/Edit Base'),'The Create/Edit Base screen did not appear')
    #~ assert(@@ie.text_field(:id, 'P19_CODE').exists?,'The additional item code field is not available')
    #~ assert(@@ie.text_field(:id, 'P19_DESCRIPTION').exists?,'The additional item description field is not available')
    #~ assert(@@ie.text_field(:id, 'P19_DIM_A').exists?,'The Dim A field is not available')
    #~ assert(@@ie.text_field(:id, 'P19_DIM_B').exists?,'The Dim B field is not available')
    #~ assert(@@ie.text_field(:id, 'P19_DIM_C').exists?,'The Dim C field is not available')
    #~ assert(@@ie.text_field(:id, 'P19_DIM_D').exists?,'The Dim D field is not available')
    #~ assert(@@ie.text_field(:id, 'P19_DIM_E').exists?,'The Dim E field is not available')
    #~ assert(@@ie.text_field(:id, 'P19_DIM_F').exists?,'The Dim F field is not available')
    #~ assert(@@ie.text_field(:id, 'P19_DIM_G').exists?,'The Dim G field is not available')
    #~ assert(@@ie.text_field(:id, 'P19_DIM_H').exists?,'The Dim H field is not available')
    #~ assert(@@ie.text_field(:id, 'P19_DIM_I').exists?,'The Dim I field is not available')
    #~ assert(@@ie.select_list(:id, 'P19_DRWG_CODE').exists?,'The drawing code field is not available')
    #~ assert(@@ie.button(:id, 'create').exists?,'The create button was not available') 
    #~ assert(@@ie.button(:id, 'cancel').exists?,'The cancel button was not available') 
    #~ @@ie.text_field(:id, 'P19_CODE').set('1765BH1')
    #~ @@ie.text_field(:id, 'P19_DESCRIPTION').set('Base for meters')
    #~ @@ie.text_field(:id, 'P19_DIM_A').set('3800')
    #~ @@ie.text_field(:id, 'P19_DIM_B').set('1400')
    #~ @@ie.text_field(:id, 'P19_DIM_C').set('2400')
    #~ @@ie.text_field(:id, 'P19_DIM_D').set('3800')
    #~ @@ie.text_field(:id, 'P19_DIM_E').set('1400')
    #~ @@ie.text_field(:id, 'P19_DIM_F').set('2400')
    #~ @@ie.text_field(:id, 'P19_DIM_G').set('3800')
    #~ @@ie.text_field(:id, 'P19_DIM_H').set('1400')
    #~ @@ie.text_field(:id, 'P19_DIM_I').set('2400')
    #~ @@ie.select_list(:id, 'P19_DRWG_CODE').select('WI')
    #~ @@ie.button(:id, 'create').click
    #~ @@ie.wait
    #~ assert_nil(@@ie.contains_text('Bases'),'The additional item screen did appear')
    #~ assert_nil(@@ie.contains_text('1765BH1'),'The new record with additional item code 1765BH1 did appear')
    #~ assert_nil(@@ie.contains_text('Base for meters'),'The description Base for meters did appear')
    #~ assert_nil(@@ie.contains_text('3800'),'The value 3800 for Dim A did appear')
    #~ assert_nil(@@ie.contains_text('1400'),'The value 1400 for Dim B  did appear')
    #~ assert_nil(@@ie.contains_text('2400'),'The value 2400 for Dim C  did appear')
    #~ assert_nil(@@ie.contains_text('3800'),'The value 3800 for Dim D did appear')
    #~ assert_nil(@@ie.contains_text('1400'),'The value 1400 for Dim E  did appear')
    #~ assert_nil(@@ie.contains_text('2400'),'The value 2400 for Dim F  did appear')
    #~ assert_nil(@@ie.contains_text('3800'),'The value 3800 for Dim G did appear')
    #~ assert_nil(@@ie.contains_text('1400'),'The value 1400 for Dim H  did appear')
    #~ assert_nil(@@ie.contains_text('2400'),'The value 2400 for Dim I  did appear')
    #~ assert_nil(@@ie.contains_text('WI'),'The new record with drawing code WI did appear')
    #~ assert(@@ie.contains_text('Error'),'An error was not generated')

  #~ end
  def test_50_logout
    menu('Logout')
    assert(@@ie.button(:value, 'Login').exists?,'The Login button was not available')        
    @@ie.button(:value, 'Login').click        
    @@ie.wait
  end 
end








