<commit_before>require File.dirname(__FILE__) + '/../spec_helper'

describe Widget do  
  describe 'default methods for all widgets' do
    it "should include a default #render_form_object_read_only" do
      Widget.render_form_object_read_only(1,'value',{}).should == 
        "<span id=\"record_1\">value</span>"
    end
    it "should include #humanize_value" do
      Widget.humanize_value('value').should == 'value'
    end
    it "should include #humanize_value that works on enumerations defined with hashes" do
      Widget.humanize_value('y',:constraints => {'enumeration' => [{'y' => 'Yes'},{'n'=>'No'}]}).should == 'Yes'
    end
    it "should include #humanize_value that works on enumerations defined in rails array style" do
      Widget.humanize_value('CAN',:constraints => {'enumeration' => [	[ "-" , nil ],[ "US" , "US" ],	[ "Canada" , "CAN" ]]}).should == 'Canada'
    end
    it "should include #humanize_value that works on enumerations when value is nil" do
      Widget.humanize_value(nil,:constraints => {'enumeration' => [{'y' => 'Yes'},{'n'=>'No'}]}).should == nil
    end
    it "should include #humanize_value that works on sets defined with hashes" do
      Widget.humanize_value('1',:constraints => {'set' => [{'1' => 'This'},{'2'=>'That'}]}).should == 'This'
      Widget.humanize_value('2,1',:constraints => {'set' => [{'1' => 'This'},{'2'=>'That'}]}).should == 'That, This'
    end
    it "should include #humanize_value that works on sets defined in rails array style" do
      Widget.humanize_value('CAN',:constraints => {'set' => [	[ "-" , nil ],[ "US" , "US" ],	[ "Canada" , "CAN" ]]}).should == 'Canada'
      Widget.humanize_value('CAN,US',:constraints => {'set' => [	[ "-" , nil ],[ "US" , "US" ],	[ "Canada" , "CAN" ]]}).should == 'Canada, US'
    end
    it "should include #humanize_value that works on sets when value is nil" do
      Widget.humanize_value(nil,:constraints => {'set' => [	[ "-" , nil ],[ "US" , "US" ],	[ "Canada" , "CAN" ]]}).should == nil
    end
  end
  
  describe TextFieldWidget do
    it "should render an html input text with a label" do
      TextFieldWidget.render_form_object(1,'value',{}).should == 
        "<input id=\"record_1\" name=\"record[1]\" type=\"text\" value=\"value\" />"
    end
    it "should render an html input text with a size parameter" do
      TextFieldWidget.render_form_object(1,'value',{:params=>'3'}).should == 
        "<input class=\"textfield_3\" id=\"record_1\" name=\"record[1]\" size=\"3\" type=\"text\" value=\"value\" />"
    end
    it "should render value as text with a read_only parameter" do
      TextFieldWidget.render_form_object_read_only(1,'value',{}).should == 
        "<span id=\"record_1\">value</span>"
    end
  end

  describe TextAreaWidget do
    it "should render an html text area with a label" do
      TextAreaWidget.render_form_object(1,'value',{}).should == 
        "<textarea id=\"record_1\" name=\"record[1]\">value</textarea>"
    end
    it "should render an html input text with rows & columns parameters" do
      TextAreaWidget.render_form_object(1,'value',{:params=>'10,20'}).should == 
        "<textarea cols=\"20\" id=\"record_1\" name=\"record[1]\" rows=\"10\">value</textarea>"
    end
    it "should render value as text with a read_only parameter" do
      TextAreaWidget.render_form_object_read_only(1,'value',{}).should == 
        "<span id=\"record_1\">value</span>"
    end
  end

  describe DateWidget do
    it "should render three html input texts and the instructions" do
      DateWidget.render_form_object(1,"2004-10-23",{}).should == 
      "<input type=\"text\"  size=2 class=\"textfield_2\" name=\"record[1][month]\" id=\"record_1_month\" value=\"10\" maxlength=\"2\"/> /\n<input type=\"text\"  size=2 class=\"textfield_2\" name=\"record[1][day]\" id=\"record_1_day\" value=\"23\" maxlength=\"2\"/> /\n<input type=\"text\" size=4 class=\"textfield_4\" name=\"record[1][year]\" id=\"record_1_year\" value=\"2004\" maxlength=\"4\"/> <span class=\"instructions\">(MM/DD/YYYY)</span>\n" 
    end
    it "should render date value as text with a read_only parameter" do
      DateWidget.render_form_object_read_only(1,"2004-10-23",{}).should == 
        "<span id=\"record_1\">10/23/2004</span>"
    end
  end
  
  describe TimeWidget do
    it "should render two html input texts plus a select for am/pm" do
      TimeWidget.render_form_object(1,"3:22",{}).should == 
        "      <input type=\"text\" size=2 class=\"textfield_2\" name=\"record[1][hours]\" id=\"record_1_hours\" value=\"3\" maxlength=\"2\"/>:\n      <input type=\"text\" class=\"left_margin_neg_5 textfield_2\" size=2 name=\"record[1][minutes]\" id=\"record_1_minutes\" value=\"22\" maxlength=\"2\"/>\n      <select name=\"record[1][am_pm]\" id=\"record_1_am_pm\">\n      \t<option value=\"am\" selected=\"selected\">AM</option>\n<option value=\"pm\">PM</option>\n\t  </select>\n"
    end
    it "should render time value as text with a read_only parameter" do
      TimeWidget.render_form_object_read_only(1,"3:22",{}).should == 
        "<span id=\"record_1\">3:22 am</span>"
    end
    it "should render low min time values with a preceeding 0 text if read_only" do
      TimeWidget.render_form_object_read_only(1,"13:02",{}).should == 
        "<span id=\"record_1\">1:02 pm</span>"
    end
  end

  describe TimeIntervalWidget do
    it "should render two html input texts plus a select for am/pm" do
      TimeIntervalWidget.render_form_object(1,"500",{}).should == 
        "      <input type=\"text\" size=2 class=\"textfield_2\" name=\"record[1][hours]\" id=\"record_1_hours\" value=\"8\" /> hours\n      <input type=\"text\" size=2 class=\"textfield_2\" name=\"record[1][minutes]\" id=\"record_1_minutes\" value=\"20\" /> minutes\n"
    end
    it "should render interval value as text if read_only" do
      TimeIntervalWidget.render_form_object_read_only(1,"500",{}).should == 
        "<span id=\"record_1\">8 hours, 20 minutes</span>"
    end
  end
  
  describe FactorTextFieldsWidget do
    it "should render two html input texts and lables from params" do
      FactorTextFieldsWidget.render_form_object(1,"500",{:params=>"5,FirstLabel,SecondLabel"}).should == 
        "<input type=\"text\" size=2 name=\"record[1][first_box]\" id=\"record_1_first_box\" value=\"100\" /> FirstLabel\n<input type=\"text\" size=2 name=\"record[1][second_box]\" id=\"record_1_second_box\" value=\"0\" /> SecondLabel\n<input type=\"hidden\" name=\"record[1][factor]\"  id=\"record_1_factor\"/ value=\"5\">"
    end
    it "should render factor value as text if read_only" do<commit_msg>fixed specs for date and time widgets re javascript additions<commit_after>require File.dirname(__FILE__) + '/../spec_helper'

describe Widget do  
  describe 'default methods for all widgets' do
    it "should include a default #render_form_object_read_only" do
      Widget.render_form_object_read_only(1,'value',{}).should == 
        "<span id=\"record_1\">value</span>"
    end
    it "should include #humanize_value" do
      Widget.humanize_value('value').should == 'value'
    end
    it "should include #humanize_value that works on enumerations defined with hashes" do
      Widget.humanize_value('y',:constraints => {'enumeration' => [{'y' => 'Yes'},{'n'=>'No'}]}).should == 'Yes'
    end
    it "should include #humanize_value that works on enumerations defined in rails array style" do
      Widget.humanize_value('CAN',:constraints => {'enumeration' => [	[ "-" , nil ],[ "US" , "US" ],	[ "Canada" , "CAN" ]]}).should == 'Canada'
    end
    it "should include #humanize_value that works on enumerations when value is nil" do
      Widget.humanize_value(nil,:constraints => {'enumeration' => [{'y' => 'Yes'},{'n'=>'No'}]}).should == nil
    end
    it "should include #humanize_value that works on sets defined with hashes" do
      Widget.humanize_value('1',:constraints => {'set' => [{'1' => 'This'},{'2'=>'That'}]}).should == 'This'
      Widget.humanize_value('2,1',:constraints => {'set' => [{'1' => 'This'},{'2'=>'That'}]}).should == 'That, This'
    end
    it "should include #humanize_value that works on sets defined in rails array style" do
      Widget.humanize_value('CAN',:constraints => {'set' => [	[ "-" , nil ],[ "US" , "US" ],	[ "Canada" , "CAN" ]]}).should == 'Canada'
      Widget.humanize_value('CAN,US',:constraints => {'set' => [	[ "-" , nil ],[ "US" , "US" ],	[ "Canada" , "CAN" ]]}).should == 'Canada, US'
    end
    it "should include #humanize_value that works on sets when value is nil" do
      Widget.humanize_value(nil,:constraints => {'set' => [	[ "-" , nil ],[ "US" , "US" ],	[ "Canada" , "CAN" ]]}).should == nil
    end
  end
  
  describe TextFieldWidget do
    it "should render an html input text with a label" do
      TextFieldWidget.render_form_object(1,'value',{}).should == 
        "<input id=\"record_1\" name=\"record[1]\" type=\"text\" value=\"value\" />"
    end
    it "should render an html input text with a size parameter" do
      TextFieldWidget.render_form_object(1,'value',{:params=>'3'}).should == 
        "<input class=\"textfield_3\" id=\"record_1\" name=\"record[1]\" size=\"3\" type=\"text\" value=\"value\" />"
    end
    it "should render value as text with a read_only parameter" do
      TextFieldWidget.render_form_object_read_only(1,'value',{}).should == 
        "<span id=\"record_1\">value</span>"
    end
  end

  describe TextAreaWidget do
    it "should render an html text area with a label" do
      TextAreaWidget.render_form_object(1,'value',{}).should == 
        "<textarea id=\"record_1\" name=\"record[1]\">value</textarea>"
    end
    it "should render an html input text with rows & columns parameters" do
      TextAreaWidget.render_form_object(1,'value',{:params=>'10,20'}).should == 
        "<textarea cols=\"20\" id=\"record_1\" name=\"record[1]\" rows=\"10\">value</textarea>"
    end
    it "should render value as text with a read_only parameter" do
      TextAreaWidget.render_form_object_read_only(1,'value',{}).should == 
        "<span id=\"record_1\">value</span>"
    end
  end

  describe DateWidget do
    it "should render three html input texts and the instructions" do
      DateWidget.render_form_object(1,"2004-10-23",{}).should == 
      "    <script type=\"text/javascript\">\n    //<![CDATA[\n    var record_1_first_pass =  true;\n    //]]>\n    </script> \n    <span id=\"record_1_wrapper\"><input onblur=\"if (record_1_first_pass) {mark_invalid_date('record_1')}\" type=\"text\"  size=2 class=\"textfield_2\" name=\"record[1][month]\" id=\"record_1_month\" value=\"10\" maxlength=\"2\"/> /\n<input onblur=\"if (record_1_first_pass) {mark_invalid_date('record_1')}\" type=\"text\"  size=2 class=\"textfield_2\" name=\"record[1][day]\" id=\"record_1_day\" value=\"23\" maxlength=\"2\"/> /\n<input onblur=\"mark_invalid_date('record_1');record_1_first_pass = true;\" type=\"text\" size=4 class=\"textfield_4\" name=\"record[1][year]\" id=\"record_1_year\" value=\"2004\" maxlength=\"4\"/> <span class=\"instructions\">(MM/DD/YYYY)</span>\n</span>\n"
    end
    it "should render date value as text with a read_only parameter" do
      DateWidget.render_form_object_read_only(1,"2004-10-23",{}).should == 
        "<span id=\"record_1\">10/23/2004</span>"
    end
  end
  
  describe TimeWidget do
    it "should render two html input texts plus a select for am/pm" do
      TimeWidget.render_form_object(1,"3:22",{}).should == 
        "     <script type=\"text/javascript\">\n     //<![CDATA[\n     var record_1_first_pass = true;\n     //]]>\n     </script> \n    <span id=\"record_1_wrapper\">      <input onblur=\"if (record_1_first_pass) {mark_invalid_time('record_1')}\" type=\"text\" size=2 class=\"textfield_2\" name=\"record[1][hours]\" id=\"record_1_hours\" value=\"3\" maxlength=\"2\"/>:\n      <input onblur=\"mark_invalid_time('record_1');record_1_first_pass = true;\" type=\"text\" class=\"left_margin_neg_5 textfield_2\" size=2 name=\"record[1][minutes]\" id=\"record_1_minutes\" value=\"22\" maxlength=\"2\"/>\n      <select onblur=\"if (record_1_first_pass) {mark_invalid_time('record_1')}\" name=\"record[1][am_pm]\" id=\"record_1_am_pm\">\n      \t<option value=\"am\" selected=\"selected\">AM</option>\n<option value=\"pm\">PM</option>\n\t  </select>\n</span>\n"
    end
    it "should render time value as text with a read_only parameter" do
      TimeWidget.render_form_object_read_only(1,"3:22",{}).should == 
        "<span id=\"record_1\">3:22 am</span>"
    end
    it "should render low min time values with a preceeding 0 text if read_only" do
      TimeWidget.render_form_object_read_only(1,"13:02",{}).should == 
        "<span id=\"record_1\">1:02 pm</span>"
    end
  end

  describe TimeIntervalWidget do
    it "should render two html input texts plus a select for am/pm" do
      TimeIntervalWidget.render_form_object(1,"500",{}).should == 
        "      <input type=\"text\" size=2 class=\"textfield_2\" name=\"record[1][hours]\" id=\"record_1_hours\" value=\"8\" /> hours\n      <input type=\"text\" size=2 class=\"textfield_2\" name=\"record[1][minutes]\" id=\"record_1_minutes\" value=\"20\" /> minutes\n"
    end
    it "should render interval value as text if read_only" do
      TimeIntervalWidget.render_form_object_read_only(1,"500",{}).should == 
        "<span id=\"record_1\">8 hours, 20 minutes</span>"
    end
  end
  
  describe FactorTextFieldsWidget do
    it "should render two html input texts and lables from params" do
      FactorTextFieldsWidget.render_form_object(1,"500",{:params=>"5,FirstLabel,SecondLabel"}).should == 
        "<input type=\"text\" size=2 name=\"record[1][first_box]\" id=\"record_1_first_box\" value=\"100\" /> FirstLabel\n<input type=\"text\" size=2 name=\"record[1][second_box]\" id=\"record_1_second_box\" value=\"0\" /> SecondLabel\n<input type=\"hidden\" name=\"record[1][factor]\"  id=\"record_1_factor\"/ value=\"5\">"
    end
    it "should render factor value as text if read_only" do
{'fraction_non_alphanumeric': 0.1880488327264939, 'fraction_numerical': 0.02470193474691226, 'mean_word_length': 3.7149108044429484, 'pattern_counts': {'":': 0, '<': 89, '<?xml version=': 0, '>': 143, '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': '7122487', 'n_tokens_mistral': 4658, 'n_tokens_neox': 4524, 'n_words': 1091}