diff --git a/module/VuFind/tests/integration-tests/src/VuFindTest/Mink/SearchActionsTest.php b/module/VuFind/tests/integration-tests/src/VuFindTest/Mink/SearchActionsTest.php
index 0de49cb9389a5f1f8c046537f324ad7f3c74d2cd..9985a75807e38bbba0d3b5158045c019151382c5 100644
--- a/module/VuFind/tests/integration-tests/src/VuFindTest/Mink/SearchActionsTest.php
+++ b/module/VuFind/tests/integration-tests/src/VuFindTest/Mink/SearchActionsTest.php
@@ -360,7 +360,27 @@ class SearchActionsTest extends \VuFindTest\Unit\MinkTestCase
     }
 
     /**
-     * Test that exclusion works properly deep in lightbox results.
+     * Support method to click a hierarchical facet.
+     *
+     * @param \Behat\Mink\Element\Element $page Mink page object
+     *
+     * @return void
+     */
+    protected function clickHierarchyFacet($page)
+    {
+        $this->findCss($page, '#j1_1.jstree-closed .jstree-icon');
+        $session = $this->getMinkSession();
+        $session->executeScript("$('#j1_1.jstree-closed .jstree-icon').click();");
+        $this->findCss($page, '#j1_1.jstree-open .jstree-icon');
+        $this->findCss($page, '#j1_2 a')->click();
+        $this->snooze();
+        $filter = $this->findCss($page, '.filters .list-group-item.active');
+        $this->assertEquals('hierarchy: 1/level1a/level2a/', $filter->getText());
+        $this->findCss($page, '#j1_2 .fa-check');
+    }
+
+    /**
+     * Test that hierarchy facets work properly.
      *
      * @return void
      */
@@ -378,15 +398,46 @@ class SearchActionsTest extends \VuFindTest\Unit\MinkTestCase
                 ]
             ]
         );
-        $page = $this->performSearch('');
-        $this->findCss($page, '#j1_1.jstree-closed .jstree-icon');
-        $session = $this->getMinkSession();
-        $session->executeScript("$('#j1_1.jstree-closed .jstree-icon').click();");
-        $this->findCss($page, '#j1_1.jstree-open .jstree-icon');
-        $this->findCss($page, '#j1_2 a')->click();
-        $filter = $this->findCss($page, '.filters .list-group-item.active');
-        $this->assertEquals('hierarchy: 1/level1a/level2a/', $filter->getText());
-        $this->findCss($page, '#j1_2 .fa-check');
+        $page = $this->performSearch('building:"hierarchy.mrc"');
+        $this->clickHierarchyFacet($page);
+    }
+
+    /**
+     * Test that we can persist uncollapsed state of collapsed facets
+     *
+     * @return void
+     */
+    public function testCollapseStatePersistence()
+    {
+        $this->changeConfigs(
+            [
+                'facets' => [
+                    'Results' => [
+                        'hierarchical_facet_str_mv' => 'hierarchy'
+                    ],
+                    'Results_Settings' => [
+                        'collapsedFacets' => '*'
+                    ],
+                    'SpecialFacets' => [
+                        'hierarchical[]' => 'hierarchical_facet_str_mv'
+                    ]
+                ]
+            ]
+        );
+        $page = $this->performSearch('building:"hierarchy.mrc"');
+        // Uncollapse format so we can check if it is still open after reload:
+        $this->findCss($page, '#side-panel-format .collapsed')->click();
+        // Uncollapse hierarchical facet so we can click it:
+        $this->findCss($page, '#side-panel-hierarchical_facet_str_mv .collapsed')->click();
+        $this->clickHierarchyFacet($page);
+
+        // We have now reloaded the page. Let's toggle format off and on to confirm
+        // that it was opened, and let's also toggle building on to confirm that
+        // it was not alread opened.
+        $this->findCss($page, '#side-panel-format .title')->click(); // off
+        $this->snooze(); // wait for animation
+        $this->findCss($page, '#side-panel-format .collapsed')->click(); // on
+        $this->findCss($page, '#side-panel-building .collapsed')->click(); // on
     }
 
     /**
diff --git a/themes/bootstrap3/js/common.js b/themes/bootstrap3/js/common.js
index 6eb6287425fe3f3b5ec5ab7722523a3c47bae849..6ad4f3b77f1e56216b4cfa7ec55eb4c5c4bcbbd8 100644
--- a/themes/bootstrap3/js/common.js
+++ b/themes/bootstrap3/js/common.js
@@ -250,7 +250,6 @@ function setupAutocomplete() {
 
 /**
  * Handle arrow keys to jump to next record
- * @returns {undefined}
  */
 function keyboardShortcuts() {
   var $searchform = $('.searchForm_lookfor');
@@ -290,6 +289,33 @@ function keyboardShortcuts() {
   }
 }
 
+/**
+ * Setup facets
+ */
+function setupFacets() {
+  // Advanced facets
+  $('.facetOR').click(function facetBlocking() {
+    $(this).closest('.collapse').html('<div class="list-group-item">' + VuFind.translate('loading') + '...</div>');
+    window.location.assign($(this).attr('href'));
+  });
+
+  // Side facet status saving
+  $('.facet.list-group .collapse').each(function openStoredFacets(index, item) {
+    var source = $('#result0 .hiddenSource').val();
+    var storedItem = sessionStorage.getItem('sidefacet-' + source + item.id);
+    if (storedItem) {
+      item.className = storedItem;
+      if ($(item).hasClass('in')) {
+        $(item).collapse('show');
+      } else {
+        $(item).collapse('hide');
+      }
+    }
+  });
+  $('.facet.list-group .collapse').on('shown.bs.collapse', facetSessionStorage);
+  $('.facet.list-group .collapse').on('hidden.bs.collapse', facetSessionStorage);
+}
+
 $(document).ready(function commonDocReady() {
   // Start up all of our submodules
   VuFind.init();
@@ -340,28 +366,8 @@ $(document).ready(function commonDocReady() {
     $.getJSON(VuFind.path + '/AJAX/JSON', {method: 'keepAlive'});
   }
 
-  // Advanced facets
-  $('.facetOR').click(function facetBlocking() {
-    $(this).closest('.collapse').html('<div class="list-group-item">' + VuFind.translate('loading') + '...</div>');
-    window.location.assign($(this).attr('href'));
-  });
-
-  // Side facet status saving
-  $('.facet.list-group .collapse').each(function openStoredFacets(index, item) {
-    var source = $('#result0 .hiddenSource').val();
-    var storedItem = sessionStorage.getItem('sidefacet-' + source + item.id);
-    if (storedItem) {
-      item.className = storedItem;
-      if (item.className.indexOf('in') < 0) {
-        $(item).siblings('.title').addClass('collapsed');
-      } else {
-        $(item).siblings('.title').removeClass('collapsed');
-      }
-    }
-  });
-  $('.facet.list-group .collapse').on('shown.bs.collapse', facetSessionStorage);
-  $('.facet.list-group .collapse').on('hidden.bs.collapse', facetSessionStorage);
-
+  setupFacets();
+  
   // retain filter sessionStorage
   $('.searchFormKeepFilters').click(function retainFiltersInSessionStorage() {
     sessionStorage.setItem('vufind_retain_filters', this.checked ? 'true' : 'false');