# -*- coding: utf-8 -*-
# Generated by the windmill services transformer
from windmill.authoring import WindmillTestClient

"""These tests must be loaded by Windmill.
Command example: $ windmill shell firefox http://localhost:8080 field_creation.py
"""

def test_login():
    """Some parameters must be modified (user, password, Plone URL).
    """
    client = WindmillTestClient(__name__)

    client.click(link=u'View your Plone site.')
    client.waits.forPageLoad(timeout=u'20000')
    client.waits.forElement(timeout=u'8000', id=u'__ac_name')
    client.type(text=u'admin', id=u'__ac_name') # To replace with the corrects username and password
    client.type(text=u'password', id=u'__ac_password')
    client.click(name=u'submit')
    client.waits.forPageLoad(timeout=u'20000')

def test_createDB():
    client = WindmillTestClient(__name__)

    client.click(link=u'Home')
    client.waits.forPageLoad(timeout=u'20000')
    client.waits.forElement(xpath=u"//dl[@id='plone-contentmenu-factories']/dt/a/span[1]", timeout=u'8000')
    client.click(xpath=u"//dl[@id='plone-contentmenu-factories']/dt/a/span[1]")
    client.click(xpath=u"//a[@id='plominodatabase']/span")
    client.waits.forPageLoad(timeout=u'20000')
    client.type(text=u'testdb', id=u'title')
    client.click(name=u'form.button.save')
    client.waits.forPageLoad(timeout=u'20000')

def test_createForm():
    client = WindmillTestClient(__name__)

    client.click(xpath=u"//dl[@id='plone-contentmenu-factories']/dt/a/span[1]")
    client.click(xpath=u"//a[@id='plominoform']/span")
    client.waits.forPageLoad(timeout=u'20000')
    client.waits.forElement(timeout=u'8000', id=u'id')
    client.type(text=u'testform', id=u'id')
    client.type(text=u'testform', id=u'title')
    client.click(name=u'form.button.save')
    client.waits.forPageLoad(timeout=u'20000')

def test_createField():
    client = WindmillTestClient(__name__)

    client.click(link=u'Edit')
    client.waits.forPageLoad(timeout=u'20000')
    client.waits.forElement(xpath=u"//body[@id='content']", timeout=u'8000')
    client.click(xpath=u"//body[@id='content']")
    client.click(id=u'FormLayout_plominofield')
    client.waits.forElement(timeout=u'5000', id=u'plominoFieldId')
    client.type(text=u'field1', id=u'plominoFieldId')
    client.click(id=u'insert')
    client.click(name=u'form.button.save')
    client.waits.forPageLoad(timeout=u'20000')
