How to test faceted views? (<noscript> in faceted results div)

Hello everybody,

I have a custom faceted view (registered with faceted:view directive) which I would like to test. In my tests I enabled faceted navigation, configured faceted widgets by importing a xml file and used one widget (simple text widget) to filter for a specifc value. Now I assert that browser.contents contains the expected values corresponding to the search. But in the section where faceted results should be displayed there is a tag in the HTML returned by browser.contents.

<div id="faceted-results" class="faceted-results">
    <noscript>

    </noscript>
</div>

This is the source code from eea.facetednavigation/eea/facetednavigation/browser/template/macros.pt

<!-- Results -->
<metal:results define-macro="results" tal:define="
  mode mode | string:edit;
  view_mode python:mode == 'view';
  edit_mode python:mode == 'edit';
  search_mode python:mode == 'search';
  faceted_html faceted_html | string:;
">
  <div id="faceted-results" class="faceted-results"
    metal:define-slot="content">
    <noscript tal:condition="view_mode">
      <tal:results replace="structure python:faceted_html" />
    </noscript>
  </div>
</metal:results>

It seems like tal:results is not supported in zope.testbrowser. Can anybody help? Thanks in advance!

Hi @brendaav,

Did you define the mandatory content-core macro within your custom faceted:view. See https://github.com/eea/eea.facetednavigation/blob/master/eea/facetednavigation/views/example/summary.pt#L14

If this is not the case, please let us know :wink:

Hello @avoinea,

thanks for the reply. Yes, I have defined the the mandatory content-core macro within the faceted:view. See below:

<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"
      xmlns:tal="http://xml.zope.org/namespaces/tal"
      xmlns:metal="http://xml.zope.org/namespaces/metal"
      xmlns:i18n="http://xml.zope.org/namespaces/i18n"
      metal:use-macro="context/main_template/macros/master"
      i18n:domain="allgmed.site">

<body>
<metal:content-core fill-slot="content-core">
  <metal:block define-macro="content-core">
    <div tal:define="
      self nocall:context/@@facetedpersonlistview;
      folderContents folderContents | python:context.getFolderContents();
      Batch python:modules['Products.CMFPlone'].Batch;
      b_start python:request.get('b_start', 0);
      batch python:isinstance(folderContents, Batch) and folderContents or Batch(folderContents, 100, int(b_start), orphan=2);">

      <div metal:use-macro="context/batch_macros/macros/navigation"/>

      <!-- Import / Export -->
      <fieldset class="faceted-exportimport-fieldset">
        <!--<legend i18n:translate="label_database_queries">Database Queries</legend>-->
        <legend tal:content="python:self.context.translate(self.label_database_queries)">Database Queries</legend>
        <form method="post" enctype="multipart/form-data"
              title="Import configuration" i18n:attributes="title"
              id="faceted-importexport-widgets" tal:attributes="
      action string:${context/absolute_url}/@@custom_faceted_exportimport;"
              tal:define="criteria python:self.get_criteria">
          <input type="file" name="import_file"/>
          <div>
            <input class="context" type="submit" value="Import" id="import_button"
                   name="import_button"
                   i18n:attributes="value"/>
            <input class="context" type="submit" value="Export" id="export_button"
                   name="export_button"
                   i18n:attributes="value" tal:attributes="
          style python:criteria and 'display: inline' or 'display: none'"/>
          </div>
        </form>
      </fieldset>

      <table class="listing"
             id="persons">
        <thead>
        <tr>
          <!--<th i18n:translate="label_form_of_address" style="font-weight: bold;">Form of Address</th>
          <th i18n:translate="label_name" style="font-weight: bold;">Name</th>
          <th i18n:translate="label_date_of_birth" style="font-weight: bold;">Date of Birth</th>
          <th i18n:translate="label_email" style="font-weight: bold;">E-Mail</th>-->

          <th tal:content="python:self.context.translate(self.label_form_of_address)" style="font-weight: bold;">Form of
            Address
          </th>
          <th tal:content="python:self.context.translate(self.label_name)" style="font-weight: bold;">Name</th>
          <th tal:content="python:self.context.translate(self.label_date_of_birth)" style="font-weight: bold;">Date of
            Birth
          </th>
          <th tal:content="python:self.context.translate(self.label_email)" style="font-weight: bold;">E-Mail</th>
        </tr>
        </thead>
        <tbody>
        <tr tal:repeat="brain folderContents">
          <div tal:define="person python:self.get_db_object(person_id=brain.UID)">
            <td tal:content="python:self.get_address_vocabulary_term(value=person.address)">
              Address
            </td>
            <td>
              <a href="" tal:attributes="href python:brain.getURL();
                                     title python:brain.Description">
                <span tal:content="python:person.last_name">Last Name</span> <span
                tal:content="python:person.first_name">First Name</span>
              </a>
            </td>
            <td tal:content="python:person.date_of_birth">
              Date of Birth
            </td>
            <td tal:content="python:person.email">
              E-Mail
            </td>
          </div>
        </tr>

        </tbody>
      </table>


      <div metal:use-macro="context/batch_macros/macros/navigation"/>

    </div>


  </metal:block>
</metal:content-core>
</body>
</html>

It also works normally, but not in the tests.

Well tal:results is just a custom name for tal:block, I would look with debugger at view_mode and faceted_html :wink:

Plone Foundation Code of Conduct