'Ensure that the JavaScript-automated prepopulated fields work with the
main form and with stacked and tabular inlines.
Refs #13068, #9264, #9983, #9784.'

def test_prepopulated_fields(self):

    from selenium.common.exceptions import TimeoutException
    self.admin_login(username=u'super', password=u'secret', login_url=u'/test_admin/admin/')
    self.selenium.get((u'%s%s' % (self.live_server_url, u'/test_admin/admin/admin_views/mainprepopulated/add/')))
    self.selenium.find_element_by_css_selector(u'#id_pubdate').send_keys(u'2012-02-18')
    self.get_select_option(u'#id_status', u'option    two').click()
    self.selenium.find_element_by_css_selector(u'#id_name').send_keys(u"    this    is    the    mAin    n\xc0M\xeb    and    it's    aw\u03b5\u0161ome")
    slug1 = self.selenium.find_element_by_css_selector(u'#id_slug1').get_attribute(u'value')
    slug2 = self.selenium.find_element_by_css_selector(u'#id_slug2').get_attribute(u'value')
    self.assertEqual(slug1, u'main-name-and-its-awesome-2012-02-18')
    self.assertEqual(slug2, u'option-two-main-name-and-its-awesome')
    self.selenium.find_element_by_css_selector(u'#id_relatedprepopulated_set-0-pubdate').send_keys(u'2011-12-17')
    self.get_select_option(u'#id_relatedprepopulated_set-0-status', u'option    one').click()
    self.selenium.find_element_by_css_selector(u'#id_relatedprepopulated_set-0-name').send_keys(u'    here    is    a    s\u0164\u0101\xc7ke\xf0            inline    !        ')
    slug1 = self.selenium.find_element_by_css_selector(u'#id_relatedprepopulated_set-0-slug1').get_attribute(u'value')
    slug2 = self.selenium.find_element_by_css_selector(u'#id_relatedprepopulated_set-0-slug2').get_attribute(u'value')
    self.assertEqual(slug1, u'here-stacked-inline-2011-12-17')
    self.assertEqual(slug2, u'option-one-here-stacked-inline')
    self.selenium.find_elements_by_link_text(u'Add    another    Related    Prepopulated')[0].click()
    self.selenium.find_element_by_css_selector(u'#id_relatedprepopulated_set-1-pubdate').send_keys(u'1999-01-25')
    self.get_select_option(u'#id_relatedprepopulated_set-1-status', u'option    two').click()
    self.selenium.find_element_by_css_selector(u'#id_relatedprepopulated_set-1-name').send_keys(u'    now    you    haVe    an\xf6ther            s\u0164\u0101\xc7ke\xf0        inline    with    a    very    ...    loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooog    text...    ')
    slug1 = self.selenium.find_element_by_css_selector(u'#id_relatedprepopulated_set-1-slug1').get_attribute(u'value')
    slug2 = self.selenium.find_element_by_css_selector(u'#id_relatedprepopulated_set-1-slug2').get_attribute(u'value')
    self.assertEqual(slug1, u'now-you-have-another-stacked-inline-very-loooooooo')
    self.assertEqual(slug2, u'option-two-now-you-have-another-stacked-inline-very-looooooo')
    self.selenium.find_element_by_css_selector(u'#id_relatedprepopulated_set-2-0-pubdate').send_keys(u'1234-12-07')
    self.get_select_option(u'#id_relatedprepopulated_set-2-0-status', u'option    two').click()
    self.selenium.find_element_by_css_selector(u'#id_relatedprepopulated_set-2-0-name').send_keys(u'And    now,    with    a    t\xc3b\u0171la\u0158    inline    !!!')
    slug1 = self.selenium.find_element_by_css_selector(u'#id_relatedprepopulated_set-2-0-slug1').get_attribute(u'value')
    slug2 = self.selenium.find_element_by_css_selector(u'#id_relatedprepopulated_set-2-0-slug2').get_attribute(u'value')
    self.assertEqual(slug1, u'and-now-tabular-inline-1234-12-07')
    self.assertEqual(slug2, u'option-two-and-now-tabular-inline')
    self.selenium.find_elements_by_link_text(u'Add    another    Related    Prepopulated')[1].click()
    self.selenium.find_element_by_css_selector(u'#id_relatedprepopulated_set-2-1-pubdate').send_keys(u'1981-08-22')
    self.get_select_option(u'#id_relatedprepopulated_set-2-1-status', u'option    one').click()
    self.selenium.find_element_by_css_selector(u'#id_relatedprepopulated_set-2-1-name').send_keys(u'a    t\xc3b\u0171la\u0158    inline    with    ignored    ;"&*^\\%$#@-/`~    characters')
    slug1 = self.selenium.find_element_by_css_selector(u'#id_relatedprepopulated_set-2-1-slug1').get_attribute(u'value')
    slug2 = self.selenium.find_element_by_css_selector(u'#id_relatedprepopulated_set-2-1-slug2').get_attribute(u'value')
    self.assertEqual(slug1, u'tabular-inline-ignored-characters-1981-08-22')
    self.assertEqual(slug2, u'option-one-tabular-inline-ignored-characters')
    self.selenium.find_element_by_xpath(u'//input[@value="Save"]').click()
    self.wait_page_loaded()
    self.assertEqual(MainPrepopulated.objects.all().count(), 1)
    MainPrepopulated.objects.get(name=u"    this    is    the    mAin    n\xc0M\xeb    and    it's    aw\u03b5\u0161ome", pubdate=u'2012-02-18', status=u'option    two', slug1=u'main-name-and-its-awesome-2012-02-18', slug2=u'option-two-main-name-and-its-awesome')
    self.assertEqual(RelatedPrepopulated.objects.all().count(), 4)
    RelatedPrepopulated.objects.get(name=u'    here    is    a    s\u0164\u0101\xc7ke\xf0            inline    !        ', pubdate=u'2011-12-17', status=u'option    one', slug1=u'here-stacked-inline-2011-12-17', slug2=u'option-one-here-stacked-inline')
    RelatedPrepopulated.objects.get(name=u'    now    you    haVe    an\xf6ther            s\u0164\u0101\xc7ke\xf0        inline    with    a    very    ...    loooooooooooooooooo', pubdate=u'1999-01-25', status=u'option    two', slug1=u'now-you-have-another-stacked-inline-very-loooooooo', slug2=u'option-two-now-you-have-another-stacked-inline-very-looooooo')
    RelatedPrepopulated.objects.get(name=u'And    now,    with    a    t\xc3b\u0171la\u0158    inline    !!!', pubdate=u'1234-12-07', status=u'option    two', slug1=u'and-now-tabular-inline-1234-12-07', slug2=u'option-two-and-now-tabular-inline')
    RelatedPrepopulated.objects.get(name=u'a    t\xc3b\u0171la\u0158    inline    with    ignored    ;"&*^\\%$#@-/`~    characters', pubdate=u'1981-08-22', status=u'option    one', slug1=u'tabular-inline-ignored-characters-1981-08-22', slug2=u'option-one-tabular-inline-ignored-characters')
