#---
#This unit test checks the bases screen.
#---
class Test_05_base_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 base record
  #
  def test_01_bases_screen_appears
    @@ie.goto(BASE)
    #we'll need to login
    login(MIPADMIN, MIPADMIN_PWD)
    assert(@@ie.contains_text('Bases'),'The bases screen did not appear')
    assert(@@ie.contains_text('Base Description'),'The base description column did not appear')
    assert(@@ie.contains_text('Depth'),'The Depth column did not appear')
    assert(@@ie.contains_text('Dim A'),'The Dim A column did not appear')
    assert(@@ie.contains_text('Dim B'),'The Dim B column did not appear')
    assert(@@ie.contains_text('Dim C'),'The Dim C column did not appear')
    assert(@@ie.contains_text('Dim D'),'The Dim D column did not appear')
    assert(@@ie.contains_text('Dim E'),'The Dim E column did not appear')
    assert(@@ie.contains_text('Dim F'),'The Dim F column did not appear')
    assert(@@ie.contains_text('Dim G'),'The Dim G column did not appear')
    assert(@@ie.contains_text('Dim H'),'The Dim H column did not appear')
    assert(@@ie.contains_text('Dim I'),'The Dim I column did not appear')
    assert(@@ie.contains_text('Drawing Code'),'The drawing code column did not appear')
    assert(@@ie.button(:id, 'create').exists?,'The create button was not available')        
  end
  #
  #Check that the Create/Edit Base form can be accessed using the Create button on the Bases report, 
  #all the required columns appears on the screen along with create and cancel buttons 
  #
  def test_02_create_base_screen_appears
    @@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, 'P51_CODE').exists?,'The base code field is not available')
    assert(@@ie.text_field(:id, 'P51_DESCRIPTION').exists?,'The base description field is not available')
    assert(@@ie.text_field(:id, 'P51_DEPTH').exists?,'The depth field is not available')
    assert(@@ie.text_field(:id, 'P51_DIM_A').exists?,'The Dim A field is not available')
    assert(@@ie.text_field(:id, 'P51_DIM_B').exists?,'The Dim B field is not available')
    assert(@@ie.text_field(:id, 'P51_DIM_C').exists?,'The Dim C field is not available')
    assert(@@ie.text_field(:id, 'P51_DIM_D').exists?,'The Dim D field is not available')
    assert(@@ie.text_field(:id, 'P51_DIM_E').exists?,'The Dim E field is not available')
    assert(@@ie.text_field(:id, 'P51_DIM_F').exists?,'The Dim F field is not available')
    assert(@@ie.text_field(:id, 'P51_DIM_G').exists?,'The Dim G field is not available')
    assert(@@ie.text_field(:id, 'P51_DIM_H').exists?,'The Dim H field is not available')
    assert(@@ie.text_field(:id, 'P51_DIM_I').exists?,'The Dim I field is not available')
    assert(@@ie.select_list(:id, 'P51_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') 
  end
  #~ def test_03_correct_lists_of_values_displayed
    #~ listofhousingtypes= W%[LIFT OFF
    #~ WALK IN
    #~ WALK THOUGH]
    #~ assert_equal(listofhousingtypes,@@ie.select_list(:id, 'P51_HOTY_CODE').getAllContents ,'The expected list of base types was not found')
    #~ listofmanufacturers= W%[ACTARIS,
                                        #~ DRESSER,
                                        #~ QUINSHIELD]
    #~ assert_equal(listofmanufacturers,@@ie.select_list(:id, 'P51_PRTY_ID').getAllContents,'The expected list of manufacturers was not found')
  #~ end
  #
  #Check that the Create/Edit Base form allows data to be inserted to create a new base
  #Check that the new base record appears in the report
  #
  def test_03_create_base
    @@ie.text_field(:id, 'P51_CODE').set('1766BH1')
    @@ie.text_field(:id, 'P51_DESCRIPTION').set('Base for meters')
    @@ie.text_field(:id, 'P51_DEPTH').set('3800')
    @@ie.text_field(:id, 'P51_DIM_A').set('3800')
    @@ie.text_field(:id, 'P51_DIM_B').set('1400')
    @@ie.text_field(:id, 'P51_DIM_C').set('2400')
    @@ie.text_field(:id, 'P51_DIM_D').set('3800')
    @@ie.text_field(:id, 'P51_DIM_E').set('1400')
    @@ie.text_field(:id, 'P51_DIM_F').set('2400')
    @@ie.text_field(:id, 'P51_DIM_G').set('3800')
    @@ie.text_field(:id, 'P51_DIM_H').set('1400')
    @@ie.text_field(:id, 'P51_DIM_I').set('2400')
    @@ie.select_list(:id, 'P51_DRWG_CODE').select('WI')
    @@ie.button(:id, 'create').click
    @@ie.wait
    assert(@@ie.contains_text('Bases'),'The base screen did not appear')
    assert(@@ie.contains_text('1766BH1'),'The new record with base code 1766BH1 did not appear')
    assert(@@ie.contains_text('3800'),'The value 3800 for Depth did not appear')
    assert(@@ie.contains_text('3800'),'The value 3800 for Dim A did not appear')
    assert(@@ie.contains_text('1400'),'The value 1400 for Dim B  did not appear')
    assert(@@ie.contains_text('2400'),'The value 2400 for Dim C  did not appear')
    assert(@@ie.contains_text('3800'),'The value 3800 for Dim D did not appear')
    assert(@@ie.contains_text('1400'),'The value 1400 for Dim E  did not appear')
    assert(@@ie.contains_text('2400'),'The value 2400 for Dim F  did not appear')
    assert(@@ie.contains_text('3800'),'The value 3800 for Dim G did not appear')
    assert(@@ie.contains_text('1400'),'The value 1400 for Dim H  did not appear')
    assert(@@ie.contains_text('2400'),'The value 2400 for Dim I  did not appear')
    assert(@@ie.contains_text('WI'),'The new record with drawing code WI did not appear')
    @@ie.button(:id, 'create').click
    @@ie.wait
    @@ie.text_field(:id, 'P51_CODE').set('1766BH2')
    @@ie.text_field(:id, 'P51_DESCRIPTION').set('Base for regulators')
    @@ie.text_field(:id, 'P51_DEPTH').set('3800')
    @@ie.text_field(:id, 'P51_DIM_A').set('3800')
    @@ie.text_field(:id, 'P51_DIM_B').set('1400')
    @@ie.text_field(:id, 'P51_DIM_C').set('2400')
    @@ie.text_field(:id, 'P51_DIM_D').set('3800')
    @@ie.text_field(:id, 'P51_DIM_E').set('1400')
    @@ie.text_field(:id, 'P51_DIM_F').set('2400')
    @@ie.text_field(:id, 'P51_DIM_G').set('3800')
    @@ie.text_field(:id, 'P51_DIM_H').set('1400')
    @@ie.text_field(:id, 'P51_DIM_I').set('2400')
    @@ie.select_list(:id, 'P51_DRWG_CODE').select('D1')
    @@ie.button(:id, 'create').click
    @@ie.wait
    assert(@@ie.contains_text('Bases'),'The base screen did not appear')
    assert(@@ie.contains_text('1766BH2'),'The new record with base code 1766BH2 did not appear')
    assert(@@ie.contains_text('3800'),'The value 3800 for Depth did not appear')
    assert(@@ie.contains_text('3800'),'The value 3800 for Dim A did not appear')
    assert(@@ie.contains_text('1400'),'The value 1400 for Dim B  did not appear')
    assert(@@ie.contains_text('2400'),'The value 2400 for Dim C  did not appear')
    assert(@@ie.contains_text('3800'),'The value 3800 for Dim D did not appear')
    assert(@@ie.contains_text('1400'),'The value 1400 for Dim E  did not appear')
    assert(@@ie.contains_text('2400'),'The value 2400 for Dim F  did not appear')
    assert(@@ie.contains_text('3800'),'The value 3800 for Dim G did not appear')
    assert(@@ie.contains_text('1400'),'The value 1400 for Dim H  did not appear')
    assert(@@ie.contains_text('2400'),'The value 2400 for Dim I  did not appear')
    assert(@@ie.contains_text('D1'),'The new record with drawing code D1 did not appear')
  end
  #
  #Check that the code 1765BH1  links to the Create/Edit Base form and the form appears with the correct data 
  #in the fields. Check that the base description can be updated and the updated record appears in the Base report
  #
  def test_04_update_base
    @@ie.link(:text, '1766BH1').click
    @@ie.wait
    assert(@@ie.contains_text('Create/Edit Base'),'The Create/Edit Base screen did not appear')
    assert(@@ie.contains_text('1766BH1'), 'The base code field did not contain value 1766BH1')
    assert(@@ie.text_field(:id, 'P51_DESCRIPTION').verify_contains('Base for meters'), 'The description is not base for meters')
    assert(@@ie.text_field(:id, 'P51_DEPTH').verify_contains('3800'), 'Depth is not 3800')
    assert(@@ie.text_field(:id, 'P51_DIM_A').verify_contains('3800'), 'DIM A is not 3800')
    assert(@@ie.text_field(:id, 'P51_DIM_B').verify_contains('1400'), 'DIM B is not 1400')
    assert(@@ie.text_field(:id, 'P51_DIM_C').verify_contains('2400'), 'DIM C is not 2400')
    assert(@@ie.text_field(:id, 'P51_DIM_D').verify_contains('3800'), 'DIM D is not 3800')
    assert(@@ie.text_field(:id, 'P51_DIM_E').verify_contains('1400'), 'DIM E is not 1400')
    assert(@@ie.text_field(:id, 'P51_DIM_F').verify_contains('2400'), 'DIM F is not 2400')
    assert(@@ie.text_field(:id, 'P51_DIM_G').verify_contains('3800'), 'DIM G is not 3800')
    assert(@@ie.text_field(:id, 'P51_DIM_H').verify_contains('1400'), 'DIM H is not 1400')
    assert(@@ie.text_field(:id, 'P51_DIM_I').verify_contains('2400'), 'DIM I is not 2400')
    assert(@@ie.select_list(:id, 'P51_DRWG_CODE').selected?('WI'), 'Drawing code is not WI')
    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, 'P51_DESCRIPTION').set('Base for slamshut valves')
    @@ie.button(:id, 'apply_changes').click
    @@ie.wait
    assert(@@ie.contains_text('Bases'),'The base screen did not appear')
    assert(@@ie.contains_text('1766BH1'),'The new record with base code 1766BH1 did not appear')
    assert(@@ie.contains_text('3800'),'The value 3800 for Depth did not appear')
    assert(@@ie.contains_text('3800'),'The value 3800 for Dim A did not appear')
    assert(@@ie.contains_text('1400'),'The value 1400 for Dim B  did not appear')
    assert(@@ie.contains_text('2400'),'The value 2400 for Dim C  did not appear')
    assert(@@ie.contains_text('3800'),'The value 3800 for Dim D did not appear')
    assert(@@ie.contains_text('1400'),'The value 1400 for Dim E  did not appear')
    assert(@@ie.contains_text('2400'),'The value 2400 for Dim F  did not appear')
    assert(@@ie.contains_text('3800'),'The value 3800 for Dim G did not appear')
    assert(@@ie.contains_text('1400'),'The value 1400 for Dim H  did not appear')
    assert(@@ie.contains_text('2400'),'The value 2400 for Dim I  did not appear')
    assert(@@ie.contains_text('WI'),'The new record with drawing code WI did not appear')
  end
  #
  #Check that the base 1765BH2 can be deleted and that the record is no longer displayed in the report
  # can't test delete due to javascript popup
#  def test_05_delete_base
#    @@ie.link(:text, '1766BH2').click
#    @@ie.wait
#    assert(@@ie.contains_text('Create/Edit Base'),'The Create/Edit Base screen did not appear')
#    assert(@@ie.text_field(:id, 'P51_CODE').verify_contains('1766BH2'), 'The base code field did not contain value 3811H')
#    assert(@@ie.text_field(:id, 'P51_DESCRIPTION').verify_contains('Base for regulators'), 'The description is not base for meters')
#    assert(@@ie.text_field(:id, 'P51_DEPTH').verify_contains('3800'), 'Depth is not 3800')
#    assert(@@ie.text_field(:id, 'P51_DIM_A').verify_contains('3800'), 'DIM A is not 3800')
#    assert(@@ie.text_field(:id, 'P51_DIM_B').verify_contains('1400'), 'DIM B is not 1400')
#    assert(@@ie.text_field(:id, 'P51_DIM_C').verify_contains('2400'), 'DIM C is not 2400')
#    assert(@@ie.text_field(:id, 'P51_DIM_D').verify_contains('3800'), 'DIM D is not 3800')
#    assert(@@ie.text_field(:id, 'P51_DIM_E').verify_contains('1400'), 'DIM E is not 1400')
#    assert(@@ie.text_field(:id, 'P51_DIM_F').verify_contains('2400'), 'DIM F is not 2400')
#    assert(@@ie.text_field(:id, 'P51_DIM_G').verify_contains('3800'), 'DIM G is not 3800')
#    assert(@@ie.text_field(:id, 'P51_DIM_H').verify_contains('1400'), 'DIM H is not 1400')
#    assert(@@ie.text_field(:id, 'P51_DIM_I').verify_contains('2400'), 'DIM I is not 2400')
#    assert(@@ie.select_list(:id, 'P51_DRWG_CODE').selected?('D1'), 'Drawing code is not WI')
#    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('1765BH2'),'The base code field did contain value 1765BH2')
#  end
  #
  #~ Check that the base code cannot be updated 
  #
  #~ def test_06_update_base_code
    #~ @@ie.link(:text, '1765BH1').click
    #~ @@ie.wait
    #~ assert(@@ie.contains_text('Create/Edit Base'),'The Create/Edit Base screen did not appear')
    #~ assert(@@ie.text_field(:id, 'P51_CODE').verify_contains('1765BH1'), 'The base code field did not contain value 1765BH1')
    #~ assert(@@ie.text_field(:id, 'P51_DESCRIPTION').verify_contains('Base for slamshut valves'), 'The description is not base for slamshut valves')
    #~ assert(@@ie.text_field(:id, 'P51_DIM_A').verify_contains('3800'), 'DIM A is not 3800')
    #~ assert(@@ie.text_field(:id, 'P51_DIM_B').verify_contains('1400'), 'DIM B is not 1400')
    #~ assert(@@ie.text_field(:id, 'P51_DIM_C').verify_contains('2400'), 'DIM C is not 2400')
    #~ assert(@@ie.text_field(:id, 'P51_DIM_D').verify_contains('3800'), 'DIM D is not 3800')
    #~ assert(@@ie.text_field(:id, 'P51_DIM_E').verify_contains('1400'), 'DIM E is not 1400')
    #~ assert(@@ie.text_field(:id, 'P51_DIM_F').verify_contains('2400'), 'DIM F is not 2400')
    #~ assert(@@ie.text_field(:id, 'P51_DIM_G').verify_contains('3800'), 'DIM G is not 3800')
    #~ assert(@@ie.text_field(:id, 'P51_DIM_H').verify_contains('1400'), 'DIM H is not 1400')
    #~ assert(@@ie.text_field(:id, 'P51_DIM_I').verify_contains('2400'), 'DIM I is not 2400')
    #~ assert(@@ie.select_list(:id, 'P51_DRWG_CODE').selected?('WI'), 'Drawing code is not WI')
    #~ 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, 'P51_CODE').set("2245A")
    #~ @@ie.button(:id, 'apply_changes').click
    #~ @@ie.wait
    #~ assert(@@ie.contains_text('Base'),'The base screen did not appear')
    #~ assert(@@ie.contains_text('2245A'),'The record with base code 2245A did not appear')
  #~ end
  #
  #Check that a base record with child records cannot be deleted
  #
  #~ def test_07_delete_base_child
    #~ assert(@@ie.contains_text('Create/Edit Base'),'The Create/Edit Base screen did not appear')
    #~ assert(@@ie.text_field(:id, 'P51_CODE').verify_contains('1765BH2'), 'The base code field did not contain value 3811H')
    #~ assert(@@ie.text_field(:id, 'P51_DESCRIPTION').verify_contains('Base for regulators'), 'The description is not base for meters')
    #~ assert(@@ie.text_field(:id, 'P51_DIM_A').verify_contains('3800'), 'DIM A is not 3800')
    #~ assert(@@ie.text_field(:id, 'P51_DIM_B').verify_contains('1400'), 'DIM B is not 1400')
    #~ assert(@@ie.text_field(:id, 'P51_DIM_C').verify_contains('2400'), 'DIM C is not 2400')
    #~ assert(@@ie.text_field(:id, 'P51_DIM_D').verify_contains('3800'), 'DIM D is not 3800')
    #~ assert(@@ie.text_field(:id, 'P51_DIM_E').verify_contains('1400'), 'DIM E is not 1400')
    #~ assert(@@ie.text_field(:id, 'P51_DIM_F').verify_contains('2400'), 'DIM F is not 2400')
    #~ assert(@@ie.text_field(:id, 'P51_DIM_G').verify_contains('3800'), 'DIM G is not 3800')
    #~ assert(@@ie.text_field(:id, 'P51_DIM_H').verify_contains('1400'), 'DIM H is not 1400')
    #~ assert(@@ie.text_field(:id, 'P51_DIM_I').verify_contains('2400'), 'DIM I is not 2400')
    #~ assert(@@ie.select_list(:id, 'P51_DRWG_CODE').selected?('D1'), 'Drawing code is not WI')
    #~ 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 base code field did not contain value 1765BH2')
  #~ end
  #
  #Check that a duplicate base 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, 'P51_CODE').exists?,'The base code field is not available')
    assert(@@ie.text_field(:id, 'P51_DESCRIPTION').exists?,'The base description field is not available')
    assert(@@ie.text_field(:id, 'P51_DIM_A').exists?,'The Dim A field is not available')
    assert(@@ie.text_field(:id, 'P51_DIM_B').exists?,'The Dim B field is not available')
    assert(@@ie.text_field(:id, 'P51_DIM_C').exists?,'The Dim C field is not available')
    assert(@@ie.text_field(:id, 'P51_DIM_D').exists?,'The Dim D field is not available')
    assert(@@ie.text_field(:id, 'P51_DIM_E').exists?,'The Dim E field is not available')
    assert(@@ie.text_field(:id, 'P51_DIM_F').exists?,'The Dim F field is not available')
    assert(@@ie.text_field(:id, 'P51_DIM_G').exists?,'The Dim G field is not available')
    assert(@@ie.text_field(:id, 'P51_DIM_H').exists?,'The Dim H field is not available')
    assert(@@ie.text_field(:id, 'P51_DIM_I').exists?,'The Dim I field is not available')
    assert(@@ie.select_list(:id, 'P51_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, 'P51_CODE').set('1766BH1')
    @@ie.text_field(:id, 'P51_DESCRIPTION').set('Base for meters')
    @@ie.text_field(:id, 'P51_DIM_A').set('3800')
    @@ie.text_field(:id, 'P51_DIM_B').set('1400')
    @@ie.text_field(:id, 'P51_DIM_C').set('2400')
    @@ie.text_field(:id, 'P51_DIM_D').set('3800')
    @@ie.text_field(:id, 'P51_DIM_E').set('1400')
    @@ie.text_field(:id, 'P51_DIM_F').set('2400')
    @@ie.text_field(:id, 'P51_DIM_G').set('3800')
    @@ie.text_field(:id, 'P51_DIM_H').set('1400')
    @@ie.text_field(:id, 'P51_DIM_I').set('2400')
    @@ie.select_list(:id, 'P51_DRWG_CODE').select('WI')
    @@ie.button(:id, 'create').click
    @@ie.wait
    assert_nil(@@ie.contains_text('1765BH1'),'The new record with base 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')
    assert(@@ie.contains_text('Attempting to create a duplicate Bases entry'),'Did not find expected error message')
    sleep 3
    @@ie.link(:text, 'OK').click
    @@ie.wait
  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








