Alphabetic widget
=================

Widget to filter results by starting letter

Imports
-------

    >>> from DateTime import DateTime
    >>> from zope.component import getMultiAdapter
    >>> from Products.CMFCore.utils import getToolByName
    >>> from eea.facetednavigation.interfaces import ICriteria

Set up
------

    >>> portal = layer['portal']
    >>> request = layer['request']
    >>> sandbox = portal['sandbox']
    >>> sandbox.setTitle('Faceted navigation folder test')

    >>> subtyper = getMultiAdapter((sandbox, request), name=u'faceted_subtyper')
    >>> subtyper.enable()

    >>> putils = getToolByName(sandbox, 'plone_utils')
    >>> handler = getMultiAdapter((sandbox, request), name=u'faceted_configure')
    >>> query = getMultiAdapter((sandbox, request), name=u'faceted_query')

Cleanup default widgets
-----------------------

    >>> cids = ICriteria(sandbox).keys()

Default widgets

    >>> cids
    [...'c1',...]

    >>> for cid in cids:
    ...     ICriteria(sandbox).delete(cid)
    >>> ICriteria(sandbox).keys()
    []

Add testing content

    >>> fid = portal.invokeFactory('Document', 'a-folder', title='Za folder')
    >>> fob = portal._getOb(fid)
    >>> fob.setLanguage('en')

Add widget
----------

    >>> _ = handler(addPropertiesWidget_button=True, wtype='alphabetic',
    ...             wposition='top', title='Alpha',
    ...             hidden=True, index='Title', default='Z')
    >>> print(ICriteria(sandbox).keys()[0])
    c0

    >>> c0_crit = ICriteria(sandbox).get('c0').__dict__
    >>> 'default' in c0_crit
    True

    >>> print(c0_crit['default'])
    Z

Query
-----

    >>> brains = query.query()
    >>> [brain.getId for brain in brains]
    ['a-folder']

    >>> _ = handler(updateCriterion_button='Save', cid='c0', hidden=False)
    >>> brains = query.query(c0='X')
    >>> [brain.getId for brain in brains]
    []

    >>> brains = query.query(c0='Z')
    >>> [brain.getId for brain in brains]
    ['a-folder']

Update widget
-------------

    >>> _ = handler(updateCriterion_button=True, cid='c0',
    ...             wposition='bottom', default='X', hidden=True)

    >>> c0_crit = ICriteria(sandbox).get('c0').__dict__
    >>> 'default' in c0_crit
    True

    >>> print(c0_crit['default'])
    X

    >>> brains = query.query()
    >>> [brain.getId for brain in brains]
    []

Delete widget
-------------

    >>> _ = handler(deleteWidget_button=True, cid='c0')
    >>> ICriteria(sandbox).keys()
    []
