<commit_before># encoding: utf-8
require File.expand_path('../watirspec_helper', __FILE__)

describe 'Element' do
  # Direct attribute access
  before :each do
    browser.url = fixture('non_control_elements.html')

    @element = window.find_elements_by_id('descartes').first
    @list    = window.find_elements_by_id('navbar').first
    @leaf    = window.find_elements_by_id('link_2').first
  end

  # parent
  describe '#parent' do
    it 'is the parent element of an element' do
      # Two .parent to get to an IDed element
      @element.parent.parent.attr(:id).should == 'promo'
    end

    it 'is nil for the root element' do
      window.find_elements_by_tag(:html).first.parent.should == nil
    end
  end

  # children
  describe '#children' do
    it 'is not empty when there are child elements' do
      @list.children.should_not be_empty
    end

    it 'contains the child elements of an element' do
      @list.children.all? do |child|
        child.parent.attr(:id) == 'navbar'
      end.should be_true
    end

    it 'is empty when the element has no children' do
      @leaf.children.should be_empty
    end

    it 'is a collection' do
      @list.children.find_elements_by_tag(:li).all? do |element|
        element.parent == @list
      end.should be_true
      # Some example calls
      @list.should.respond_to? :id
      @list.should.respond_to? :tag
    end
  end

  # attr(what, value=nil)
  describe '#attr' do
    it 'gets the value of the given attribute' do
      @element.attr(:class).should == 'descartes'
    end

    it 'can access attributes with dashes' do
      @leaf.attr(:"data-fixture").should == 'leaf'
    end

    it 'is nil when the attribute does not exist' do
      @element.attr(:hoobaflooba).should == nil
    end

    it 'sets the attribute value when passed a value' do
      @element.attr(:id => 'value')
      @element.attr(:id).should == 'value'
    end

    it 'sets multiple attributes when passed values' do
      @element.attr(:id => 'one', :class => 'two')
      @element.attr(:id).should == 'one'
      @element.attr(:class).should == 'two'
    end
  end

  describe 'sugar' do
    it 'provides direct access to the element\'s attributes' do
      @element.class.should == @element.attr(:class)
      @element.id.should == @element.attr(:id)
    end

    it 'uses underscores instead of dashes' do<commit_msg>Attribute access now uses underscores to be consistant with the sugar<commit_after># encoding: utf-8
require File.expand_path('../watirspec_helper', __FILE__)

describe 'Element' do
  # Direct attribute access
  before :each do
    browser.url = fixture('non_control_elements.html')

    @element = window.find_elements_by_id('descartes').first
    @list    = window.find_elements_by_id('navbar').first
    @leaf    = window.find_elements_by_id('link_2').first
  end

  # parent
  describe '#parent' do
    it 'is the parent element of an element' do
      # Two .parent to get to an IDed element
      @element.parent.parent.attr(:id).should == 'promo'
    end

    it 'is nil for the root element' do
      window.find_elements_by_tag(:html).first.parent.should == nil
    end
  end

  # children
  describe '#children' do
    it 'is not empty when there are child elements' do
      @list.children.should_not be_empty
    end

    it 'contains the child elements of an element' do
      @list.children.all? do |child|
        child.parent.attr(:id) == 'navbar'
      end.should be_true
    end

    it 'is empty when the element has no children' do
      @leaf.children.should be_empty
    end

    it 'is a collection' do
      @list.children.find_elements_by_tag(:li).all? do |element|
        element.parent == @list
      end.should be_true
      # Some example calls
      @list.should.respond_to? :id
      @list.should.respond_to? :tag
    end
  end

  # attr(what, value=nil)
  describe '#attr' do
    it 'gets the value of the given attribute' do
      @element.attr(:class).should == 'descartes'
    end

    it 'uses underscores instead of dashes' do
      @leaf.attr(:data_fixture).should == 'leaf'
    end

    it 'is nil when the attribute does not exist' do
      @element.attr(:hoobaflooba).should == nil
    end

    it 'sets the attribute value when passed a value' do
      @element.attr(:id => 'value')
      @element.attr(:id).should == 'value'
    end

    it 'sets multiple attributes when passed values' do
      @element.attr(:id => 'one', :class => 'two')
      @element.attr(:id).should == 'one'
      @element.attr(:class).should == 'two'
    end
  end

  describe 'sugar' do
    it 'provides direct access to the element\'s attributes' do
      @element.class.should == @element.attr(:class)
      @element.id.should == @element.attr(:id)
    end

    it 'uses underscores instead of dashes' do
{'fraction_non_alphanumeric': 0.11277882009589327, 'fraction_numerical': 0.0008338544923910778, 'mean_word_length': 2.8261562998405103, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 9, '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': '2796732', 'n_tokens_mistral': 1511, 'n_tokens_neox': 1468, 'n_words': 459}