Faceted Navigation
==================

Imports
=======

    >>> from zope.component import getMultiAdapter
    >>> from eea.facetednavigation.interfaces import ICriteria

Set up
=======

Setup sandbox

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

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

    >>> subtyper.enable()

    >>> handler = getMultiAdapter((sandbox, request), name=u'faceted_configure')
    >>> query_handler = getMultiAdapter((sandbox, request), name=u'faceted_query')
    >>> config = getMultiAdapter((sandbox, request), name=u'configure_faceted.html')
    >>> view = getMultiAdapter((sandbox, request), name=u'facetednavigation_view')

Cleanup default widgets
=======================

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

Default widgets

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

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

Add some criteria
=================

    >>> _ = handler(wtype='checkbox', addWidget_button=True)
    >>> criteria = config.get_criteria()
    >>> criterion_id = criteria[0].getId()

Update criteria properties
==========================

    >>> form = {
    ...   criterion_id + '_title': 'Test widget',
    ...   criterion_id + '_index': 'Title',
    ...   criterion_id + '_widget': 'checkbox',
    ...   criterion_id + '_vocabulary': '',
    ...   criterion_id + '_position': 'top',
    ...   criterion_id + '_catalog': True,
    ...   'saveChanges_button': True,
    ... }
    >>> _ = handler(**form)
    >>> criteria = config.get_criteria()
    >>> criterion = criteria[0]
    >>> criterion.widget, criterion.title, criterion.index, criterion.position
    ('checkbox', 'Test widget', 'Title', 'top')
    >>> criterion.catalog, criterion.vocabulary
    (True, '')

Change criteria order
=====================

    >>> _ = handler(wtype='text', addWidget_button=True)
    >>> _ = handler(wtype='alphabetic', addWidget_button=True)
    >>> _ = handler(wtype='sorting', addWidget_button=True)

    >>> criteria = config.get_criteria()
    >>> [x.widget for x in criteria]
    ['checkbox', 'text', 'alphabetic', 'sorting']

    >>> alphabetic_id = criteria[2].getId()
    >>> checkbox_id = criteria[0].getId()

    >>> kwargs = {'moveUp_button+++' + alphabetic_id: 'On'}
    >>> _ = handler(**kwargs)
    >>> kwargs = {'moveDown_button+++' + checkbox_id: 'On'}
    >>> _ = handler(**kwargs)

    >>> criteria = config.get_criteria()

Delete criteria
===============

    >>> _ = handler(
    ...     deleteWidgets_button=True,
    ...     paths=[alphabetic_id, checkbox_id]
    ... )
    >>> criteria = config.get_criteria()
    >>> [x.widget for x in criteria]
    ['text', 'sorting']

Default criteria
================

    >>> query_handler.default_criteria
    {}

    >>> _ = handler(wtype='text', addPropertiesWidget_button=True, default='Water')
    >>> query_handler.default_criteria
    {'c2': 'Water'}
