===========
 Searching
===========

It is possible to search for persons. There are some different search
types.

Set up
======

Visitors are allowed to search, so we log in as a visitor:

>>> from icemac.addressbook.testing import Browser
>>> browser = Browser()
>>> browser.login('visitor')
>>> browser.open('http://localhost/ab')

There is a link in the global navigation which leads to the searches
overview providing links to the offered search types:

>>> browser.getLink('Search').click()
>>> print browser.contents
<!DOCTYPE ...
  <ul class="bullet">
  <li>
  <a href="http://localhost/ab/@@multi_keyword.html"><span>Keyword search</span></a>
</li>
  <li>
  <a href="http://localhost/ab/@@name_search.html"><span>Name search</span></a>
</li>
</ul>
  ...

Keyword search
==============

This search type allows to search for persons who have specified
keywords assigned to:

>>> browser.getLink('Keyword search').click()

An explanation text is displayed:

>>> [x.text for x in browser.etree.xpath("//div[@id='content']/div[2]")]
['The keywords you want to search for have to be in the right box. Use the arrow buttons to move them.']

When no entry in the keywords field is selected no persons are found:

>>> browser.getControl('Search').click()
>>> print browser.contents
<...No person found...

When no person is found the same message is displayed:

>>> browser.getControl('work').click()
>>> browser.getControl('Search').click()
>>> print browser.contents
<...No person found...

When selecting a keyword which leads to results they are displayed as
a table with links to the edit forms of the found persons:


>>> browser.getControl('work').click() # deselect keyword
>>> browser.getControl('church').click()
>>> browser.getControl('Search').click()
>>> print browser.contents
<!DOCTYPE ...
  <tbody>
    <tr class="table-even-row">
      <td><input type="checkbox" class="checkbox-widget" name="persons:list" value="Person-2" checked="checked" /></td>
      <td class="sorted-on ascending"><a href="http://localhost/ab/Person-2">Koch</a></td>
      <td></td>
    </tr>
    <tr class="table-odd-row">
      <td><input type="checkbox" class="checkbox-widget" name="persons:list" value="Person-4" checked="checked" /></td>
      <td class="sorted-on ascending"><a href="http://localhost/ab/Person-4">Liebig</a></td>
      <td></td>
    </tr>
    <tr class="table-even-row">
      <td><input type="checkbox" class="checkbox-widget" name="persons:list" value="Person-3" checked="checked" /></td>
      <td class="sorted-on ascending"><a href="http://localhost/ab/Person-3">Velleuer</a></td>
      <td></td>
    </tr>
  </tbody>...


The form is displayed on the result page, too. The previously selected
keyword is still selected:

>>> browser.getControl('church').selected
True

The default serch term concatenator is `and`. When selecting multiple
keywords only persons having all keywords are found:

>>> browser.getControl('search term concatenation').displayValue
['and']
>>> browser.getControl('family').click()
>>> browser.getControl('Search').click()
>>> print browser.contents
<!DOCTYPE ...
  <tbody>
    <tr class="table-even-row">
      <td><input type="checkbox" class="checkbox-widget" name="persons:list" value="Person-2" checked="checked" /></td>
      <td class="sorted-on ascending"><a href="http://localhost/ab/Person-2">Koch</a></td>
      <td></td>
    </tr>
    <tr class="table-odd-row">
      <td><input type="checkbox" class="checkbox-widget" name="persons:list" value="Person-3" checked="checked" /></td>
      <td class="sorted-on ascending"><a href="http://localhost/ab/Person-3">Velleuer</a></td>
      <td></td>
    </tr>
  </tbody>...

By selecting `or` as search term concatenation all keyword having one
of the selected keywords are found:

>>> browser.getControl('or').click()
>>> browser.getControl('keywords').displayValue = ['friends', 'family']
>>> browser.getControl('Search').click()
>>> print browser.contents
<!DOCTYPE ...
   <tbody>
     <tr class="table-even-row">
       <td><input type="checkbox" class="checkbox-widget" name="persons:list" value="Person" checked="checked" /></td>
       <td class="sorted-on ascending"><a href="http://localhost/ab/Person">Hohmuth</a></td>
       <td></td>
     </tr>
     <tr class="table-odd-row">
       <td><input type="checkbox" class="checkbox-widget" name="persons:list" value="Person-2" checked="checked" /></td>
       <td class="sorted-on ascending"><a href="http://localhost/ab/Person-2">Koch</a></td>
       <td></td>
    </tr>
     <tr class="table-even-row">
       <td><input type="checkbox" class="checkbox-widget" name="persons:list" value="Person-3" checked="checked" /></td>
       <td class="sorted-on ascending"><a href="http://localhost/ab/Person-3">Velleuer</a></td>
      <td></td>
     </tr>
   </tbody>
  ...


Name search
===========

This search type allows to search for the name of a person (or parts of it
using wildcards):

>>> browser.getLink('Name search').click()

When nothig is entered in the search field an error message is displayed:

>>> browser.getControl('Search').click()
>>> print browser.contents
<!...
      <div class="status">
        <div class="summary">There were some errors.</div>
        <ul class="errors">
          <li>
              Name of a person:
  <div class="error">Required input is missing.</div>
          </li>
        </ul>
      </div>
 ...

When no person is found the a message is displayed:

>>> browser.getControl('Name').value = 'Unknown'
>>> browser.getControl('Search').click()
>>> print browser.contents
<...No person found...

When entering a search term which leads to results they are displayed as
a table with links to the edit forms of the found persons:

>>> browser.getControl('Name').value = 'Lie*'
>>> browser.getControl('Search').click()
>>> print browser.contents
<!DOCTYPE ...
  <tbody>
    <tr class="table-even-row">
      <td><input type="checkbox" class="checkbox-widget" name="persons:list" value="Person-4" checked="checked" /></td>
      <td class="sorted-on ascending"><a href="http://localhost/ab/Person-4">Liebig</a></td>
      <td></td>
    </tr>
    <tr class="table-odd-row">
      <td><input type="checkbox" class="checkbox-widget" name="persons:list" value="Person-5" checked="checked" /></td>
      <td class="sorted-on ascending"><a href="http://localhost/ab/Person-5">Tester</a></td>
      <td><a href="http://localhost/ab/Person-5">Liese</a></td>
   </tr>
  </tbody>
  ...
