# encoding: utf-8

require_relative 'admin_page.rb'

class ItemTypes < AdminPage
  def visit
    @browser.goto intranet(:item_types)
    self
  end

  def show_all
    @browser.select_list(:name => "table_item_type_length").select_value("-1")
    self
  end

  def create(code, desc)
    @browser.execute_script("document.getElementById('newitemtype').click()")
    Watir::Wait.until {
      @browser.form(:id => "itemtypeentry").text_field(:id => "itemtype").present?
    }

    form = @browser.form(:id => "itemtypeentry")
    form.text_field(:id => "itemtype").set code
    form.text_field(:id => "description").set desc
    form.submit
    self
  end

  def delete(code)
    item_type_table.rows.each do |row|
      if row.text.include?(code)
        row.link(:href => /op=delete_confirm/).click
        @browser.input(:value => "Delete this Item Type").click
        break
      end
    end
  end

  def exists(code, desc)
    text = item_type_table.text
    text.should include(code)
    text.should include(desc)
    self
  end

  def item_type_table
    table =  @browser.table(:id => "table_item_type")
    table.wait_until_present
    table
  end

end
# encoding: utf-8

require_relative 'admin_page.rb'

class ItemTypes < AdminPage
  def visit
    @browser.goto intranet(:item_types)
    self
  end

  def show_all
    @browser.select_list(:name => "table_item_type_length").select_value("-1")
    self
  end

  def create(code, desc)
    @browser.execute_script("document.getElementById('newitemtype').click()")
    Watir::Wait.until(BROWSER_WAIT_TIMEOUT) {
      @browser.h3(:text => "Add item type").present?
    }

    form = @browser.form(:id => "itemtypeentry")
    form.text_field(:id => "itemtype").set code
    form.text_field(:id => "description").set desc
    form.submit
    self
  end

  def delete(code)
    item_type_table.rows.each do |row|
      if row.text.include?(code)
        row.link(:href => /op=delete_confirm/).click
        @browser.input(:value => "Delete this Item Type").click
        break
      end
    end
  end

  def exists(code, desc)
    text = item_type_table.text
    text.should include(code)
    text.should include(desc)
    self
  end

  def item_type_table
    table =  @browser.table(:id => "table_item_type")
    table.wait_until_present
    table
  end

end
--- 
+++ 
@@ -15,8 +15,8 @@
 
   def create(code, desc)
     @browser.execute_script("document.getElementById('newitemtype').click()")
-    Watir::Wait.until(BROWSER_WAIT_TIMEOUT) {
-      @browser.h3(:text => "Add item type").present?
+    Watir::Wait.until {
+      @browser.form(:id => "itemtypeentry").text_field(:id => "itemtype").present?
     }
 
     form = @browser.form(:id => "itemtypeentry")
Add wait for what we're actually waiting for
